H5-ThreeDoorder/unpackage/dist/build/web/static/js/mixin/PayMixin.js

173 lines
4.6 KiB
JavaScript

// var jweixin = require('jweixin-module');
import {
GetPaypackageInfor,
makeMinUrlAPI,
getPayParamsAPI
} from '@/request/pay/index.js';
class Payment {
static order_sn = 0
/**
* @param {String} pay_price 支付金额
* @param {String} order_sn 订单号
* @param {String} type 支付类型
* @param {String} return_url 支付时H5内部跳转路径
* @param {String} redirect 是否关闭调起支付的页面
* 该方法没有支付失败和成功回调函数必须由微信支付完成之后跳转至指定页面去查询订单状态然后根据订单状态再跳转值业务页面
*/
H5_Payment(data) {
uni.showLoading({
title: '支付中...'
});
const {
pay_price,
order_sn,
type,
return_url,
openid,
redirect=false,
PAY_TYPE = '1',
success = () => {},
file = () => {}
} = data;
if (!pay_price) throw new Error('缺少支付金额');
if (!order_sn) throw new Error('缺少订单号');
if (!type) throw new Error('缺少支付类型');
// 下单信息
const OrderData = {
pay_price,
order_sn,
type,
openid
};
// 判断是微信支付还是支付宝支付
if(PAY_TYPE == '1'){
// 微信内嵌WEBVIEW方式进入H5页面
if(getApp()['globalData']['parameters']?.isWechat){
OrderData['WechatRetreat'] = true;
// 先跳转至微信支付页面
try{
// wx.miniProgram.navigateTo({
// url: `/pages/wxpay/h5pay/h5pay?data=${encodeURIComponent(JSON.stringify(OrderData))}`
// });
wx.miniProgram.navigateTo({
url: `/pages/extension/shop/wxPay/wxPay?data=${encodeURIComponent(JSON.stringify(OrderData))}`
}); // Jin
// 延迟两秒后H5内部跳转
setTimeout(()=>{
uni.hideLoading();
if(return_url){
// 是否需要关闭调起支付的页面
if(redirect){
uni.redirectTo({
url:return_url
});
}else{
uni.navigateTo({
url:return_url
})
}
}
},2000)
}catch(e){
uni.hideLoading();
//TODO handle the exception
uni.showToast({
title:'支付错误',
icon:'none'
})
}
}else{
OrderData['WechatRetreat'] = false;
openMiniProgram({
path: `pages/wxpay/h5pay/h5pay?data=${encodeURIComponent(JSON.stringify(OrderData))}`,
id: 'gh_faaea9b90759',
// type: 'release',
type: 'preview'
})
// 其他方式进入H5页面(APP)
// 反之使用跳转连接进入
// makeMinUrlAPI({
// path :'/pages/wxpay/h5pay/h5pay',
// query:`data=${encodeURIComponent(JSON.stringify(OrderData))}`,
// // uu_id:17551,
// // release 正式版
// // trial 测试版
// // develop 开发板
// env_version:'develop',
// }).then(res=>{
// // console.log(res);
// console.log(res['data']['openlink'],'openlink');
// // return
// location.href = res['data']['openlink'];
// // 延迟两秒后H5内部跳转
setTimeout(()=>{
uni.hideLoading();
if(return_url){
// 是否需要关闭调起支付的页面
if(redirect){
uni.redirectTo({
url:return_url
});
}else{
uni.navigateTo({
url:return_url
})
}
}
},2000)
// })
}
}else{
OrderData['WechatRetreat'] = true;
window.location.href=`https://ds.alipay.com/?scheme=${encodeURIComponent(`alipays://platformapi/startapp?appId=2021003130603407&page=pages/wxpay/h5pay/h5pay?data=${encodeURIComponent(JSON.stringify(OrderData))}`)}`
// window.location.href = `https://ds.alipay.com/?scheme=alipays://platformapi/startapp?appId=2021003130603407&page=pages/wxpay/h5pay/h5pay?data=${encodeURIComponent(JSON.stringify(OrderData))}`;
// 支付宝支付
// this.WX_Pay(data);
}
}
// 支付宝支付
App_Pay(){
// 获取支付包信息
}
// 再次支付
/**
* @param {String} order_sn 再次支付订单号
* @param {String} type 再次支付订单类型
* @param {String} return_url 再次支付回跳地址
*/
Repayment(data){
getPayParamsAPI({
order_sn:data['order_sn'],
type:data['type']
}).then(res=>{
console.log({});
this.H5_Payment({
// 此处将传入数据与接口数据合并,重复则替换为后者
...data,...res['data']
})
})
}
set PayOrder(value){
this['order_sn'] = value;
}
// 获取当前执行支付的订单号
get PayOrder(){
return this['order_sn']
}
}
const install = (Vue) => {
Vue.prototype.$Payment = new Payment();
}
export default {
install
};