提交 84d78079 作者: 王进

增加支付遮罩

上级 6dfe2032
......@@ -15,7 +15,6 @@ class WechatSDK {
this.sdkinit()
}
private debug: number // 1是测试模式,用于printf函数输出
private isPaying: boolean = false // 支付状态
private sdkinit() {
const that = this
//配置默认参数
......@@ -156,65 +155,66 @@ class WechatSDK {
public payOrder(Params) {
const that = this
that.MidasPaymentParams.offerId = SDKConfig.offerid
//根据支付状态来判断是否发起订单请求
if (!that.isPaying) {
that.isPaying = true
// 支付前先获取用户订单状态,如果没有未完成订单则继续支付
that.sdkRequest(sdkPortLinks.order, that.deepCopy({}, that.sdkParams, Params)).then(res => {
console.log("订单返回---->", res)
if (res.code == 0) {
if (res.data.weixin_mini_program_app_id) { // 跳小程序支付
const postParams = that.deepCopy({}, that.sdkParams, Params, {
weixin_mini_program_app_id: res.data.weixin_mini_program_app_id, // 跳转小程序的appid,获取新openid用
sub_product_code: res.data.sub_product_code, // 跳转小程序的productcode
pay_channel: res.data.pay_channel, // 支付方式改变
productKey: SDKConfig.productKey
}) // 合并后附上签名参数
const params = { // 跳转参数
appId: res.data.weixin_mini_program_app_id, // 跳转的小程序appid
path: '', // 跳转到首页
envVersion: SDKConfig.navPayEnv, //跳转方式
extraData: postParams,
success: () => { console.log("跳转成功") },
fail: () => { console.log("跳转失败") }
}
that.navigateToMiniProgram(params)
} else {
// 根据返回的用户订单状态判断是新订单还是未完成订单
if (res.data.order_type == 1) { // 新订单
that.MidasPaymentParams.buyQuantity = <number>(Params.money / 100) * <number>res.data.weixin_proportion // 充值金额
this.printf("SDK -> 发起支付参数:", 0)
this.printf(that.MidasPaymentParams, 0);
// 调微信米大师支付接口
(wx as any).requestMidasPayment(that.deepCopy({}, that.MidasPaymentParams, {
success: function (data) {
that.printf("SDK -> 支付成功:", 0)
that.printf(data, 0)
that.getCoins(that.deepCopy({}, that.sdkParams, { order_num: res.data.order_num }))
},
fail: function (err) {
that.printf("SDK -> 支付失败:", 0)
that.printf(err, 0)
}
}));
} else { // 已有未完成订单,弹窗提示
const params = {
title: SDKConfig.shareTitle,
content: '订单发货中,请稍候下单..'
that.LoadingOn();
// 支付前先获取用户订单状态,如果没有未完成订单则继续支付
that.sdkRequest(sdkPortLinks.order, that.deepCopy({}, that.sdkParams, Params)).then(res => {
console.log("订单返回---->", res)
if (res.code == 0) {
if (res.data.weixin_mini_program_app_id) { // 跳小程序支付
const postParams = that.deepCopy({}, that.sdkParams, Params, {
weixin_mini_program_app_id: res.data.weixin_mini_program_app_id, // 跳转小程序的appid,获取新openid用
sub_product_code: res.data.sub_product_code, // 跳转小程序的productcode
pay_channel: res.data.pay_channel, // 支付方式改变
productKey: SDKConfig.productKey
}) // 合并后附上签名参数
const params = { // 跳转参数
appId: res.data.weixin_mini_program_app_id, // 跳转的小程序appid
path: '', // 跳转到首页
envVersion: SDKConfig.navPayEnv, //跳转方式
extraData: postParams,
success: () => { console.log("跳转成功") },
fail: () => { console.log("跳转失败") }
}
that.LoadingOff();
that.navigateToMiniProgram(params)
} else {
// 根据返回的用户订单状态判断是新订单还是未完成订单
if (res.data.order_type == 1) { // 新订单
that.MidasPaymentParams.buyQuantity = <number>(Params.money / 100) * <number>res.data.weixin_proportion // 充值金额
this.printf("SDK -> 发起支付参数:", 0)
this.printf(that.MidasPaymentParams, 0);
// 调微信米大师支付接口
(wx as any).requestMidasPayment(that.deepCopy({}, that.MidasPaymentParams, {
success: function (data) {
that.printf("SDK -> 支付成功:", 0)
that.printf(data, 0)
that.getCoins(that.deepCopy({}, that.sdkParams, { order_num: res.data.order_num }))
},
fail: function (err) {
that.printf("SDK -> 支付失败:", 0)
that.printf(err, 0)
}
that.showModal(params)
}));
that.LoadingOff();
} else { // 已有未完成订单,弹窗提示
that.LoadingOff();
const params = {
title: SDKConfig.shareTitle,
content: '订单发货中,请稍候下单..'
}
that.showModal(params)
}
} else { // 输出订单失败消息
that.printf(res.msg, 1)
that.sdkAlert(res.msg)
}
that.isPaying = false
}, err => {
that.isPaying = false
console.log(err)
})
}
} else { // 输出订单失败消息
that.LoadingOff();
const errmsg = res.msg || '支付失败..'
that.printf(res.msg, 1)
that.sdkAlert(errmsg)
}
}, err => {
that.LoadingOff();
console.log(err)
})
}
private getCoins(orderParams) { // 通知服务端扣费
this.printf("SDK -> 通知扣费:", 0)
......@@ -606,6 +606,17 @@ class WechatSDK {
that.sdkAlert('微信版本不兼容,请升级..')
}
}
private LoadingOn() {
(wx as any).showLoading({
title: '请稍候..',
mask: true
})
}
private LoadingOff() {
(wx as any).hideLoading()
}
}
// md5加密
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论