【黄啊码】小程序:九宫格抽奖如何实现?可控制抽奖率

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:b0bd592d-d23e-4d8b-bc3e-9c2c3e4265fb

[En]

[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:6c3bce27-b3ee-4835-a4ba-9597cbbe6861

一般人的逻辑就是:getLocation之后直接request

然而,当你request后才发现,根本没有弹窗,what?为什么?

因为获取经纬度需要调用腾讯接口,接口的返回也需要时间,所以我们需要用Promise进行异步调用,接收返回值后才能request,例子如下,废话不多说,有问题百度黄啊码

php;gutter:true;
var p = new Promise(function (resolve, reject) {
wx.getLocation({
isHighAccuracy:true,
highAccuracyExpireTime:3000,
type:'gcz02',
success (res) {
let latitude=res.latitude;
let longitude=res.longitude;
resolve({latitude,longitude});
},fail(res){
let latitude='';
let longitude='';
resolve({latitude,longitude});
}
});
});
p.then(function (datas) {
wx.request({
url: config.api+'/api/XXX/XXXX',
method:'POST',
data: {
latitude:datas.latitude,
longitude:datas.longitude
},
header: { 'content-type': 'application/json' // 默认值
},
success (res) {
if(res.data.code == 0){
wx.showModal({
title: '提示',
content: res.data.message,
})
}
else{
wx.showModal({
title: '提示',
content: res.data.message,
})
return false
}
}
})
})
},

Original: https://www.cnblogs.com/huangama/p/15741267.html
Author: 黄啊码
Title: 【黄啊码】小程序:九宫格抽奖如何实现?可控制抽奖率

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/562261/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球