I encountered a problem when using thinkphp5.1x to make WeChat Mini Programs"s payment.
the front-end process is to request the order-issuing API first, and then request the payment interface after the order-issuing API is successful.
Front-end Code:
getpay:function(){
var token=wx.getStorageSync("token");
wx.request({
//
url: "http://restcms.cncyz.com/api/v1/placeOrder",
method:"POST",
header:{
token:token
},
data:{
//
products:[
{product_id:1, count:3},
{product_id:11,count:5}
]
},
success:function(res){
console.log(res);
//
wx.request({
url: "http://restcms.cncyz.com/api/v1/pay",
method: "POST",
header: {
token: token
},
data: {
id: res.data.order_id
},
success:function(resn){
//
console.log(resn);
}
})
}
})
}
the problem encountered is
http://restcms.cncyz.com/api/. order interface threw an exception because the user address does not exist
$data=UserAddress::where("user_id","=",$this->uid)->find();
if(empty($data)){
throw new UserException(["msg"=>""]);
}
return $data;
Wechat developer tool
what I don"t understand, the first order exception thrown should be terminated. Why is there a payment error message?
the following code is not supposed to be executed. If an exception is thrown, why will it still be executed? and there is an error message
success:function(res){
console.log(res);
//
wx.request({
url: "http://restcms.cncyz.com/api/v1/pay",
method: "POST",
header: {
token: token
},
data: {
id: res.data.order_id
},
success:function(resn){
//
console.log(resn);
}
})
How should the code be modified? What"s the reason?