mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-16 23:45:53 +08:00
fix: 🐛 1:修改微信订阅,更改为每次支付成功之后请求订阅信息。2:修改微信支付在真机中支付成功跳转问题
This commit is contained in:
26
App.vue
26
App.vue
@@ -2,15 +2,15 @@
|
|||||||
/**
|
/**
|
||||||
* vuex管理登录状态,具体可以参考官方登录模板示例
|
* 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 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
|
// #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;
|
||||||
|
|||||||
@@ -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,52 +65,40 @@ 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;
|
||||||
var templateid = message.map((item) => item.code);
|
var templateid = message.map((item) => item.code);
|
||||||
uni.requestSubscribeMessage({
|
uni.requestSubscribeMessage({
|
||||||
tmplIds: templateid,
|
tmplIds: templateid,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
for (let key in res) {
|
|
||||||
// 表示用户拒绝订阅该信息
|
},
|
||||||
if (res[key] == "reject") {
|
fail: (res) => {
|
||||||
this.checked = false;
|
console.log('fail', res)
|
||||||
} else {
|
uni.showToast({
|
||||||
uni.setStorageSync("acceptSubscribeMessage", res);
|
icon: "none",
|
||||||
}
|
title: "订阅消息失败",
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
fail: (res) => {
|
complete: (res) => {
|
||||||
uni.removeStorageSync("acceptSubscribeMessage");
|
console.log('complete', res)
|
||||||
this.checked = false;
|
|
||||||
},
|
/**
|
||||||
complete: () => {
|
* 已经支付成功
|
||||||
/**
|
*/
|
||||||
* 已经支付成功
|
uni.redirectTo({
|
||||||
*/
|
url:
|
||||||
uni.redirectTo({
|
"/pages/cart/payment/success?paymentMethod=WECHAT" +
|
||||||
url:
|
"&payPrice=" +
|
||||||
"/pages/cart/payment/success?paymentMethod=WECHAT" +
|
price,
|
||||||
"&payPrice=" +
|
});
|
||||||
price,
|
},
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
/**
|
|
||||||
* 已经支付成功
|
|
||||||
*/
|
|
||||||
uni.redirectTo({
|
|
||||||
url:
|
|
||||||
"/pages/cart/payment/success?paymentMethod=WECHAT" +
|
|
||||||
"&payPrice=" +
|
|
||||||
price,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LiLiWXPay;
|
export default LiLiWXPay;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
¥{{ Number(payPrice) | unitPrice }}
|
¥{{ Number(payPrice) | unitPrice }}
|
||||||
</div>
|
</div>
|
||||||
<div class="pay-btns">
|
<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 @click="navigateTo('/pages/tabbar/home/index', 'switch')">回到首页</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<div>
|
<div>
|
||||||
支付方式:
|
支付方式:
|
||||||
</div>
|
</div>
|
||||||
<div>{{paymentMethod | paymentTypeFilter}}</div>
|
<div>{{ paymentMethod | paymentTypeFilter }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -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%;
|
||||||
@@ -112,7 +108,7 @@ export default {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
|
||||||
> div {
|
>div {
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
border: 1px solid #fff;
|
border: 1px solid #fff;
|
||||||
border-radius: 100px;
|
border-radius: 100px;
|
||||||
@@ -146,7 +142,7 @@ export default {
|
|||||||
border-radius: 20rpx;
|
border-radius: 20rpx;
|
||||||
background: rgba($color: $main-color, $alpha: 0.2);
|
background: rgba($color: $main-color, $alpha: 0.2);
|
||||||
|
|
||||||
> h2 {
|
>h2 {
|
||||||
margin-top: 20rpx;
|
margin-top: 20rpx;
|
||||||
font-size: 40rpx;
|
font-size: 40rpx;
|
||||||
color: $main-color;
|
color: $main-color;
|
||||||
|
|||||||
@@ -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,18 +788,29 @@ 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
|
||||||
) {
|
) {
|
||||||
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) {
|
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;
|
let repeatData;
|
||||||
|
|||||||
180
utils/request.js
180
utils/request.js
@@ -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";
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ http.interceptors.request.use(
|
|||||||
*/
|
*/
|
||||||
const decodeJwt = jwt(accessToken);
|
const decodeJwt = jwt(accessToken);
|
||||||
const timing = new Date().getTime() / 1000
|
const timing = new Date().getTime() / 1000
|
||||||
if(decodeJwt.exp <= timing){
|
if (decodeJwt.exp <= timing) {
|
||||||
accessToken = ""
|
accessToken = ""
|
||||||
storage.setAccessToken('')
|
storage.setAccessToken('')
|
||||||
}
|
}
|
||||||
@@ -132,95 +132,95 @@ let requests = [];
|
|||||||
// 必须使用异步函数,注意
|
// 必须使用异步函数,注意
|
||||||
http.interceptors.response.use(
|
http.interceptors.response.use(
|
||||||
async (response) => {
|
async (response) => {
|
||||||
isNavigateTo = false
|
isNavigateTo = false
|
||||||
/* 请求之后拦截器。可以使用async await 做异步操作 */
|
/* 请求之后拦截器。可以使用async await 做异步操作 */
|
||||||
// token存在并且token过期
|
// token存在并且token过期
|
||||||
// if (isRefreshing && response.statusCode === 403) {
|
// if (isRefreshing && response.statusCode === 403) {
|
||||||
// cleanStorage();
|
// cleanStorage();
|
||||||
// isRefreshing = false;
|
// isRefreshing = false;
|
||||||
// }
|
// }
|
||||||
uni.showLoading() ? uni.hideLoading() : ''
|
uni.showLoading() ? uni.hideLoading() : ''
|
||||||
let token = storage.getAccessToken();
|
let token = storage.getAccessToken();
|
||||||
if (
|
if (
|
||||||
(token && response.statusCode === 403) ||
|
(token && response.statusCode === 403) ||
|
||||||
response.data.status === 403
|
response.data.status === 403
|
||||||
) {
|
) {
|
||||||
if (!isRefreshing) {
|
if (!isRefreshing) {
|
||||||
console.log('旧token', token)
|
console.log('旧token', token)
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
storage.setAccessToken('')
|
storage.setAccessToken('')
|
||||||
let oldRefreshToken = storage.getRefreshToken();
|
let oldRefreshToken = storage.getRefreshToken();
|
||||||
//调用刷新token的接口
|
//调用刷新token的接口
|
||||||
return refreshTokenFn(oldRefreshToken)
|
return refreshTokenFn(oldRefreshToken)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
let {
|
let {
|
||||||
accessToken,
|
accessToken,
|
||||||
refreshToken
|
refreshToken
|
||||||
} = res.data.result;
|
} = res.data.result;
|
||||||
storage.setAccessToken(accessToken);
|
storage.setAccessToken(accessToken);
|
||||||
storage.setRefreshToken(refreshToken);
|
storage.setRefreshToken(refreshToken);
|
||||||
|
|
||||||
response.header.accessToken = `${accessToken}`;
|
response.header.accessToken = `${accessToken}`;
|
||||||
// token 刷新后将数组的方法重新执行
|
// token 刷新后将数组的方法重新执行
|
||||||
console.log('接口队列', requests, '新token', accessToken)
|
console.log('接口队列', requests, '新token', accessToken)
|
||||||
requests.forEach((cb) => cb(accessToken));
|
requests.forEach((cb) => cb(accessToken));
|
||||||
requests = []; // 重新请求完清空
|
requests = []; // 重新请求完清空
|
||||||
return http.request(response.config);
|
return http.request(response.config);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('刷新token报错' + oldRefreshToken, err)
|
console.log('刷新token报错' + oldRefreshToken, err)
|
||||||
cleanStorage();
|
cleanStorage();
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
isRefreshing = false;
|
isRefreshing = false;
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 返回未执行 resolve 的 Promise
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
// 用函数形式将 resolve 存入,等待刷新后再执行
|
|
||||||
requests.push((token) => {
|
|
||||||
response.header.accessToken = `${token}`;
|
|
||||||
resolve(http.request(response.config));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
// 返回未执行 resolve 的 Promise
|
||||||
// 如果当前返回没登录
|
return new Promise((resolve) => {
|
||||||
} else if (
|
// 用函数形式将 resolve 存入,等待刷新后再执行
|
||||||
(!token && !storage.getRefreshToken() && response.statusCode === 403) ||
|
requests.push((token) => {
|
||||||
response.data.code === 403
|
response.header.accessToken = `${token}`;
|
||||||
) {
|
resolve(http.request(response.config));
|
||||||
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 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 {
|
export {
|
||||||
|
|||||||
Reference in New Issue
Block a user