// 需要给对应的云函数安装 request-promise 依赖
// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
const rp = require(‘request-promise’)
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const page = event.page
const scene = event.scene
//appid和秘钥
const appid = ‘***’,
secret = ‘***’;
const AccessToken_options = {
method: ‘GET’,
url: 'https://api.weixin.qq.com/cgi-bin/token’,
qs: {
appid,
secret,
grant_type: ‘client_credential’
},
json: true
};
//获取AccessToken
const resultValue = await rp(AccessToken_options);
const token = resultValue.access_token;
}