云函数报错
发布于 5 年前 作者 qiangyao 6244 次浏览 来自 问答

使用云函数调用msgSecCheck方法时会报错

代码如下:

// 云函数入口文件
const cloud = require('wx-server-sdk')
const got = require('got')
 
let appid = '';
let secret = '';
 
let msgCheckUrl = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=';
let tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+appid+'&secret='+secret
 
cloud.init()
 
// 云函数入口函数
exports.main = async (event, context) => {
  let tokenResponse = await got(tokenUrl)
  let token = JSON.parse(tokenResponse.body).access_token;
 
  // 文本内容检测接口拼接 access_token 值, JSON.stringIfy 将值转换成 JSON 字符串
  let checkResponse = await got(msgCheckUrl + token, {
    body: JSON.stringify({
      content: event.text
    })
  });
  return checkResponse.body

报错如下:

Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail cloud function service error code -504002, error message incorrect header check; at cloud.callFunction api; 

    at new t (WAService.js:22)

    at o (WAService.js:22)

    at Object.i [as returnAsFinalCloudSDKError] (WAService.js:22)

    at Function.success (WAService.js:21)

    at Object.success (WAService.js:4)

    at L.<anonymous> (WAService.js:7)

    at L.emit (WAService.js:8)

    at Function.<anonymous> (WAService.js:12)

    at WAService.js:6

    at e (appservice?t=1561966315142:1107)

求解

2 回复

请问楼主最后解决了吗?遇到一样的问题

checkUrl 未定义,是想用 msgCheckUrl 吧?

回到顶部