- 当前 Bug 的表现(可附上截图)
云函数执行到request时,直接忽视,不返回,不知道是因为域名的问题还是怎回事
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
var request = require(‘request’);
request({
url: ‘https://api.weixin.qq.com/sns/jscode2session’,
data: {
appid: _APPID,
secret: _SECRET,
js_code: _JSCODE,
grant_type: ‘authorization_code’
},
method: ‘GET’,
header: {
‘content-type’: ‘application/json’
}, // 设置请求的 header
success: function (res) {
console.log('sessionkey: ’ + sessionkey)
},
fail: function (err) {
console.log(err);
}
})
首先安装 request-promise
npm 命令 npm install request-promise
// 云函数入口文件 const cloud = require('wx-server-sdk') //npm install request-promise const rp = require('request-promise');
cloud.init()
// 云函数入口函数 exports.main = async (event, context) => {
//appid 和秘钥 jscode const appid = 'wxxxxxxxx', secret = 'xxxxxxxxxxxx',_JSCODE='';
const AccessToken_options = { method: 'GET', url: 'https://api.weixin.qq.com/sns/jscode2session', qs: { appid, secret, grant_type:'authorization_code' js_code:_JSCODE }, json: true
};
const resultValue = await rp(AccessToken_options);
return { resultValue }
}
|