zcgj
调用msgSecCheck,报错incorrect header check- 当前 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 请问哪里不对呢
2021-01-23