- 当前 Bug 的表现(可附上截图)
const got = require( 'got' ) // 引入 got 库 const Config = require( '../controllers/defaultConfig' ); router.post( '/msgSecCheck' , async(ctx, next) => { console.log(ctx) // 获取 access_token 值 let tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + Config.wxConfig.appid + '&secret=' + Config.wxConfig.secret; // 文本内容检测接口 let checkUrl = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' ; let tokenResponse = await got(tokenUrl); // 通过 got 请求 api let token = JSON.parse(tokenResponse.body).access_token; // JSON.parse 将数据转换成对象获取到具体 access_token 值 // 文本内容检测接口拼接 access_token 值, JSON.stringIfy 将值转换成 JSON 字符串 let checkResponse; try { checkResponse = await got(checkUrl + token, { method: 'POST' , headers: { 'Content-Type' : 'application/json' }, body: JSON.stringify({ content: ctx.request.body.content }) }); } catch (err) { console.log(err) } ctx.body.data = checkResponse; }) |
进入catch,打出
{ ReadError: incorrect header check at EventEmitter.emitter.on (I:\work\whigest\whigestTalkServer\node_modules\got\source\as-promise.js:28:12) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) name: 'ReadError' , code: 'Z_DATA_ERROR' , host: 'api.weixin.qq.com' , hostname: 'api.weixin.qq.com' , method: 'POST' , path: '/wxa/msg_sec_check?access_token=23_Xqd0UPPUJBSjbkLosKBvLCm6oZvtvbpuK6NNZGSSvPJ4Y7ljhcXnqr2b1S8u7XYMXZ0novGe2wJftEfqD6v9QEqD6dwZ5-3WzPQkSYUroJp_HKiUPvWQFTjXY_tvZ_ZQXX0jpWSM3rEJc4MIEOJgAHAMWR' , socketPath: undefined, protocol: 'https:' , url: 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=23_Xqd0UPPUJBSjbkLosKBvLCm6oZvtvbpuK6NNZGSSvPJ4Y7ljhcXnqr2b1S8u7XYMXZ0novGe2wJftEfqD6v9QEqD6dwZ5-3WzPQkSYUroJp_HKiUPvWQFTjXY_tvZ_ZQXX0jpWSM3rEJc4MIEOJgAHAMWR' , gotOptions: { path: '/wxa/msg_sec_check?access_token=23_Xqd0UPPUJBSjbkLosKBvLCm6oZvtvbpuK6NNZGSSvPJ4Y7ljhcXnqr2b1S8u7XYMXZ0novGe2wJftEfqD6v9QEqD6dwZ5-3WzPQkSYUroJp_HKiUPvWQFTjXY_tvZ_ZQXX0jpWSM3rEJc4MIEOJgAHAMWR' , protocol: 'https:' , slashes: true , auth: null , host: 'api.weixin.qq.com' , port: null , hostname: 'api.weixin.qq.com' , hash: null , search: '?access_token=23_Xqd0UPPUJBSjbkLosKBvLCm6oZvtvbpuK6NNZGSSvPJ4Y7ljhcXnqr2b1S8u7XYMXZ0novGe2wJftEfqD6v9QEqD6dwZ5-3WzPQkSYUroJp_HKiUPvWQFTjXY_tvZ_ZQXX0jpWSM3rEJc4MIEOJgAHAMWR' , pathname: '/wxa/msg_sec_check' , href: 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=23_Xqd0UPPUJBSjbkLosKBvLCm6oZvtvbpuK6NNZGSSvPJ4Y7ljhcXnqr2b1S8u7XYMXZ0novGe2wJftEfqD6v9QEqD6dwZ5-3WzPQkSYUroJp_HKiUPvWQFTjXY_tvZ_ZQXX0jpWSM3rEJc4MIEOJgAHAMWR' , retry: { retries: [Function], methods: [Object], statusCodes: [Object], errorCodes: [Object] }, headers: { 'user-agent' : 'got/9.6.0 (https://github.com/sindresorhus/got)' , 'content-type' : 'application/json' , 'accept-encoding' : 'gzip, deflate' , 'content-length' : 106 }, hooks: { beforeRequest: [], beforeRedirect: [], beforeRetry: [], afterResponse: [], beforeError: [], init: [] }, decompress: true , throwHttpErrors: true , followRedirect: true , stream: false , form: false , json: false , cache: false , useElectronNet: false , method: 'POST' , body: '{"content":"特3456书yuuo莞6543李zxcz蒜7782法fgnv级\\n完2347全dfji试3726测asad感3847知qwez到"}' } } |
- 预期表现
接口正常
- 复现路径
post请求
- 提供一个最简复现 Demo
代码如上
使用koa2 请问哪里不对呢
zcgj
一样的问题,不知道如何解决
感觉应该是那个got的请求的问题,我这边也是用got请求检查违规内容的,然后报错:rror: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 9b28feb7-2402-11ea-afe4-5254003e0a60, cloud function service error code -504002, error message incorrect header check
ReadError: incorrect header check,我到现在还没解决
楼主是如何解决的。。我这边也遇到这个问题额
遇到跟楼主一样的问题,请问楼主解决了吗