提交 84d78079 作者: 王进

增加支付遮罩

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