|
|
@ -74,10 +74,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
let app = getApp() |
|
|
|
let app = getApp() |
|
|
|
import { |
|
|
|
import { |
|
|
|
addOrder, |
|
|
|
addOrder, |
|
|
|
orderToPay |
|
|
|
orderToPay |
|
|
|
} from "../../../Utils/Api.js"; |
|
|
|
} from "../../../Utils/Api.js"; |
|
|
|
|
|
|
|
var jweixin = require('jweixin-module'); |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
@ -87,8 +88,11 @@ |
|
|
|
user: "", |
|
|
|
user: "", |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
onLoad() { |
|
|
|
|
|
|
|
this.user = app.globalData.userInfo |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
|
|
|
|
select(amount) { |
|
|
|
select(amount) { |
|
|
|
this.inputAmount = amount; |
|
|
|
this.inputAmount = amount; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -126,11 +130,9 @@ |
|
|
|
}] |
|
|
|
}] |
|
|
|
} |
|
|
|
} |
|
|
|
addOrder(goods).then(res => { |
|
|
|
addOrder(goods).then(res => { |
|
|
|
|
|
|
|
uni.hideLoading(); |
|
|
|
if (res.return_code == '000000') { |
|
|
|
if (res.return_code == '000000') { |
|
|
|
//模板模拟支付,实际应用请调起微信/支付宝 |
|
|
|
//模板模拟支付,实际应用请调起微信/支付宝 |
|
|
|
uni.showLoading({ |
|
|
|
|
|
|
|
title: '支付中...' |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
let params = { |
|
|
|
let params = { |
|
|
|
"orderId": res.return_data.id, |
|
|
|
"orderId": res.return_data.id, |
|
|
|
"openId": app.globalData.openId, |
|
|
|
"openId": app.globalData.openId, |
|
|
@ -138,6 +140,10 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
orderToPay(params).then(res => { |
|
|
|
orderToPay(params).then(res => { |
|
|
|
if (res.return_code == '000000') { |
|
|
|
if (res.return_code == '000000') { |
|
|
|
|
|
|
|
// #ifdef MP |
|
|
|
|
|
|
|
uni.showLoading({ |
|
|
|
|
|
|
|
title: '支付中...' |
|
|
|
|
|
|
|
}) |
|
|
|
uni.requestPayment({ |
|
|
|
uni.requestPayment({ |
|
|
|
"appId": res.return_data.appId, |
|
|
|
"appId": res.return_data.appId, |
|
|
|
"nonceStr": res.return_data.nonceStr, |
|
|
|
"nonceStr": res.return_data.nonceStr, |
|
|
@ -159,23 +165,80 @@ |
|
|
|
console.log('fail:' + JSON.stringify(err)); |
|
|
|
console.log('fail:' + JSON.stringify(err)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
// #endif |
|
|
|
uni.showToast({ |
|
|
|
|
|
|
|
title:'支付失败' |
|
|
|
//判断是否是公众号 |
|
|
|
}) |
|
|
|
// #ifdef H5 |
|
|
|
|
|
|
|
//判断微信浏览器 |
|
|
|
|
|
|
|
this.payRequest(res); |
|
|
|
|
|
|
|
// #endif |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
|
|
title: '支付失败' |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
uni.showToast({ |
|
|
|
title: res.return_msg |
|
|
|
title: res.return_msg |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
payRequest: function(self) { |
|
|
|
onLoad() { |
|
|
|
uni.showLoading({ |
|
|
|
this.user = app.globalData.userInfo |
|
|
|
title: '支付中...' |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
jweixin.config({ |
|
|
|
|
|
|
|
// debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 |
|
|
|
|
|
|
|
appId: self.return_data.appId, // 必填,公众号的唯一标识 |
|
|
|
|
|
|
|
timestamp: self.return_data.timeStamp, // 必填,生成签名的时间戳 |
|
|
|
|
|
|
|
nonceStr: self.return_data.nonceStr, // 必填,生成签名的随机串 |
|
|
|
|
|
|
|
signature: self.return_data.sign, // 必填,签名,见附录1 |
|
|
|
|
|
|
|
jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
uni.hideLoading(); |
|
|
|
|
|
|
|
jweixin.ready(function() { |
|
|
|
|
|
|
|
jweixin.checkJsApi({ |
|
|
|
|
|
|
|
jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表,所有JS接口列表见附录2, |
|
|
|
|
|
|
|
success: function(res) {}, |
|
|
|
|
|
|
|
fail: function(res) {} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
jweixin.chooseWXPay({ |
|
|
|
|
|
|
|
appId: self.return_data.appId, |
|
|
|
|
|
|
|
timestamp: self.return_data |
|
|
|
|
|
|
|
.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 |
|
|
|
|
|
|
|
nonceStr: self.return_data.nonceStr, // 支付签名随机串,不长于 32 位 |
|
|
|
|
|
|
|
package: self.return_data |
|
|
|
|
|
|
|
.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***) |
|
|
|
|
|
|
|
signType: 'MD5', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' |
|
|
|
|
|
|
|
paySign: self.return_data.sign, // 支付签名 |
|
|
|
|
|
|
|
success: function(res) { |
|
|
|
|
|
|
|
// 支付成功后的回调函数 |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
|
|
title: '支付成功' |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
uni.reLaunch({ |
|
|
|
|
|
|
|
url: '../success/success?id=' + that.couponId |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
cancel: function(r) {}, |
|
|
|
|
|
|
|
fail: function(res) {} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jweixin.error(function(res) { |
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
|
|
title: '支付失败了', |
|
|
|
|
|
|
|
duration: 4000 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|