This commit is contained in:
eric
2025-09-09 19:21:08 +08:00
parent 8dd0faeb34
commit 1cb0295d2d
2 changed files with 92 additions and 15 deletions

View File

@@ -116,7 +116,9 @@ const config = {
// port: 10087, // 选择一个适当的端口号
proxy: {
"/api/": {
target: JSON.parse('"http://localhost:8700"'), //本地调试端口
// target: JSON.parse('"http://localhost:8200"'), //本地调试端口
target: JSON.parse('"http://192.168.31.222:8200"'), //本地调试端口
pathRewrite: {
"^/api/": "/",
},

View File

@@ -105,6 +105,8 @@ const Index = () => {
// },
});
useEffect(() => {
// window.localStorage.removeItem('vip')
// window.alert(window.localStorage.getItem("username"));
if (contentRef.current) {
const h1Elements = contentRef.current.querySelectorAll("h1");
const h2Elements = contentRef.current.querySelectorAll("h2");
@@ -336,15 +338,36 @@ const Index = () => {
setopen(value);
};
const createUser = (username, password) => {
Taro.request({
method: "POST",
url: `${process.env.TARO_API_API}/create_user`,
data: {
username: username,
password: password || "123456", // 如果没有传入密码,则使用默认密码
},
header: {
"content-type": "application/json",
},
success: function (res) {
console.log("用户创建结果:", res.data);
window.localStorage.setItem("username", res?.data?.username);
window.localStorage.setItem("password", res?.data?.password);
},
fail: function (err) {
console.error("创建用户失败:", err);
Taro.showToast({
title: "请求失败",
icon: "error",
});
},
});
};
const payh5 = (type, total_fee = 1000) => {
// console.log("111");
Taro.request({
method: "POST",
url: `${process.env.TARO_API_API}/payh5`,
// url: "${process.env.TARO_API_API}/payh5",
// url: "https://pay.hackrobot.cn${process.env.TARO_API_API}/payh5", //仅为示例,并非真实的接口地址
data: {
callback_url: window.location.href,
openid: window.localStorage.getItem("openid"),
@@ -355,8 +378,10 @@ const Index = () => {
"content-type": "application/json", // 默认值
},
success: function (res) {
// payjs数据返回
console.log(res.data);
// window.alert(res.data.jsapi);
// window.alert(res.data.username);
// window.alert(JSON.stringify(res?.data, null, 2));
WeixinJSBridge.invoke(
"getBrandWCPayRequest",
{
@@ -369,11 +394,21 @@ const Index = () => {
// paySign: "2A823C8D47CCF871C6C65A56DC228CF8",
...(res?.data?.jsapi ?? {}),
},
function (res) {
function (reslut) {
// 支付成功
if (res.err_msg == "get_brand_wcpay_request:ok") {
if (reslut.err_msg == "get_brand_wcpay_request:ok") {
// 新增memos用户
// 动态生成用户名,若 username 没传入则使用默认值 "user" + 当前时间戳
const finalUsername = `user${Date.now()}`;
createUser(finalUsername, "123456");
window.localStorage.setItem(type, 1); //订单类型 book/meetup/video/vip
WeixinJSBridge.call("closeWindow");
window.localStorage.setItem("username", finalUsername);
window.localStorage.setItem("password", "123456");
// WeixinJSBridge.call("closeWindow");
} else {
window.alert("支付取消/失败");
// createUser();
}
}
);
@@ -387,6 +422,42 @@ const Index = () => {
});
};
const handleCopyUsername = () => {
Taro.setClipboardData({
data: window.localStorage.getItem("username"), // 复制账号
success: () => {
Taro.showToast({
title: "账号已复制",
icon: "success",
});
},
fail: () => {
Taro.showToast({
title: "复制失败",
icon: "none",
});
},
});
};
const handleCopyPassword = () => {
Taro.setClipboardData({
data: '123456', // 复制密码
success: () => {
Taro.showToast({
title: "密码已复制",
icon: "success",
});
},
fail: () => {
Taro.showToast({
title: "复制失败",
icon: "none",
});
},
});
};
return (
<>
<View className="index">
@@ -462,7 +533,7 @@ const Index = () => {
} else {
if (!!isWeChat) {
//58元
payh5("vip", 5800);
payh5("vip", 100);
} else {
window.location.href = `https://mp.weixin.qq.com/s/16xcMIgxEEGBPY7fanNq0g`;
}
@@ -477,20 +548,24 @@ const Index = () => {
</AtButton>
) : (
<View className="vipcode">
<Image className="vipcodeImg" src={hackrobot}></Image>
<View
onClick={() => {
window.location.href = `https://memos.hackrobot.org`;
}}
>
👉星球地址: memos.hackrobot.org
👉星球地址:{" "}
<span style={{ color: "blue" }}>memos.hackrobot.org</span>
</View>
<View>账号:{window.localStorage.getItem("username")}</View>
<Button onClick={handleCopyUsername}>复制账号</Button>
<View>密码:{"123456"}</View>{" "}
<Button onClick={handleCopyPassword}>复制密码</Button>
<View>
添加
<span style={{ color: "green" }}>微信好友: hackrobot</span>
</View>
<View>获取 账号</View>
{/* <View>获取 账号</View> */}
<Image className="vipcodeImg" src={hackrobot}></Image>
</View>
)}
</View>