|
@@ -25,37 +25,43 @@
|
|
* 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no
|
|
* 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no
|
|
*/
|
|
*/
|
|
createOrder(provider){
|
|
createOrder(provider){
|
|
-
|
|
|
|
this.http.request({
|
|
this.http.request({
|
|
url: '/level-one-server/app/WalletManage/topupSave',
|
|
url: '/level-one-server/app/WalletManage/topupSave',
|
|
- //url: '/level-one-server/app/WalletManage/wxPay/createOrder',
|
|
|
|
data: {
|
|
data: {
|
|
amount: this.total_fee, // 支付金额,单位分 100 = 1元
|
|
amount: this.total_fee, // 支付金额,单位分 100 = 1元
|
|
goodsName: '服务点充值'
|
|
goodsName: '服务点充值'
|
|
},
|
|
},
|
|
success: res => {
|
|
success: res => {
|
|
- this.user.wallet = this.user.wallet + this.total_fee;
|
|
|
|
|
|
+ console.log('WxPayAppOrderResult:',res)
|
|
|
|
+ // 调起支付
|
|
|
|
+ this.orderPayment(res.data.data);
|
|
|
|
+ this.transaction_id = res.data.data.prepayId;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 调起支付
|
|
|
|
+ orderPayment(data){
|
|
|
|
+ console.log('fff',data)
|
|
|
|
+ uni.requestPayment({
|
|
|
|
+ "provider": "wxpay",
|
|
|
|
+ "orderInfo": data,
|
|
|
|
+ success:(res)=>{
|
|
|
|
+ this.user.wallet = this.user.wallet + this.total_fee;
|
|
console.log("this.user",this.user)
|
|
console.log("this.user",this.user)
|
|
uni.setStorageSync('info', this.user);
|
|
uni.setStorageSync('info', this.user);
|
|
- uni.showToast({
|
|
|
|
- title: '充值成功!'
|
|
|
|
- });
|
|
|
|
- uni.navigateBack({
|
|
|
|
- data:1
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
+ url: '/pages/wallet/topup/detail?transaction_id=' + data.prepayId
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ fail:(err)=>{
|
|
|
|
+ // 发起支付失败
|
|
|
|
+ uni.showToast({title: '发起支付失败!'+err.errMsg,});
|
|
|
|
+ }
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
- // 打开查询订单的弹窗
|
|
|
|
- getOrderPopup(key){
|
|
|
|
- if (key) {
|
|
|
|
- this.$refs.getOrderPopup.open();
|
|
|
|
- } else {
|
|
|
|
- this.$refs.getOrderPopup.close();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
+
|
|
// 查询支付状态
|
|
// 查询支付状态
|
|
async getOrder() {
|
|
async getOrder() {
|
|
this.getOrderRes = {};
|
|
this.getOrderRes = {};
|
|
@@ -78,82 +84,8 @@
|
|
icon: "none"
|
|
icon: "none"
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- },
|
|
|
|
-
|
|
|
|
- // 监听事件 - 支付订单创建成功(此时用户还未支付)
|
|
|
|
- onCreate(res){
|
|
|
|
- console.log('create: ', res);
|
|
|
|
- // 如果只是想生成支付二维码,不需要组件自带的弹窗,则在这里可以获取到支付二维码 qr_code_image
|
|
|
|
- },
|
|
|
|
- // 监听事件 - 支付成功
|
|
|
|
- onSuccess(res){
|
|
|
|
- console.log('success: ', res);
|
|
|
|
- if (res.user_order_success) {
|
|
|
|
- // 代表用户已付款,且你自己写的回调成功并正确执行了
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // 代表用户已付款,但你自己写的回调执行失败(通常是因为你的回调代码有问题)
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 日期格式化
|
|
|
|
- * @params {Date || Number} date 需要格式化的时间
|
|
|
|
- * timeFormat(new Date(),"yyyy-MM-dd hh:mm:ss");
|
|
|
|
- */
|
|
|
|
- timeFormat(time, fmt = 'yyyy-MM-dd hh:mm:ss', targetTimezone = 8){
|
|
|
|
- try {
|
|
|
|
- if (!time) {
|
|
|
|
- return "";
|
|
|
|
- }
|
|
|
|
- if (typeof time === "string" && !isNaN(time)) time = Number(time);
|
|
|
|
- // 其他更多是格式化有如下:
|
|
|
|
- // yyyy-MM-dd hh:mm:ss|yyyy年MM月dd日 hh时MM分等,可自定义组合
|
|
|
|
- let date;
|
|
|
|
- if (typeof time === "number") {
|
|
|
|
- if (time.toString().length == 10) time *= 1000;
|
|
|
|
- date = new Date(time);
|
|
|
|
- } else {
|
|
|
|
- date = time;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const dif = date.getTimezoneOffset();
|
|
|
|
- const timeDif = dif * 60 * 1000 + (targetTimezone * 60 * 60 * 1000);
|
|
|
|
- const east8time = date.getTime() + timeDif;
|
|
|
|
-
|
|
|
|
- date = new Date(east8time);
|
|
|
|
- let opt = {
|
|
|
|
- "M+": date.getMonth() + 1, //月份
|
|
|
|
- "d+": date.getDate(), //日
|
|
|
|
- "h+": date.getHours(), //小时
|
|
|
|
- "m+": date.getMinutes(), //分
|
|
|
|
- "s+": date.getSeconds(), //秒
|
|
|
|
- "q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
- "S": date.getMilliseconds() //毫秒
|
|
|
|
- };
|
|
|
|
- if (/(y+)/.test(fmt)) {
|
|
|
|
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
|
|
- }
|
|
|
|
- for (let k in opt) {
|
|
|
|
- if (new RegExp("(" + k + ")").test(fmt)) {
|
|
|
|
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (opt[k]) : (("00" + opt[k]).substr(("" + opt[k]).length)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return fmt;
|
|
|
|
- } catch (err) {
|
|
|
|
- // 若格式错误,则原值显示
|
|
|
|
- return time;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
+ },
|
|
},
|
|
},
|
|
- computed: {
|
|
|
|
- // 计算当前是否是ios app
|
|
|
|
- isIosAppCom(){
|
|
|
|
- let info = uni.getSystemInfoSync();
|
|
|
|
- return info.uniPlatform === 'app' && info.osName === 'ios' ? true : false;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|