fix: create order

This commit is contained in:
zzc
2026-02-11 23:59:51 +08:00
parent 6ca148f65e
commit f5841d0934
4 changed files with 16 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import { request } from "@/utils/request.js";
export const createOrder = async (data) => { export const createOrder = async (data) => {
return request({ return request({
url: "/api/pay/wechat/order/create", url: "/api/pay/order/v2/create",
method: "POST", method: "POST",
data, data,
}); });

View File

@@ -111,6 +111,7 @@ import { storeToRefs } from "pinia";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import { createOrder, getVipPlan } from "@/api/pay.js"; import { createOrder, getVipPlan } from "@/api/pay.js";
import NavBar from "@/components/NavBar/NavBar.vue"; import NavBar from "@/components/NavBar/NavBar.vue";
import { getPlatformProvider } from "@/utils/system";
const userStore = useUserStore(); const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore); const { userInfo } = storeToRefs(userStore);
@@ -179,8 +180,11 @@ const handlePurchase = async () => {
}); });
if (orderRes?.payParams) { if (orderRes?.payParams) {
const platform = getPlatformProvider();
const provider = platform === "mp-alipay" ? "alipay" : "wxpay";
uni.requestPayment({ uni.requestPayment({
provider: "wxpay", provider: provider,
...orderRes.payParams, ...orderRes.payParams,
success(res) { success(res) {
uni.showToast({ title: "支付成功", icon: "success" }); uni.showToast({ title: "支付成功", icon: "success" });
@@ -189,7 +193,9 @@ const handlePurchase = async () => {
}, },
fail(err) { fail(err) {
console.log("payment fail", err); console.log("payment fail", err);
if (err.errMsg.indexOf("cancel") > -1) { // 支付宝取消支付的错误码是 6001
// 微信取消支付的错误信息包含 cancel
if (err.errMsg.indexOf("cancel") > -1 || err.resultCode === "6001") {
uni.showToast({ title: "支付已取消", icon: "none" }); uni.showToast({ title: "支付已取消", icon: "none" });
} else { } else {
uni.showToast({ title: "支付失败", icon: "none" }); uni.showToast({ title: "支付失败", icon: "none" });

View File

@@ -3,6 +3,8 @@
const BASE_URL = "http://192.168.1.3:3999"; const BASE_URL = "http://192.168.1.3:3999";
// const BASE_URL = "http://192.168.31.253:3999"; // const BASE_URL = "http://192.168.31.253:3999";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import { getPlatform } from "./system.js";
const platform = getPlatform();
// 环境区分 // 环境区分
// const BASE_URL = // const BASE_URL =
@@ -33,6 +35,7 @@ function hideLoading() {
function getHeaders() { function getHeaders() {
const headers = { const headers = {
"x-app-id": "69665538a49b8ae3be50fe5d", "x-app-id": "69665538a49b8ae3be50fe5d",
"x-platform": platform,
}; };
const userStore = useUserStore(); const userStore = useUserStore();
if (userStore.token) { if (userStore.token) {

View File

@@ -55,6 +55,10 @@ export function getPlatformProvider() {
// return typeof tt !== 'undefined' ? 'toutiao' : 'weixin'; // return typeof tt !== 'undefined' ? 'toutiao' : 'weixin';
} }
export function getPlatform() {
return getPlatformProvider().replace("mp-", "");
}
export function getDeviceInfo() { export function getDeviceInfo() {
const info = uni.getSystemInfoSync(); const info = uni.getSystemInfoSync();
return { return {