mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-24 05:46:04 +08:00
优化商城支付对接功能
This commit is contained in:
parent
7d6786033a
commit
6588361088
@ -14,9 +14,14 @@ import {
|
|||||||
dateTimeStringToDateString
|
dateTimeStringToDateString
|
||||||
} from '../../utils/DateUtil.js'
|
} from '../../utils/DateUtil.js'
|
||||||
|
|
||||||
|
import WexinPayFactory from '../../factory/WexinPayFactory.js'
|
||||||
|
|
||||||
|
|
||||||
const ACTION_NAVIGATE_TO = "navigateTo"; // 跳转
|
const ACTION_NAVIGATE_TO = "navigateTo"; // 跳转
|
||||||
const ACTION_REFRESH_TOKEN = "refreshToken";
|
const ACTION_REFRESH_TOKEN = "refreshToken";
|
||||||
|
const ACTION_NAVIGATE_TO_PAGE = "navigateToPage";
|
||||||
|
const ACTION_PAY_ORDER = "payOrder";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +67,7 @@ export function checkSession(that, url) {
|
|||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/hcWebViewRefresh/hcWebViewRefresh?url=' + _url
|
url: '/pages/hcWebViewRefresh/hcWebViewRefresh?url=' + _url
|
||||||
});
|
});
|
||||||
},err=>{
|
}, err => {
|
||||||
|
|
||||||
});
|
});
|
||||||
}, function(error) { //回话过期
|
}, function(error) { //回话过期
|
||||||
@ -91,6 +96,80 @@ export function checkSession(that, url) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCurrentPage(){
|
||||||
|
let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
|
||||||
|
let curRoute = routes[routes.length - 1].route //获取当前页面路由
|
||||||
|
return '/'+curRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toPay(data, _url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let obj = {};
|
||||||
|
let orderInfo = {};
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
uni.requestPayment({
|
||||||
|
'timeStamp': data.timeStamp,
|
||||||
|
'nonceStr': data.nonceStr,
|
||||||
|
'package': data.package,
|
||||||
|
'signType': data.signType,
|
||||||
|
'paySign': data.sign,
|
||||||
|
'success': function(res) {
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付成功",
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
uni.redirectTo({
|
||||||
|
url:getCurrentPage()+'?url='+_url
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'fail': function(err) {
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
// #ifdef H5
|
||||||
|
WexinPayFactory.wexinPay(data, function() {
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付成功",
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
uni.redirectTo({
|
||||||
|
url:getCurrentPage()+'?url='+_url
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
obj = getPayInfo(data);
|
||||||
|
// 第二种写法,传对象字符串
|
||||||
|
orderInfo = JSON.stringify(obj)
|
||||||
|
uni.requestPayment({
|
||||||
|
provider: 'wxpay',
|
||||||
|
orderInfo: orderInfo, //微信、支付宝订单数据
|
||||||
|
success: function(res) {
|
||||||
|
console.log("购买", res)
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付成功",
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
uni.redirectTo({
|
||||||
|
url:getCurrentPage()+'?url='+_url
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: function(err) {
|
||||||
|
console.log("购买失败", err)
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} event事件
|
* @param {Object} event事件
|
||||||
*/
|
*/
|
||||||
@ -107,6 +186,10 @@ export function reciveMessage(event, that) {
|
|||||||
} else if (_data.action == ACTION_REFRESH_TOKEN) {
|
} else if (_data.action == ACTION_REFRESH_TOKEN) {
|
||||||
//校验是否登录,如果没有登录跳转至温馨提示页面
|
//校验是否登录,如果没有登录跳转至温馨提示页面
|
||||||
checkSession(that, _data.url);
|
checkSession(that, _data.url);
|
||||||
|
} else if (_data.action == ACTION_NAVIGATE_TO_PAGE) {
|
||||||
|
window.location.href = _data.url;
|
||||||
|
} else if (_data.action == ACTION_PAY_ORDER) {
|
||||||
|
toPay(_data.data, _data.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,14 @@
|
|||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
let _url = options.url;
|
let _url = options.url;
|
||||||
|
|
||||||
this.url = conf.mallUrl + '#' + _url;
|
if(_url.indexOf("http")>-1){
|
||||||
|
_url = _url.replace("**","?");
|
||||||
|
_url = _url.replace("@@","&");
|
||||||
|
_url = _url.replace("$$","#");
|
||||||
|
this.url = _url;
|
||||||
|
}else{
|
||||||
|
this.url = conf.mallUrl + '#' + _url;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('_hcUrl',this.url);
|
console.log('_hcUrl',this.url);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user