feat: support balance pay

This commit is contained in:
Rogee
2025-05-12 19:45:47 +08:00
parent f8678c1197
commit 1fa31a6b71
11 changed files with 186 additions and 41 deletions

View File

@@ -92,35 +92,40 @@ const handleBuy = async () => {
buying.value = true;
try {
const response = await postApi.buy(article.value.id);
const payData = response.data;
// 调用微信支付
window.WeixinJSBridge.invoke(
"getBrandWCPayRequest",
{
...payData,
},
async function (res) {
if (res.err_msg === "get_brand_wcpay_request:ok") {
// 支付成功,刷新文章数据
fetchArticle();
await updateMediaSource();
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
// 用户取消支付
console.log("Payment cancelled");
alert("支付已取消");
} else {
// 支付失败或取消
console.error("Payment failed:", res.err_msg);
alert(
"支付失败:" +
(res.err_msg === "get_brand_wcpay_request:cancel"
? "支付已取消"
: "支付异常")
);
if (payData.AppID != "balance") {
// 调用微信支付
window.WeixinJSBridge.invoke(
"getBrandWCPayRequest",
{
...payData,
},
async function (res) {
if (res.err_msg === "get_brand_wcpay_request:ok") {
// 支付成功,刷新文章数据
fetchArticle();
await updateMediaSource();
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
// 用户取消支付
console.log("Payment cancelled");
alert("支付已取消");
} else {
// 支付失败或取消
console.error("Payment failed:", res.err_msg);
alert(
"支付失败:" +
(res.err_msg === "get_brand_wcpay_request:cancel"
? "支付已取消"
: "支付异常")
);
}
}
}
);
);
} else {
alert("余额支付成功");
}
} catch (error) {
console.error("Failed to initiate payment:", error);
alert("发起支付失败,请稍后重试");
@@ -225,7 +230,7 @@ onUnmounted(() => {
</div>
<button @click="handleBuy" :disabled="buying"
class="bg-orange-600 text-white px-8 py-2 rounded hover:bg-orange-500 active:bg-orange-600 transition-colors disabled:opacity-50">
<span v-if="buying">处理中...</span>
<span v-if="buying">购买中...</span>
<span v-else>立即购买</span>
</button>
</div>