function getAccessTokenls (req, res) {
const resObj = Common.clone(Constant.DEFAULT_SUCCESS); // 定义好的成功返回模板
const appId = CONFIG.WECHAT.APP_ID;
const appSecret = CONFIG.WECHAT.APP_SECRET;
let tasks = {
/**
* 获取access_token
*/
accessToken: cb => {
request({
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appId}&secret=${appSecret}`,
method: 'GET',
headers: { 'Content-Type': 'text/json' }
}, function (error, response, body) {
// console.log(body)
if (!error && response.statusCode == 200) {
let data = JSON.parse(body)
resObj.data.accessTokenData = data;
cb(null, data)
}
});
},
/**
* 通过access_token获取ticket(临时)
*/
ticket: ['accessToken', (result, cb) => {
// console.log(result)
let accessToken = result.accessToken.access_token;
let url = `https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=${accessToken}`;
request({
url: url,
method: 'POST',
json: true,
headers: { 'Content-Type': 'text/json' },
body: {
expire_seconds: 60 * 60 * 24 * 7, // 有效时间(单位s)
action_name: "QR_STR_SCENE", // 临时
action_info: {
scene: {
scene_str: "张三"
}
}
}
}, function (error, response, body) {
// console.log(body)
if (!error && response.statusCode == 200) {
let data = JSON.parse(body)
resObj.data.ticketData = data;
resObj.data.ticketData.type = "临时";
cb(null)
}
});
}]
}
Common.autoFn(tasks, res, resObj); // 异步执行
}
一开始body那写的是data,报错
` "errcode": 44002,
"errmsg": "empty post data rid: 5f44c53b-6c3d44e5-1aeb35c6",`
百度方法后改成body,接口直接报502错误,没有往下走了,是哪里出了问题呢
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…