(源代码无关内容太多,我就放上极简版了)后台配置了百度那个域名(https:
wxml:
这里是获取到的数据{{testData}}
JS:
async onShow(){
const a = await this.getAccess_token();
this.setData({
testData: a.data.access_token,
})
},
getAccess_token() {
return new Promise(function (resolve, reject) {
wx.request({
url: 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=IEx2te9DfY4PbocCc6xjUrbB&client_secret=QFxdtqSbBF9hhnpHXCmaLb5kaA5122D1&',
method: "POST",
success: (res) => {
resolve(res)
},
fail: (_err) => {
wx.showToast({
title: `获取token失败${JSON.stringify(_err)}`,
icon:'none'
});
reject(_err);
}
});
});
},