Merge remote-tracking branch 'origin/feature/mall_product' into feature/mall_product

pull/2/head
小小张 2023-05-26 12:00:47 +08:00
commit df46d2a7cb
5 changed files with 112 additions and 111 deletions

View File

@ -240,5 +240,5 @@ wx:
database: 16 # 数据库索引 database: 16 # 数据库索引
password: 20221122@dev # 密码,建议生产环境开启 password: 20221122@dev # 密码,建议生产环境开启
phone: phone:
query-url: http://phone.cyywl.top/cyywl-phone-query-api/ query-url: http://cy-phone-bill-inquiry-server:4006/cyywl-phone-query-api/
token: eyIwLnR5cCI6IkpXVCIsImFsZyI6IkhTNTEyIn0 token: eyIwLnR5cCI6IkpXVCIsImFsZyI6IkhTNTEyIn0

View File

@ -222,3 +222,7 @@ wx:
port: 6369 # 端口 port: 6369 # 端口
database: 16 # 数据库索引 database: 16 # 数据库索引
password: 20221122@dev # 密码,建议生产环境开启 password: 20221122@dev # 密码,建议生产环境开启
phone:
query-url: https://cmx.bskies.cc:8000/cyywl-phone-query-api/
token: eyIwLnR5cCI6IkpXVCIsImFsZyI6IkhTNTEyIn0

View File

@ -20,8 +20,7 @@
</view> </view>
</view> </view>
<view class="mask" @click='close' v-if="pay_close"></view> <view class="mask" @click='close' v-if="pay_close"></view>
<button style="cursor: pointer;display:none;" class="clipboard" <button style="cursor: pointer;display:none;" class="clipboard" :data-clipboard-text="alipayLink">
:data-clipboard-text="alipayLink">
</button> </button>
<!-- 支付宝支付界面 --> <!-- 支付宝支付界面 -->
<u-modal :show="alipayShow" title="支付宝支付" @confirm="handleConfirm"> <u-modal :show="alipayShow" title="支付宝支付" @confirm="handleConfirm">
@ -38,6 +37,7 @@
wechatOrderPay, wechatOrderPay,
wechatQueryPayResult wechatQueryPayResult
} from '@/api/order.js'; } from '@/api/order.js';
import uniPay from '@/libs/pay.js'
import { import {
memberTopUp memberTopUp
} from '@/api/member.js'; } from '@/api/member.js';
@ -82,126 +82,32 @@
this.alipayShow = false this.alipayShow = false
window.location.reload() window.location.reload()
}, },
//
_copy(context) {
//
let oInput = document.createElement('input');
//
oInput.value = context;
//
document.body.appendChild(oInput);
//
oInput.select();
//
document.execCommand('Copy');
//
this.$util.Tips({
title: '复制链接成功'
})
this.alipayShow = true
//
oInput.remove();
},
close: function() { close: function() {
this.$emit('onChangeFun', { this.$emit('onChangeFun', {
action: 'payClose' action: 'payClose'
}); });
}, },
// JSAPI // JSAPI
wxPayJSAPI(payData) {
function onBridgeReady() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId": payData.appId, //ID
"timeStamp": payData.timeStamp, //1970
"nonceStr": payData.nonceStr, //
"package": payData.packageValue,
"signType": payData.signType, //
"paySign": payData.paySign //
},
function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
window.location.reload()
// uni.switchTab({
// url: '/pages/member_application/index'
// })
}
})
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady()
}
},
goPay: function(paytype) { goPay: function(paytype) {
let that = this; let that = this;
if (that.payInfo.orderInfos.length === 0) return that.$util.Tips({ if (that.payInfo.orderInfos.length === 0) return that.$util.Tips({
title: '请选择要支付的订单' title: '请选择要支付的订单'
}); });
uni.showLoading({ uniPay({
title: '支付中', payInfo: that.payInfo,
mask: true payType: paytype,
}); createOrderFun: memberTopUp,
if(paytype === 'WXPAY' && that.openId) { wxPaySuccess: () => {
that.payInfo.openid = that.openId window.location.reload()
},
} else if(paytype === 'WXPAY' && !that.openId){ aliPaySuccess: (link) => {
return that.$util.Tips({ that.alipayLink = link
title: '请在微信客户端进行支付操作' setTimeout(() => {
});
}
memberTopUp({
...that.payInfo,
payType: paytype
}).then(res => {
let jsConfig = res.data
switch (paytype) {
case 'WXPAY':
uni.hideLoading();
that.wxPayJSAPI(jsConfig.jsapiResult)
break;
case 'ALIPAY':
uni.hideLoading();
this.alipayLink = jsConfig.body
// this._copy(jsConfig.body)
setTimeout(()=>{
document.querySelector(".clipboard").click(); document.querySelector(".clipboard").click();
this.alipayShow = true that.alipayShow = true
}, 500) }, 500)
// const div = document.createElement('div')
// /* data.content */
// div.innerHTML = jsConfig.body
// document.body.appendChild(div)
// document.forms[0].submit()
break;
case 'weixinh5':
uni.hideLoading();
location.replace(jsConfig.mwebUrl + '&redirect_url=' + window.location.protocol +
'//' + window.location.host + goPages + '&status=1');
return that.$util.Tips({
title: "支付中",
icon: 'success'
}, () => {
that.$emit('onChangeFun', {
action: 'pay_complete'
});
});
break;
} }
}).catch(err => {
uni.hideLoading();
return that.$util.Tips({
title: err
}, () => {
that.$emit('onChangeFun', {
action: 'pay_fail'
});
});
}) })
} }
} }

