both the development version and the beta version can be used, but there is a problem with the online version
common.js
let url= "https://devxcx.webf10.com";
export let getopenidbycode=url+"/xcx/stockgame?action=getopenidbycode";
export default function axios (init) {
init=init?init.url?init:false:false;
if(!init) return "!!!";
let defaults={
data:{},
method:"get",
dataType:"json",
header: { "content-type": "application/json"},
...init
};
defaults={...defaults,...init};
let abort;
let Pro=new Promise(function(resolve,reject){
abort=wx.request({
...defaults,
success(e){
resolve(e);
},
fail(e){
reject(e);
console.log("fail:"+e)
wx.showToast({
title: "~~~",
icon: "none",
duration: 3
})
}
})
});
return {
ajax:Pro,
abort
}
};
app.js
import request, {getopenidbycode} from ". / assets/js/common.js";
App ({
onLaunch: function () {
let that=this;
wx.login({
success: function(res) {
if(res.errMsg.includes("login:ok")){
let ajax=request({
url:getopenidbycode,
data:{
code:res.code
},
});
ajax.ajax.then(function(success){
if(success.statusCode==200&&success.data.status==0){
wx.setStorageSync("open_id",success.data.data);
that.open_id=success.data.data;
}else{
wx.showToast({
title: success.data.error,
icon: "none",
duration: 2000
})
}
},function(fail){
console.log("fail:"+fail)
})
}
},
fail(e){ //
}
});
}
found that Mini Program reported the problem of network instability as soon as he was running, and couldn"t get open_id, to undefined, when he got the authorization information. What"s going on?