From 915aee91438d88917e0fea0b3326f7fc2c32a4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lemon=E6=A9=AA?= <17633066053@163.com> Date: Mon, 23 Aug 2021 10:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=AE=A2=E9=98=85=E8=BF=9B=E8=A1=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js_sdk/lili-pay/wx-pay.js | 68 ++++++++++++++++++++++++++++++---- manifest.json | 4 +- pages/cart/payment/success.vue | 38 +------------------ 3 files changed, 64 insertions(+), 46 deletions(-) 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 @@