fix: create order
This commit is contained in:
@@ -2,7 +2,7 @@ import { request } from "@/utils/request.js";
|
||||
|
||||
export const createOrder = async (data) => {
|
||||
return request({
|
||||
url: "/api/pay/wechat/order/create",
|
||||
url: "/api/pay/order/v2/create",
|
||||
method: "POST",
|
||||
data,
|
||||
});
|
||||
|
||||
@@ -111,6 +111,7 @@ import { storeToRefs } from "pinia";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import { createOrder, getVipPlan } from "@/api/pay.js";
|
||||
import NavBar from "@/components/NavBar/NavBar.vue";
|
||||
import { getPlatformProvider } from "@/utils/system";
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
@@ -179,8 +180,11 @@ const handlePurchase = async () => {
|
||||
});
|
||||
|
||||
if (orderRes?.payParams) {
|
||||
const platform = getPlatformProvider();
|
||||
const provider = platform === "mp-alipay" ? "alipay" : "wxpay";
|
||||
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
provider: provider,
|
||||
...orderRes.payParams,
|
||||
success(res) {
|
||||
uni.showToast({ title: "支付成功", icon: "success" });
|
||||
@@ -189,7 +193,9 @@ const handlePurchase = async () => {
|
||||
},
|
||||
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" });
|
||||
} else {
|
||||
uni.showToast({ title: "支付失败", icon: "none" });
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
const BASE_URL = "http://192.168.1.3:3999";
|
||||
// const BASE_URL = "http://192.168.31.253:3999";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import { getPlatform } from "./system.js";
|
||||
const platform = getPlatform();
|
||||
|
||||
// 环境区分
|
||||
// const BASE_URL =
|
||||
@@ -33,6 +35,7 @@ function hideLoading() {
|
||||
function getHeaders() {
|
||||
const headers = {
|
||||
"x-app-id": "69665538a49b8ae3be50fe5d",
|
||||
"x-platform": platform,
|
||||
};
|
||||
const userStore = useUserStore();
|
||||
if (userStore.token) {
|
||||
|
||||
@@ -55,6 +55,10 @@ export function getPlatformProvider() {
|
||||
// return typeof tt !== 'undefined' ? 'toutiao' : 'weixin';
|
||||
}
|
||||
|
||||
export function getPlatform() {
|
||||
return getPlatformProvider().replace("mp-", "");
|
||||
}
|
||||
|
||||
export function getDeviceInfo() {
|
||||
const info = uni.getSystemInfoSync();
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user