2025-03-19 19:04:10 +08:00
|
|
|
|
import {showMessage} from "../dialog/message";
|
2025-03-19 19:44:17 +08:00
|
|
|
|
import {fetchPost} from "./fetch";
|
|
|
|
|
|
import {genUUID} from "./genID";
|
2025-03-19 21:44:49 +08:00
|
|
|
|
import {progressLoading} from "../dialog/processSystem";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
|
2025-03-19 19:44:17 +08:00
|
|
|
|
export const processIOSPurchaseResponse = (code: number) => {
|
2025-03-19 21:44:49 +08:00
|
|
|
|
progressLoading({
|
|
|
|
|
|
code: 2,
|
|
|
|
|
|
msg: ""
|
|
|
|
|
|
});
|
2025-03-19 19:04:10 +08:00
|
|
|
|
if (code === 0) {
|
|
|
|
|
|
/// #if MOBILE
|
|
|
|
|
|
document.querySelector("#modelMain").dispatchEvent(new CustomEvent("click", {
|
|
|
|
|
|
detail: document.querySelector("#modelMain #refresh")
|
|
|
|
|
|
}));
|
|
|
|
|
|
/// #else
|
|
|
|
|
|
document.querySelector('.config__tab-container[data-name="account"] #refresh').dispatchEvent(new Event("click"));
|
|
|
|
|
|
/// #endif
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// -1:Invalid cloud region 云端区域无效
|
|
|
|
|
|
// -2:Server communication failed, need to retry 服务器通讯失败,需要重试
|
|
|
|
|
|
// -3:Non-iOS device 非 iOS 设备
|
|
|
|
|
|
// -4:Account not logged in 账号未登录
|
|
|
|
|
|
// -5:Account status abnormal 账号状态异常
|
|
|
|
|
|
// -6:Parameter error 参数错误
|
|
|
|
|
|
// -7:AccountToken verification failed 校验 accountToken 失败
|
|
|
|
|
|
// -8:Transaction verification failed 校验 transaction 失败
|
2025-03-19 22:22:57 +08:00
|
|
|
|
// -9:Unknown product 未知的商品
|
2025-03-25 12:12:36 +08:00
|
|
|
|
// -10:用户取消交易
|
|
|
|
|
|
// -11:购买交易被挂起
|
|
|
|
|
|
// -12:其他情况
|
2025-03-19 19:04:10 +08:00
|
|
|
|
let message = "";
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
case -1:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Invalid cloud region.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -2:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Server communication failed, need to retry.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -3:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Non-iOS device.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -4:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Account not logged in.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -5:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Account status abnormal.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -6:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Parameter error.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -7:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "AccountToken verification failed.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case -8:
|
2025-03-19 20:15:42 +08:00
|
|
|
|
message = "Transaction verification failed.";
|
2025-03-19 19:04:10 +08:00
|
|
|
|
break;
|
2025-03-19 22:22:57 +08:00
|
|
|
|
case -9:
|
|
|
|
|
|
message = "Unknown product.";
|
|
|
|
|
|
break;
|
2025-03-25 12:12:36 +08:00
|
|
|
|
case -10:
|
|
|
|
|
|
message = "User canceled the transaction.";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case -11:
|
|
|
|
|
|
message = "Purchase transaction was suspended.";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case -12:
|
|
|
|
|
|
message = "Purchase failed.";
|
|
|
|
|
|
break;
|
2025-03-19 19:04:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
showMessage(message, 0, "error");
|
|
|
|
|
|
}
|
2025-03-19 18:53:41 +08:00
|
|
|
|
};
|
2025-03-19 19:44:17 +08:00
|
|
|
|
|
|
|
|
|
|
export const iOSPurchase = (productType: string) => {
|
|
|
|
|
|
if (window.siyuan.user) {
|
|
|
|
|
|
fetchPost("/api/setting/getCloudUser", {
|
|
|
|
|
|
token: window.siyuan.user.userToken,
|
|
|
|
|
|
}, response => {
|
|
|
|
|
|
if (window.siyuan.user.userSiYuanOneTimePayStatus !== response.data.userSiYuanOneTimePayStatus ||
|
|
|
|
|
|
window.siyuan.user.userSiYuanProExpireTime !== response.data.userSiYuanProExpireTime ||
|
|
|
|
|
|
window.siyuan.user.userSiYuanSubscriptionPlan !== response.data.userSiYuanSubscriptionPlan ||
|
|
|
|
|
|
window.siyuan.user.userSiYuanSubscriptionType !== response.data.userSiYuanSubscriptionType ||
|
|
|
|
|
|
window.siyuan.user.userSiYuanSubscriptionStatus !== response.data.userSiYuanSubscriptionStatus) {
|
|
|
|
|
|
showMessage(window.siyuan.languages["_kernel"][19]);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
window.siyuan.user = response.data;
|
|
|
|
|
|
let productID;
|
|
|
|
|
|
if (window.siyuan.config.cloudRegion === 0) {
|
|
|
|
|
|
productID = productType === "function" ? "china00" : "china02";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
productID = productType === "function" ? "00" : "02";
|
|
|
|
|
|
}
|
|
|
|
|
|
window.webkit.messageHandlers.purchase.postMessage(`${productID} ${genUUID().substring(0, 19)}${window.siyuan.config.cloudRegion}00${window.siyuan.user.userId.substring(0, 1)}-${window.siyuan.user.userId.substring(1)}`);
|
2025-03-19 21:44:49 +08:00
|
|
|
|
progressLoading({
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
msg: ""
|
|
|
|
|
|
});
|
2025-03-19 19:44:17 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showMessage(window.siyuan.languages.needLogin);
|
|
|
|
|
|
}
|
2025-03-19 21:46:18 +08:00
|
|
|
|
};
|