You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
high-mini/pages/qianZhuPay/qianZhuPay.vue

155 lines
4.5 KiB

3 years ago
<template>
<view>
3 years ago
3 years ago
</view>
</template>
<script>
import {
qzOrderToPay
} from '../../Utils/Api.js'
let app = getApp();
// #ifdef H5
var jweixin = require('jweixin-module');
// #endif
3 years ago
export default {
data() {
return {
3 years ago
orderNo: '',
source: '',
orderInfoUrl: ''
3 years ago
}
},
onLoad(options) {
3 years ago
this.orderNo = options.orderNo;
this.source = options.source;
this.orderInfoUrl = options.orderInfoUrl;
this.orderToPay();
3 years ago
},
methods: {
//获取订单数据
orderToPay() {
let that = this;
// #ifdef H5
let params = {
"orderId": that.orderNo,
"openId": app.globalData.openId,
"orderScene": that.source,
"openIdType": 2
}
// #endif
// #ifdef MP
3 years ago
let params = {
"orderNo": that.orderNo,
"openId": app.globalData.openId,
"source": that.source
}
// #endif
3 years ago
qzOrderToPay(params).then(res => {
if (res.return_code == '000000') {
// #ifdef MP
uni.showLoading({
title: '支付中...'
})
uni.requestPayment({
"appId": res.return_data.appId,
"nonceStr": res.return_data.nonceStr,
"package": res.return_data.package,
"paySign": res.return_data.sign,
"signType": "MD5",
"timeStamp": res.return_data.timeStamp,
success: function(res) {
uni.hideLoading();
uni.showToast({
title: '支付成功'
})
uni.redirectTo({
url: '../tabBar/order/webUrl/webUrl?url=' + that
3 years ago
.orderInfoUrl+'&orderid='+that.orderNo+'&sour='+that.source
})
3 years ago
},
fail: function(err) {
uni.hideLoading();
uni.redirectTo({
url: '../tabBar/order/webUrl/webUrl?url=' + that
3 years ago
.orderInfoUrl+'&orderid='+that.orderNo+'&sour='+that.source
3 years ago
})
},
});
// #endif
//判断是否是公众号
// #ifdef H5
//判断微信浏览器
that.payRequest(res);
// #endif
} else {
uni.showToast({
title: res.return_msg,
icon: 'none'
})
uni.redirectTo({
3 years ago
url: '../tabBar/order/webUrl/webUrl?url=' + that.orderInfoUrl + '&orderid='+that.orderNo
3 years ago
})
}
3 years ago
})
},
payRequest: function(self) {
uni.showLoading({
title: '支付中...'
})
jweixin.config({
// debug: false, // 开启调试模式,调用的所有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,
3 years ago
success: function(res) {},
fail: function(res) {}
});
jweixin.chooseWXPay({
appId: self.return_data.appId,
3 years ago
timestamp: self.return_data
.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: self.return_data.nonceStr, // 支付签名随机串,不长于 32 位
3 years ago
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({
3 years ago
url: '../tabBar/user/user'
});
},
3 years ago
cancel: function(r) {},
fail: function(res) {}
});
});
jweixin.error(function(res) {
uni.showToast({
icon: 'none',
title: '支付失败了',
duration: 4000
});
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
/*alert("config信息验证失败");*/
});
},
3 years ago
}
}
</script>
<style>
</style>