const cloud = require('wx-server-sdk')
const request = require('request');
const got = require('got');
cloud.init({
env:"xcx-16888-8gdoshjo1f8f465f"
})
// 云函数入口函数
exports.main = async (event, context) => {
// var biz="";
// var encrypt_card_id="";
//let postRespone = await got ('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=“”&secret=“”')
//return postRespone.body
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=“”&secret=“”', //appid保密了
method:"GET",
header:{"Content-Type" :"json"},//applicationg/
success:function(res){
var ACCESS_TOKEN = res;
return ACCESS_TOKEN;
}
})
两种请求写法出现同样错误:
errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 389246a2-1386-11ec-9863-5a70464c32c8, cloud function service error code -504002, error message ReferenceError: wx is not defined
有固定IP,open平台也已将公众号与小程序绑定,白名单也已加上。
wx.是客户端api,云函数是服务端,没有wx对象