时间:2019-04-29 来源:小程序工厂
谢谢,已OK
首先安装 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 }
}