mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-16 15:35:52 +08:00
fix: 🐛 1:修改微信订阅,更改为每次支付成功之后请求订阅信息。2:修改微信支付在真机中支付成功跳转问题
This commit is contained in:
26
App.vue
26
App.vue
@@ -2,15 +2,15 @@
|
||||
/**
|
||||
* vuex管理登录状态,具体可以参考官方登录模板示例
|
||||
*/
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
import APPUpdate from "@/plugins/APPUpdate";
|
||||
import {
|
||||
getClipboardData
|
||||
} from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
import config from "@/config/config";
|
||||
import storage from "@/utils/storage";
|
||||
import {
|
||||
getClipboardData
|
||||
} from "@/js_sdk/h5-copy/h5-copy.js";
|
||||
import APPUpdate from "@/plugins/APPUpdate";
|
||||
import storage from "@/utils/storage";
|
||||
import {
|
||||
mapMutations
|
||||
} from "vuex";
|
||||
|
||||
|
||||
|
||||
@@ -20,14 +20,7 @@
|
||||
* */
|
||||
// #ifdef MP-WEIXIN
|
||||
wx.onAppRoute((res) => {
|
||||
const pages = getCurrentPages();
|
||||
console.log("pages:" + pages.length,pages);
|
||||
if (pages.length > 3) {
|
||||
delete getCurrentPages()[2]
|
||||
}
|
||||
console.log('路由监听', {
|
||||
res
|
||||
})
|
||||
|
||||
})
|
||||
// #endif
|
||||
|
||||
@@ -43,6 +36,7 @@
|
||||
* 监听返回
|
||||
*/
|
||||
onBackPress(e) {
|
||||
console.log("onBackPress-APP", e);
|
||||
if (e.from == "backbutton") {
|
||||
let routes = getCurrentPages();
|
||||
let curRoute = routes[routes.length - 1].options;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* @param {sn,price}
|
||||
*/
|
||||
|
||||
import { initiatePay } from "@/api/trade";
|
||||
import { getWeChatMpMessage } from "@/api/message.js";
|
||||
import { initiatePay } from "@/api/trade";
|
||||
class LiLiWXPay {
|
||||
constructor(...payList) {
|
||||
this.data = payList[0];
|
||||
@@ -65,52 +65,40 @@ 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,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//订阅消息
|
||||
getWeChatMpMessage().then((res) => {
|
||||
var message = res.data.result;
|
||||
var templateid = message.map((item) => item.code);
|
||||
uni.requestSubscribeMessage({
|
||||
tmplIds: templateid,
|
||||
success: (res) => {
|
||||
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log('fail', res)
|
||||
uni.showToast({
|
||||
icon: "none",
|
||||
title: "订阅消息失败",
|
||||
})
|
||||
},
|
||||
complete: (res) => {
|
||||
console.log('complete', res)
|
||||
|
||||
/**
|
||||
* 已经支付成功
|
||||
*/
|
||||
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;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
¥{{ Number(payPrice) | unitPrice }}
|
||||
</div>
|
||||
<div class="pay-btns">
|
||||
<div v-show="!from" @click="checkOrder">查看{{this.orderType == "RECHARGE" ? '余额' : '订单'}}</div>
|
||||
<div v-show="!from" @click="checkOrder">查看{{ this.orderType == "RECHARGE" ? '余额' : '订单' }}</div>
|
||||
<div @click="navigateTo('/pages/tabbar/home/index', 'switch')">回到首页</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,7 +16,7 @@
|
||||
<div>
|
||||
支付方式:
|
||||
</div>
|
||||
<div>{{paymentMethod | paymentTypeFilter}}</div>
|
||||
<div>{{ paymentMethod | paymentTypeFilter }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,7 +60,7 @@ export default {
|
||||
this.from = options.from || "";
|
||||
this.payPrice = options.payPrice || 0;
|
||||
this.orderType = options.orderType;
|
||||
// this.sendMessage()
|
||||
|
||||
},
|
||||
methods: {
|
||||
checkOrder() {
|
||||
@@ -77,11 +77,6 @@ export default {
|
||||
this.navigateTo("/pages/order/myOrder?status=0");
|
||||
}
|
||||
},
|
||||
changeStatus(val) {
|
||||
if (val) {
|
||||
this.sendMessage();
|
||||
}
|
||||
},
|
||||
|
||||
navigateTo(url, type) {
|
||||
if (type === "switch") {
|
||||
@@ -105,6 +100,7 @@ export default {
|
||||
padding: 0 20rpx 20rpx;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.pay-btns {
|
||||
display: flex;
|
||||
width: 50%;
|
||||
@@ -112,7 +108,7 @@ export default {
|
||||
margin: 0 auto;
|
||||
color: #fff;
|
||||
|
||||
> div {
|
||||
>div {
|
||||
padding: 6px 12px;
|
||||
border: 1px solid #fff;
|
||||
border-radius: 100px;
|
||||
@@ -146,7 +142,7 @@ export default {
|
||||
border-radius: 20rpx;
|
||||
background: rgba($color: $main-color, $alpha: 0.2);
|
||||
|
||||
> h2 {
|
||||
>h2 {
|
||||
margin-top: 20rpx;
|
||||
font-size: 40rpx;
|
||||
color: $main-color;
|
||||
|
||||
@@ -386,13 +386,13 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import * as API_Trade from "@/api/trade";
|
||||
import * as API_Address from "@/api/address";
|
||||
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 { mapState } from "vuex";
|
||||
import LiLiWXPay from "@/js_sdk/lili-pay/wx-pay.js";
|
||||
import configs from "@/config/config";
|
||||
export default {
|
||||
onLoad: function (val) {
|
||||
this.routerVal = val;
|
||||
@@ -445,6 +445,8 @@ export default {
|
||||
notSupportFreight: [], //不支持运费
|
||||
notSupportFreightGoodsList: ["以下商品超出配送范围:"],
|
||||
storeAddress: "",
|
||||
|
||||
originOrderData:"", // 原始订单数据
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
@@ -482,6 +484,7 @@ export default {
|
||||
* 监听返回
|
||||
*/
|
||||
onBackPress(e) {
|
||||
console.log("onBackPress", e);
|
||||
if (e.from == "backbutton") {
|
||||
let routes = getCurrentPages();
|
||||
let curRoute = routes[routes.length - 1].options;
|
||||
@@ -495,7 +498,7 @@ export default {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log("curRoute.addId",curRoute.addId)
|
||||
if (curRoute.addId) {
|
||||
uni.reLaunch({
|
||||
url: "/pages/tabbar/cart/cartList",
|
||||
@@ -785,18 +788,29 @@ export default {
|
||||
this.notSupportFreight = [];
|
||||
// 获取结算参数
|
||||
API_Trade.getCheckoutParams(this.routerVal.way).then((res) => {
|
||||
// 获取结算参数 进行首次判断
|
||||
this.originOrderData = this.orderMessage ? JSON.parse(JSON.stringify(this.orderMessage)) : ""
|
||||
|
||||
if (
|
||||
!res.data.result.checkedSkuList ||
|
||||
res.data.result.checkedSkuList.length === 0
|
||||
) {
|
||||
uni.switchTab({
|
||||
url: "/pages/tabbar/cart/cartList",
|
||||
});
|
||||
|
||||
if(!this.originOrderData.checkedSkuList.length){
|
||||
uni.switchTab({
|
||||
url: "/pages/tabbar/cart/cartList",
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
if (res.data.result.skuList.length <= 0) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/order/myOrder?status=0",
|
||||
});
|
||||
|
||||
if(!this.originOrderData.skuList.length){
|
||||
uni.navigateTo({
|
||||
url: "/pages/order/myOrder?status=0",
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let repeatData;
|
||||
|
||||
180
utils/request.js
180
utils/request.js
@@ -1,16 +1,16 @@
|
||||
import Request from "@/lib/request/index.js";
|
||||
import {
|
||||
refreshTokenFn
|
||||
} 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 {
|
||||
md5
|
||||
} from "@/utils/md5.js";
|
||||
import Foundation from "@/utils/Foundation.js";
|
||||
import api from "@/config/api.js";
|
||||
import storage from "@/utils/storage.js";
|
||||
|
||||
import jwt from '@/js_sdk/t-jwt/jwt.js';
|
||||
import uuid from "@/utils/uuid.modified.js";
|
||||
import jwt from '@/js_sdk/t-jwt/jwt.js'
|
||||
import store from "../store";
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ http.interceptors.request.use(
|
||||
*/
|
||||
const decodeJwt = jwt(accessToken);
|
||||
const timing = new Date().getTime() / 1000
|
||||
if(decodeJwt.exp <= timing){
|
||||
if (decodeJwt.exp <= timing) {
|
||||
accessToken = ""
|
||||
storage.setAccessToken('')
|
||||
}
|
||||
@@ -132,95 +132,95 @@ let requests = [];
|
||||
// 必须使用异步函数,注意
|
||||
http.interceptors.response.use(
|
||||
async (response) => {
|
||||
isNavigateTo = false
|
||||
/* 请求之后拦截器。可以使用async await 做异步操作 */
|
||||
// token存在并且token过期
|
||||
// if (isRefreshing && response.statusCode === 403) {
|
||||
// cleanStorage();
|
||||
// isRefreshing = false;
|
||||
// }
|
||||
uni.showLoading() ? uni.hideLoading() : ''
|
||||
let token = storage.getAccessToken();
|
||||
if (
|
||||
(token && response.statusCode === 403) ||
|
||||
response.data.status === 403
|
||||
) {
|
||||
if (!isRefreshing) {
|
||||
console.log('旧token', token)
|
||||
isRefreshing = true;
|
||||
storage.setAccessToken('')
|
||||
let oldRefreshToken = storage.getRefreshToken();
|
||||
//调用刷新token的接口
|
||||
return refreshTokenFn(oldRefreshToken)
|
||||
.then((res) => {
|
||||
let {
|
||||
accessToken,
|
||||
refreshToken
|
||||
} = res.data.result;
|
||||
storage.setAccessToken(accessToken);
|
||||
storage.setRefreshToken(refreshToken);
|
||||
isNavigateTo = false
|
||||
/* 请求之后拦截器。可以使用async await 做异步操作 */
|
||||
// token存在并且token过期
|
||||
// if (isRefreshing && response.statusCode === 403) {
|
||||
// cleanStorage();
|
||||
// isRefreshing = false;
|
||||
// }
|
||||
uni.showLoading() ? uni.hideLoading() : ''
|
||||
let token = storage.getAccessToken();
|
||||
if (
|
||||
(token && response.statusCode === 403) ||
|
||||
response.data.status === 403
|
||||
) {
|
||||
if (!isRefreshing) {
|
||||
console.log('旧token', token)
|
||||
isRefreshing = true;
|
||||
storage.setAccessToken('')
|
||||
let oldRefreshToken = storage.getRefreshToken();
|
||||
//调用刷新token的接口
|
||||
return refreshTokenFn(oldRefreshToken)
|
||||
.then((res) => {
|
||||
let {
|
||||
accessToken,
|
||||
refreshToken
|
||||
} = res.data.result;
|
||||
storage.setAccessToken(accessToken);
|
||||
storage.setRefreshToken(refreshToken);
|
||||
|
||||
response.header.accessToken = `${accessToken}`;
|
||||
// token 刷新后将数组的方法重新执行
|
||||
console.log('接口队列', requests, '新token', accessToken)
|
||||
requests.forEach((cb) => cb(accessToken));
|
||||
requests = []; // 重新请求完清空
|
||||
return http.request(response.config);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('刷新token报错' + oldRefreshToken, err)
|
||||
cleanStorage();
|
||||
return Promise.reject(err);
|
||||
})
|
||||
.finally(() => {
|
||||
isRefreshing = false;
|
||||
});
|
||||
} else {
|
||||
// 返回未执行 resolve 的 Promise
|
||||
return new Promise((resolve) => {
|
||||
// 用函数形式将 resolve 存入,等待刷新后再执行
|
||||
requests.push((token) => {
|
||||
response.header.accessToken = `${token}`;
|
||||
resolve(http.request(response.config));
|
||||
});
|
||||
response.header.accessToken = `${accessToken}`;
|
||||
// token 刷新后将数组的方法重新执行
|
||||
console.log('接口队列', requests, '新token', accessToken)
|
||||
requests.forEach((cb) => cb(accessToken));
|
||||
requests = []; // 重新请求完清空
|
||||
return http.request(response.config);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('刷新token报错' + oldRefreshToken, err)
|
||||
cleanStorage();
|
||||
return Promise.reject(err);
|
||||
})
|
||||
.finally(() => {
|
||||
isRefreshing = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 如果当前返回没登录
|
||||
} else if (
|
||||
(!token && !storage.getRefreshToken() && response.statusCode === 403) ||
|
||||
response.data.code === 403
|
||||
) {
|
||||
console.log('没有token 以及刷新token 内容', token, storage.getRefreshToken())
|
||||
cleanStorage();
|
||||
|
||||
// 如果当前状态码为正常但是success为不正常时
|
||||
} else if (
|
||||
(response.statusCode == 200 && !response.data.success) ||
|
||||
response.statusCode == 400
|
||||
) {
|
||||
if (response.data.message) {
|
||||
uni.showToast({
|
||||
title: response.data.message,
|
||||
icon: "none",
|
||||
duration: 1500,
|
||||
success: function () {
|
||||
store.state.isShowToast = true;
|
||||
},
|
||||
fail: function () {
|
||||
store.state.isShowToast = false;
|
||||
},
|
||||
complete: function () {
|
||||
store.state.isShowToast = false;
|
||||
}
|
||||
} else {
|
||||
// 返回未执行 resolve 的 Promise
|
||||
return new Promise((resolve) => {
|
||||
// 用函数形式将 resolve 存入,等待刷新后再执行
|
||||
requests.push((token) => {
|
||||
response.header.accessToken = `${token}`;
|
||||
resolve(http.request(response.config));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 如果当前返回没登录
|
||||
} else if (
|
||||
(!token && !storage.getRefreshToken() && response.statusCode === 403) ||
|
||||
response.data.code === 403
|
||||
) {
|
||||
console.log('没有token 以及刷新token 内容', token, storage.getRefreshToken())
|
||||
cleanStorage();
|
||||
|
||||
// 如果当前状态码为正常但是success为不正常时
|
||||
} else if (
|
||||
(response.statusCode == 200 && !response.data.success) ||
|
||||
response.statusCode == 400
|
||||
) {
|
||||
if (response.data.message) {
|
||||
uni.showToast({
|
||||
title: response.data.message,
|
||||
icon: "none",
|
||||
duration: 1500,
|
||||
success: function () {
|
||||
store.state.isShowToast = true;
|
||||
},
|
||||
fail: function () {
|
||||
store.state.isShowToast = false;
|
||||
},
|
||||
complete: function () {
|
||||
store.state.isShowToast = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
return error;
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
return error;
|
||||
}
|
||||
);
|
||||
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user