fix: 🐛 1:修改微信订阅,更改为每次支付成功之后请求订阅信息。2:修改微信支付在真机中支付成功跳转问题

This commit is contained in:
RyanRan
2024-07-02 11:58:06 +08:00
parent 0b601e4f3e
commit 31c341148f
5 changed files with 164 additions and 172 deletions

20
App.vue
View File

@@ -2,15 +2,15 @@
/** /**
* vuex管理登录状态具体可以参考官方登录模板示例 * vuex管理登录状态具体可以参考官方登录模板示例
*/ */
import { import config from "@/config/config";
mapMutations
} from "vuex";
import APPUpdate from "@/plugins/APPUpdate";
import { import {
getClipboardData getClipboardData
} from "@/js_sdk/h5-copy/h5-copy.js"; } from "@/js_sdk/h5-copy/h5-copy.js";
import config from "@/config/config"; import APPUpdate from "@/plugins/APPUpdate";
import storage from "@/utils/storage"; import storage from "@/utils/storage";
import {
mapMutations
} from "vuex";
@@ -20,14 +20,7 @@
* */ * */
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
wx.onAppRoute((res) => { wx.onAppRoute((res) => {
const pages = getCurrentPages();
console.log("pages:" + pages.length,pages);
if (pages.length > 3) {
delete getCurrentPages()[2]
}
console.log('路由监听', {
res
})
}) })
// #endif // #endif
@@ -43,6 +36,7 @@
* 监听返回 * 监听返回
*/ */
onBackPress(e) { onBackPress(e) {
console.log("onBackPress-APP", e);
if (e.from == "backbutton") { if (e.from == "backbutton") {
let routes = getCurrentPages(); let routes = getCurrentPages();
let curRoute = routes[routes.length - 1].options; let curRoute = routes[routes.length - 1].options;

View File

@@ -7,8 +7,8 @@
* @param {sn,price} * @param {sn,price}
*/ */
import { initiatePay } from "@/api/trade";
import { getWeChatMpMessage } from "@/api/message.js"; import { getWeChatMpMessage } from "@/api/message.js";
import { initiatePay } from "@/api/trade";
class LiLiWXPay { class LiLiWXPay {
constructor(...payList) { constructor(...payList) {
this.data = payList[0]; this.data = payList[0];
@@ -65,8 +65,8 @@ class LiLiWXPay {
} }
function sendMessage(price) { function sendMessage(price) {
//判断用户是否已经进行了订阅
if (!uni.getStorageSync("acceptSubscribeMessage")) {
//订阅消息 //订阅消息
getWeChatMpMessage().then((res) => { getWeChatMpMessage().then((res) => {
var message = res.data.result; var message = res.data.result;
@@ -74,20 +74,18 @@ function sendMessage(price) {
uni.requestSubscribeMessage({ uni.requestSubscribeMessage({
tmplIds: templateid, tmplIds: templateid,
success: (res) => { success: (res) => {
for (let key in res) {
// 表示用户拒绝订阅该信息
if (res[key] == "reject") {
this.checked = false;
} else {
uni.setStorageSync("acceptSubscribeMessage", res);
}
}
}, },
fail: (res) => { fail: (res) => {
uni.removeStorageSync("acceptSubscribeMessage"); console.log('fail', res)
this.checked = false; uni.showToast({
icon: "none",
title: "订阅消息失败",
})
}, },
complete: () => { complete: (res) => {
console.log('complete', res)
/** /**
* 已经支付成功 * 已经支付成功
*/ */
@@ -100,17 +98,7 @@ function sendMessage(price) {
}, },
}); });
}); });
} else {
/**
* 已经支付成功
*/
uni.redirectTo({
url:
"/pages/cart/payment/success?paymentMethod=WECHAT" +
"&payPrice=" +
price,
});
}
} }
export default LiLiWXPay; export default LiLiWXPay;

View File

@@ -60,7 +60,7 @@ export default {
this.from = options.from || ""; this.from = options.from || "";
this.payPrice = options.payPrice || 0; this.payPrice = options.payPrice || 0;
this.orderType = options.orderType; this.orderType = options.orderType;
// this.sendMessage()
}, },
methods: { methods: {
checkOrder() { checkOrder() {
@@ -77,11 +77,6 @@ export default {
this.navigateTo("/pages/order/myOrder?status=0"); this.navigateTo("/pages/order/myOrder?status=0");
} }
}, },
changeStatus(val) {
if (val) {
this.sendMessage();
}
},
navigateTo(url, type) { navigateTo(url, type) {
if (type === "switch") { if (type === "switch") {
@@ -105,6 +100,7 @@ export default {
padding: 0 20rpx 20rpx; padding: 0 20rpx 20rpx;
width: 80%; width: 80%;
} }
.pay-btns { .pay-btns {
display: flex; display: flex;
width: 50%; width: 50%;

View File

@@ -386,13 +386,13 @@
</div> </div>
</template> </template>
<script> <script>
import * as API_Trade from "@/api/trade";
import * as API_Address from "@/api/address"; import * as API_Address from "@/api/address";
import * as API_Order from "@/api/order"; import * as API_Order from "@/api/order";
import * as API_Trade from "@/api/trade";
import configs from "@/config/config";
import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
import invoices from "@/pages/order/invoice/setInvoice"; import invoices from "@/pages/order/invoice/setInvoice";
import { mapState } from "vuex"; import { mapState } from "vuex";
import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
import configs from "@/config/config";
export default { export default {
onLoad: function (val) { onLoad: function (val) {
this.routerVal = val; this.routerVal = val;
@@ -445,6 +445,8 @@ export default {
notSupportFreight: [], //不支持运费 notSupportFreight: [], //不支持运费
notSupportFreightGoodsList: ["以下商品超出配送范围:"], notSupportFreightGoodsList: ["以下商品超出配送范围:"],
storeAddress: "", storeAddress: "",
originOrderData:"", // 原始订单数据
}; };
}, },
watch: { watch: {
@@ -482,6 +484,7 @@ export default {
* 监听返回 * 监听返回
*/ */
onBackPress(e) { onBackPress(e) {
console.log("onBackPress", e);
if (e.from == "backbutton") { if (e.from == "backbutton") {
let routes = getCurrentPages(); let routes = getCurrentPages();
let curRoute = routes[routes.length - 1].options; let curRoute = routes[routes.length - 1].options;
@@ -495,7 +498,7 @@ export default {
}); });
} }
}); });
console.log("curRoute.addId",curRoute.addId)
if (curRoute.addId) { if (curRoute.addId) {
uni.reLaunch({ uni.reLaunch({
url: "/pages/tabbar/cart/cartList", url: "/pages/tabbar/cart/cartList",
@@ -785,20 +788,31 @@ export default {
this.notSupportFreight = []; this.notSupportFreight = [];
// 获取结算参数 // 获取结算参数
API_Trade.getCheckoutParams(this.routerVal.way).then((res) => { API_Trade.getCheckoutParams(this.routerVal.way).then((res) => {
// 获取结算参数 进行首次判断
this.originOrderData = this.orderMessage ? JSON.parse(JSON.stringify(this.orderMessage)) : ""
if ( if (
!res.data.result.checkedSkuList || !res.data.result.checkedSkuList ||
res.data.result.checkedSkuList.length === 0 res.data.result.checkedSkuList.length === 0
) { ) {
if(!this.originOrderData.checkedSkuList.length){
uni.switchTab({ uni.switchTab({
url: "/pages/tabbar/cart/cartList", url: "/pages/tabbar/cart/cartList",
}); });
} }
}
if (res.data.result.skuList.length <= 0) { if (res.data.result.skuList.length <= 0) {
if(!this.originOrderData.skuList.length){
uni.navigateTo({ uni.navigateTo({
url: "/pages/order/myOrder?status=0", url: "/pages/order/myOrder?status=0",
}); });
} }
}
let repeatData; let repeatData;
res.data.result.cartList.forEach((item, index) => { res.data.result.cartList.forEach((item, index) => {
// 如果已经写过备注信息的话赋值 // 如果已经写过备注信息的话赋值

View File

@@ -1,16 +1,16 @@
import Request from "@/lib/request/index.js";
import { import {
refreshTokenFn refreshTokenFn
} from "@/api/login.js"; } from "@/api/login.js";
import storage from "@/utils/storage.js"; import api from "@/config/api.js";
import Request from "@/lib/request/index.js";
import Foundation from "@/utils/Foundation.js";
import { import {
md5 md5
} from "@/utils/md5.js"; } from "@/utils/md5.js";
import Foundation from "@/utils/Foundation.js"; import storage from "@/utils/storage.js";
import api from "@/config/api.js";
import jwt from '@/js_sdk/t-jwt/jwt.js';
import uuid from "@/utils/uuid.modified.js"; import uuid from "@/utils/uuid.modified.js";
import jwt from '@/js_sdk/t-jwt/jwt.js'
import store from "../store"; import store from "../store";