diff --git a/js_sdk/lili-pay/wx-pay.js b/js_sdk/lili-pay/wx-pay.js index fea8916..5d292d1 100644 --- a/js_sdk/lili-pay/wx-pay.js +++ b/js_sdk/lili-pay/wx-pay.js @@ -1,7 +1,18 @@ +/** + * 微信小程序支付 + * 此处针对于微信小程序开发的支付插件 + * 第一次支付成功后会跳出订阅的消息 如果用户拒绝或同意都会跳转到支付成功页面 + * 如果点击订阅 会将状态写进缓存 之后不再提醒。 + * + * @param {sn,price} + */ + import { initiatePay } from "@/api/trade"; +import { getWeChatMpMessage } from "@/api/message.js"; class LiLiWXPay { constructor(...payList) { this.data = payList[0]; + console.log(payList); // 调用支付 this.pay = () => { uni.showLoading({ @@ -32,13 +43,7 @@ class LiLiWXPay { icon: "none", title: "支付成功!", }); - // 之后成功后跳转到支付成功页面 - uni.redirectTo({ - url: - "/pages/cart/payment/success?paymentMethod=WECHAT" + - "&payPrice=" + - this.data.price, - }); + sendMessage(payList[0].price); }, fail: (e) => { this.exception = e; @@ -59,4 +64,53 @@ class LiLiWXPay { } } +function sendMessage(price) { + //判断用户是否已经进行了订阅 + if (!uni.getStorageSync("acceptSubscribeMessage")) { + //订阅消息 + getWeChatMpMessage().then((res) => { + var message = res.data.result; + var templateid = message.map((item) => item.code); + uni.requestSubscribeMessage({ + tmplIds: templateid, + success: (res) => { + for (let key in res) { + // 表示用户拒绝订阅该信息 + if (res[key] == "reject") { + this.checked = false; + } else { + uni.setStorageSync("acceptSubscribeMessage", res); + } + } + }, + fail: (res) => { + uni.removeStorageSync("acceptSubscribeMessage"); + this.checked = false; + }, + complete: () => { + /** + * 已经支付成功 + */ + uni.redirectTo({ + url: + "/pages/cart/payment/success?paymentMethod=WECHAT" + + "&payPrice=" + + price, + }); + }, + }); + }); + } else { + /** + * 已经支付成功 + */ + uni.redirectTo({ + url: + "/pages/cart/payment/success?paymentMethod=WECHAT" + + "&payPrice=" + + price, + }); + } +} + export default LiLiWXPay; diff --git a/manifest.json b/manifest.json index 166ba0c..00ca42a 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name" : "lili商城", "appid" : "__UNI__C100675", "description" : "", - "versionName" : "4.0.30", - "versionCode" : 4000030, + "versionName" : "4.0.31", + "versionCode" : 4000031, "transformPx" : false, "app-plus" : { "compatible" : { diff --git a/pages/cart/payment/success.vue b/pages/cart/payment/success.vue index 3a67e16..aa2892a 100644 --- a/pages/cart/payment/success.vue +++ b/pages/cart/payment/success.vue @@ -7,36 +7,24 @@