2024-07-06 11:05:19 +08:00
|
|
|
|
import { get } from "@/utils/storeInfo";
|
2024-07-22 16:07:41 +08:00
|
|
|
|
import requireAPI from "@/utils/requireAPI";
|
2024-07-06 11:05:19 +08:00
|
|
|
|
import { Toast } from "antd-mobile";
|
2024-07-16 20:20:12 +08:00
|
|
|
|
import { JSEncrypt } from "jsencrypt";
|
2024-07-24 15:32:23 +08:00
|
|
|
|
import baseRequest from "@/utils/baseRequest";
|
2024-07-06 11:05:19 +08:00
|
|
|
|
//关注和取关功能
|
2024-07-12 22:52:48 +08:00
|
|
|
|
export const handleLogout = async () => {
|
|
|
|
|
const account = get("account");
|
|
|
|
|
try {
|
2024-07-22 16:07:41 +08:00
|
|
|
|
const data = await requireAPI("POST", `/api/login/logout`, {
|
2024-07-12 22:52:48 +08:00
|
|
|
|
body: {
|
2024-07-16 20:20:12 +08:00
|
|
|
|
mid: account.mid,
|
2024-07-12 22:52:48 +08:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
//关注和取关功能
|
2024-07-06 11:05:19 +08:00
|
|
|
|
export const handleFollow = async (isFollowed, followedID, callback) => {
|
|
|
|
|
const account = get("account");
|
|
|
|
|
let body = {
|
|
|
|
|
[!isFollowed ? "account_relations" : "sentences"]: [
|
|
|
|
|
{ sub_mid: account.mid, obj_mid: followedID, predicate: 0 },
|
|
|
|
|
{ sub_mid: followedID, obj_mid: account.mid, predicate: 1 },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
try {
|
2024-07-22 16:07:41 +08:00
|
|
|
|
const data = await requireAPI("POST", `/api/account_relation/${
|
2024-07-06 11:05:19 +08:00
|
|
|
|
!isFollowed ? "create" : "delete"
|
|
|
|
|
}`, {
|
|
|
|
|
body,
|
|
|
|
|
});
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2024-07-15 16:54:04 +08:00
|
|
|
|
callback && callback(!isFollowed);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//点赞和取消点赞功能
|
2024-07-16 20:20:12 +08:00
|
|
|
|
export const thumbsUp = async (id, times, callback, isZone) => {
|
2024-07-08 20:07:36 +08:00
|
|
|
|
try {
|
2024-07-16 20:20:12 +08:00
|
|
|
|
const body = isZone
|
|
|
|
|
? {
|
|
|
|
|
zone_moment_id: id,
|
|
|
|
|
times: times == 1 ? -1 : 1,
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
moment_id: id,
|
|
|
|
|
times: times == 1 ? -1 : 1,
|
|
|
|
|
};
|
2024-07-08 20:07:36 +08:00
|
|
|
|
console.log("body", body);
|
|
|
|
|
|
2024-07-22 16:07:41 +08:00
|
|
|
|
const data = await requireAPI("POST", `/api/${
|
2024-07-16 20:20:12 +08:00
|
|
|
|
isZone ? "zone_moment" : "moment"
|
|
|
|
|
}/thumbs_up`, {
|
2024-07-08 20:07:36 +08:00
|
|
|
|
body,
|
|
|
|
|
});
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
callback(times == 1 ? -1 : 1);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
//点赞和取消点赞功能
|
|
|
|
|
export const zoneThumbsUp = async (id, times = 1, callback) => {
|
2024-07-06 11:05:19 +08:00
|
|
|
|
console.log("times", times);
|
|
|
|
|
try {
|
|
|
|
|
const body = {
|
|
|
|
|
moment_id: id,
|
2024-07-08 20:07:36 +08:00
|
|
|
|
times: times == 1 ? -1 : 1,
|
2024-07-06 11:05:19 +08:00
|
|
|
|
};
|
2024-07-22 16:07:41 +08:00
|
|
|
|
const data = await requireAPI("POST", `/api/zone/thumbs_up`, {
|
2024-07-06 11:05:19 +08:00
|
|
|
|
body,
|
|
|
|
|
});
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
2024-07-08 20:07:36 +08:00
|
|
|
|
} else {
|
|
|
|
|
callback(times == 1 ? -1 : 1);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-07-10 16:50:53 +08:00
|
|
|
|
// 查看关系
|
2024-07-06 11:05:19 +08:00
|
|
|
|
export async function checkRelation(subMid, objMid, predicate) {
|
|
|
|
|
try {
|
2024-07-08 20:07:36 +08:00
|
|
|
|
const data =
|
2024-07-22 16:07:41 +08:00
|
|
|
|
await requireAPI("POST", `/api/account_relation/list_by_sentence`, {
|
2024-07-08 20:07:36 +08:00
|
|
|
|
body: {
|
|
|
|
|
sub_mid: subMid,
|
|
|
|
|
obj_mid: objMid,
|
|
|
|
|
predicate: predicate,
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-07-06 11:05:19 +08:00
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
2024-07-08 20:07:36 +08:00
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
2024-07-06 11:05:19 +08:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return data.data.is_account_relation_existed;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
// 获取用户信息
|
2024-07-10 00:48:37 +08:00
|
|
|
|
export async function getUserInfo() {
|
|
|
|
|
try {
|
2024-07-22 16:07:41 +08:00
|
|
|
|
const data = await requireAPI("POST", `/api/account/list_by_mid`, null, true);
|
2024-07-10 00:48:37 +08:00
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return data.data.account;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-10 16:50:53 +08:00
|
|
|
|
|
|
|
|
|
// 创建订单
|
|
|
|
|
export const createOrder = async (type = "alipay_h5") => {
|
|
|
|
|
if (!selectedPrice.id && !customCoin.selected) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
content: "请选择充值档位",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (customCoin.selected && customCoin.num < 10) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
content: "最低充值1元哦~",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-24 15:32:23 +08:00
|
|
|
|
const base = baseRequest();
|
2024-07-10 16:50:53 +08:00
|
|
|
|
const body = {
|
|
|
|
|
...base,
|
|
|
|
|
product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id,
|
|
|
|
|
custom_coins: customCoin.selected ? customCoin.num : 0,
|
|
|
|
|
pay_type: type,
|
|
|
|
|
redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "",
|
|
|
|
|
from: "app",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//如果是微信jsapi支付直接跳转到中间页
|
|
|
|
|
if (type === "wxpay_jsapi") {
|
|
|
|
|
router.push(`/pay/${encodeURIComponent(JSON.stringify(body))}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
|
|
|
|
|
const signature = generateSignature(body);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(
|
|
|
|
|
`/api/vas/create_order?signature=${signature}`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
content: data.msg,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (type) {
|
|
|
|
|
case "yeepay_alipay_h5":
|
|
|
|
|
router.push(`${data.data.yeepay_alipay_h5_param_str}`);
|
|
|
|
|
break;
|
|
|
|
|
case "yeepay_wxpay_h5":
|
|
|
|
|
router.push(`${data.data.yeepay_wxpay_h5_param_str}`);
|
|
|
|
|
break;
|
|
|
|
|
case "alipay_h5":
|
|
|
|
|
router.push(`${data.data.alipay_h5_param_str}`);
|
|
|
|
|
break;
|
|
|
|
|
case "wxpay_h5":
|
|
|
|
|
router.push(
|
|
|
|
|
`https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent(
|
|
|
|
|
data.data.wxpay_h5_param_str
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
router.push(`${data.data.alipay_h5_param_str}`);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
2024-07-16 20:20:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//点击获取验证码
|
|
|
|
|
export const handleVerification = async (mobilePhone="",regionCode) => {
|
|
|
|
|
console.log("mobilePhone",mobilePhone.toString())
|
|
|
|
|
//手机号校验
|
|
|
|
|
if (!mobilePhone.toString().match(/^1[3456789]\d{9}$/)) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: "手机号码格式错误",
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//对手机号进行RSA加密
|
|
|
|
|
const encrypt = new JSEncrypt();
|
|
|
|
|
encrypt.setPublicKey(process.env.EXPO_PUBLIC_RSA_KEY);
|
|
|
|
|
const mobile_phone = encrypt.encrypt(mobilePhone);
|
|
|
|
|
//发送短信验证码
|
|
|
|
|
try {
|
2024-07-22 16:07:41 +08:00
|
|
|
|
await requireAPI("POST", `/api/veri_code/send`, {
|
2024-07-16 20:20:12 +08:00
|
|
|
|
body: {
|
|
|
|
|
mobile_phone: mobile_phone,
|
|
|
|
|
region_code: regionCode,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-07-18 23:20:42 +08:00
|
|
|
|
|