-本地调试时报错:module.exports.ReadError: incorrect header check
云端上调试也是这个报错:{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"incorrect header check"}
- 确认了我的access_token没有问题,依赖库全部装上,
同样的函数,换了别的接口,对接成功,换回'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" 就依然不行
然后我就用postman测试https://api.weixin.qq.com/wxa/msg_sec_check?access_token=接口,对接成功,我复制了对接成功的POST地址放回云函数再次调试,依然报错,这是为啥?
开发工具版本是最新的 v1.02.1906062
-大佬们能给看看嘛,救救孩子
云函数的代码
// 云函数入口文件const cloud = require('wx-server-sdk');const got=require('got');var appid ='appid';var appsecret ='appsecret '; cloud.init();// 拼接 access_token let tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + appsecret// 内容检测接口let checkUrl = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='// 云函数入口函数exports.main = async (event, context) => { let tokenResponse = await got(tokenUrl); let token = JSON.parse(tokenResponse.body).access_token; let checkResponse = await got(checkUrl + token, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content: event.content }) }); return checkResponse.body;} |

请用云调用的方式试试呢
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html#method-cloud
已经采用这个方法解决了 真的非常简单,token都不用
什么意思啊,这个应该怎么用。大佬求告知
//云函数声明// 云函数入口文件const cloud = require('wx-server-sdk')cloud.init()// 云函数入口函数exports.main = async (event, context) => {try{const checkmsg = await cloud.openapi.security.msgSecCheck({content: event.content});returncheckmsg;}catch(err) {throwerr}}//在你需要用到的地方写一个函数调用云函数,也可以直接用//检测敏感词汇msgSecCheck:function(event){varstr = eventwx.cloud.callFunction({name:'checkMsg',data:{content:str}}).then(res=>{this.setData({checkCode: JSON.stringify(res.result.errCode)});}).catch(err=>{this.setData({checkCode: String(err.errCode)});});}我是新手,所以这种写法比较粗糙简陋,用来做个毕业设计就足够了
云函数: