完成支付功能
This commit is contained in:
10
src/apis.js
10
src/apis.js
@@ -26,6 +26,14 @@ function request(method, url, data = {}) {
|
|||||||
resolve({});
|
resolve({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (message === "ERROR_ORDER_UNPAY") {
|
||||||
|
uni.showToast({
|
||||||
|
title: "当前有未支付订单",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
resolve({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: message,
|
title: message,
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -260,7 +268,6 @@ export const createOrderAPI = (vipId) => {
|
|||||||
return request("POST", "/user/order/create", {
|
return request("POST", "/user/order/create", {
|
||||||
vipId,
|
vipId,
|
||||||
quanity: 1,
|
quanity: 1,
|
||||||
mockTest: true,
|
|
||||||
tradeType: "mini",
|
tradeType: "mini",
|
||||||
payType: "wxpay",
|
payType: "wxpay",
|
||||||
});
|
});
|
||||||
@@ -269,7 +276,6 @@ export const createOrderAPI = (vipId) => {
|
|||||||
export const payOrderAPI = (id) => {
|
export const payOrderAPI = (id) => {
|
||||||
return request("POST", "/user/order/pay", {
|
return request("POST", "/user/order/pay", {
|
||||||
id,
|
id,
|
||||||
mockTest: true,
|
|
||||||
tradeType: "mini",
|
tradeType: "mini",
|
||||||
payType: "wxpay",
|
payType: "wxpay",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const MESSAGETYPES = {
|
|||||||
HalfTimeOver: 388606440,
|
HalfTimeOver: 388606440,
|
||||||
BackToGame: 1899960424,
|
BackToGame: 1899960424,
|
||||||
FinalShootResult: 3813452544,
|
FinalShootResult: 3813452544,
|
||||||
|
PaySuccess: 3793388244,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"];
|
export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"];
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import Avatar from "@/components/Avatar.vue";
|
|||||||
import SButton from "@/components/SButton.vue";
|
import SButton from "@/components/SButton.vue";
|
||||||
import SModal from "@/components/SModal.vue";
|
import SModal from "@/components/SModal.vue";
|
||||||
import Signin from "@/components/Signin.vue";
|
import Signin from "@/components/Signin.vue";
|
||||||
import { createOrderAPI } from "@/apis";
|
import { createOrderAPI, getHomeData } from "@/apis";
|
||||||
import { formatTimestamp } from "@/util";
|
import { formatTimestamp } from "@/util";
|
||||||
import useStore from "@/store";
|
import useStore from "@/store";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const { user, config } = storeToRefs(store);
|
const { user, config } = storeToRefs(store);
|
||||||
|
const { updateUser } = store;
|
||||||
|
|
||||||
const selectedVIP = ref(0);
|
const selectedVIP = ref(0);
|
||||||
const showModal = ref(false);
|
const showModal = ref(false);
|
||||||
@@ -23,10 +24,28 @@ const onPay = async () => {
|
|||||||
const result = await createOrderAPI(
|
const result = await createOrderAPI(
|
||||||
config.value.vipMenus[selectedVIP.value].id
|
config.value.vipMenus[selectedVIP.value].id
|
||||||
);
|
);
|
||||||
|
if (!result.pay) return;
|
||||||
|
const params = result.pay.order.jsApi.params;
|
||||||
|
if (params) {
|
||||||
|
wx.requestPayment({
|
||||||
|
timeStamp: params.timeStamp, // 时间戳
|
||||||
|
nonceStr: params.nonceStr, // 随机字符串
|
||||||
|
package: params.package, // 统一下单接口返回的 prepay_id 参数值,格式:prepay_id=***
|
||||||
|
paySign: params.paySign, // 签名
|
||||||
|
signType: "RSA", // 签名类型,默认为RSA
|
||||||
|
async success(res) {
|
||||||
|
const result = await getHomeData();
|
||||||
|
if (result.user) updateUser(result.user);
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "创建成功",
|
title: "支付成功",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
console.log("pay error", res);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
import Container from "@/components/Container.vue";
|
import Container from "@/components/Container.vue";
|
||||||
import SButton from "@/components/SButton.vue";
|
import SButton from "@/components/SButton.vue";
|
||||||
import { payOrderAPI, cancelOrderListAPI } from "@/apis";
|
import { payOrderAPI, cancelOrderListAPI, getHomeData } from "@/apis";
|
||||||
import { orderStatusNames } from "@/constants";
|
import { orderStatusNames } from "@/constants";
|
||||||
|
import useStore from "@/store";
|
||||||
|
const store = useStore();
|
||||||
|
const { updateUser } = store;
|
||||||
|
|
||||||
const data = ref({});
|
const data = ref({});
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const order = uni.getStorageSync("order");
|
const order = uni.getStorageSync("order");
|
||||||
@@ -14,6 +18,29 @@ onMounted(() => {
|
|||||||
|
|
||||||
const goPay = async () => {
|
const goPay = async () => {
|
||||||
const result = await payOrderAPI(data.value.orderId);
|
const result = await payOrderAPI(data.value.orderId);
|
||||||
|
const params = result.jsApi.params;
|
||||||
|
if (params) {
|
||||||
|
loading.value = true;
|
||||||
|
wx.requestPayment({
|
||||||
|
timeStamp: params.timeStamp, // 时间戳
|
||||||
|
nonceStr: params.nonceStr, // 随机字符串
|
||||||
|
package: params.package, // 统一下单接口返回的 prepay_id 参数值,格式:prepay_id=***
|
||||||
|
paySign: params.paySign, // 签名
|
||||||
|
signType: "RSA", // 签名类型,默认为RSA
|
||||||
|
async success(res) {
|
||||||
|
const result = await getHomeData();
|
||||||
|
if (result.user) updateUser(result.user);
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付成功",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
loading.value = false;
|
||||||
|
console.log("pay error", res);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelOrder = async () => {
|
const cancelOrder = async () => {
|
||||||
@@ -36,6 +63,7 @@ const cancelOrder = async () => {
|
|||||||
</view>
|
</view>
|
||||||
<view v-if="data.orderStatus === 1">
|
<view v-if="data.orderStatus === 1">
|
||||||
<SButton :onClick="goPay">去支付</SButton>
|
<SButton :onClick="goPay">去支付</SButton>
|
||||||
|
<view :style="{ height: '10px' }" />
|
||||||
<SButton :onClick="cancelOrder">取消订单</SButton>
|
<SButton :onClick="cancelOrder">取消订单</SButton>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ const { user, config } = storeToRefs(store);
|
|||||||
|
|
||||||
const getStatusColor = (status) => {
|
const getStatusColor = (status) => {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "4":
|
case 1:
|
||||||
return "#35CD67";
|
|
||||||
case "5":
|
|
||||||
return "#EF4848";
|
return "#EF4848";
|
||||||
|
case 4:
|
||||||
|
return "#35CD67";
|
||||||
default:
|
default:
|
||||||
return "#999999";
|
return "#999999";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import websocket from "@/websocket";
|
import websocket from "@/websocket";
|
||||||
|
|
||||||
export const formatTimestamp = (timestamp) => {
|
export const formatTimestamp = (timestamp) => {
|
||||||
const date = new Date(timestamp);
|
const date = new Date(timestamp * 1000);
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
const month = date.getMonth() + 1;
|
const month = date.getMonth() + 1;
|
||||||
const day = date.getDate();
|
const day = date.getDate();
|
||||||
|
|
||||||
return `${year}.${month}.${day}`;
|
return `${year}年${month}月${day}号`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const checkConnection = () => {
|
export const checkConnection = () => {
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ function createWebSocket(token, onMessage) {
|
|||||||
// 接收消息
|
// 接收消息
|
||||||
uni.onSocketMessage((res) => {
|
uni.onSocketMessage((res) => {
|
||||||
const data = JSON.parse(res.data);
|
const data = JSON.parse(res.data);
|
||||||
if(data.event === 'pong' || !data.data.updates) return;
|
if (data.event === "pong" || !data.data.updates) return;
|
||||||
if (onMessage) onMessage(data.data.updates);
|
if (onMessage) onMessage(data.data.updates);
|
||||||
const msg = data.data.updates[0];
|
const msg = data.data.updates[0];
|
||||||
if (msg && msg.constructor === MESSAGETYPES.BackToGame) {
|
if (!msg) return;
|
||||||
|
if (msg.constructor === MESSAGETYPES.BackToGame) {
|
||||||
const { battleInfo } = msg;
|
const { battleInfo } = msg;
|
||||||
uni.setStorageSync(`battle-${battleInfo.id}`, battleInfo);
|
uni.setStorageSync(`battle-${battleInfo.id}`, battleInfo);
|
||||||
// 约战
|
// 约战
|
||||||
@@ -57,6 +58,9 @@ function createWebSocket(token, onMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (msg.constructor === MESSAGETYPES.PaySuccess) {
|
||||||
|
console.log(1111111, msg);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 错误处理
|
// 错误处理
|
||||||
|
|||||||
Reference in New Issue
Block a user