91
yudao-ui-app/libs/pay.js Normal file
View File

@ -0,0 +1,91 @@
import util from 'utils/util'
import store from '@/store'
const payTypes = ['WXPAY', 'ALIPAY']
/**
* 统一支付处理方法
* @param payInfo // 支付下单信息
* @param payType // 支付类型
* @param createOrderFun // 预下单方法
* @param wxPaySuccess // 微信支付下单支付成功回调
* @param aliPaySuccess // 支付宝支付下单成功回调
*/
const unityPay = (options) => {
let _options = {
payInfo: {},
payType: '',
createOrderFun: () => {},
wxPaySuccess: () => {},
aliPaySuccess: () => {}
}
Object.assign(_options, options)
if (!_options.payType) {
return util.Tips({
title: '请选择支付方式'
})
}
if (!payTypes.includes(_options.payType)) {
throw new Error('支付方式参数值为 WXPAY、ALIPAY')
}
// 目前微信只支持JSAPIh5支付开通后取消该验证
const openId = store.state.app.openId || ''
if (_options.payType === 'WXPAY' && !openId) {
return util.Tips({
title: '请在微信客户端进行支付操作'
})
}
_options.payInfo.openid = openId
uni.showLoading({
title: '支付中',
mask: true
})
_options.createOrderFun({
..._options.payInfo,
payType: _options.payType
}).then(res => {
const payConfig = res.data
switch (_options.payType) {
// 微信JSAPI支付
case 'WXPAY':
wxPayJSAPI(payConfig.jsapiResult)
break
case 'ALIPAY':
_options.aliPaySuccess(payConfig.body)
break
}
}).catch(() => {
util.Tips({
title: '预下单失败'
})
}).finally(uni.hideLoading)
}
const wxPayJSAPI = (payData) => {
function onBridgeReady() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId": payData.appId, //公众号ID由商户传入
"timeStamp": payData.timeStamp, //时间戳自1970年以来的秒数
"nonceStr": payData.nonceStr, //随机串
"package": payData.packageValue,
"signType": payData.signType, //微信签名方式:
"paySign": payData.paySign //微信签名
},
function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
_options.wxPaySuccess()
}
})
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady()
}
}
export default unityPay

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB