feat(subscription): 对齐续费接口为一步生成支付码

- 修正续费请求路径为后端实际的 /renew-pay/{id},避免 404 错误
- 续费接口新增 method 和 envVersion 参数支持余额与微信支付
- 续费请求返回支付结果,微信支付返回小程序码,余额支付直接成功
- 续费不再分步调起支付,前端确认续费逻辑简化为一步调用后端接口
- 后端 renewPay 优化,避免放弃支付导致服务中断及时长丢失
- 后端续费激活逻辑调整,续费保留原订阅有效期累计时长
- 排查并解决微信小程序支付配置缺失导致续费失败的问题
- 代码及注释同步更新,完善续费流程整体一致性与稳定性
This commit is contained in:
2026-07-15 22:19:54 +08:00
parent 5b5bb3b0e5
commit 015cd50c08
4 changed files with 84 additions and 28 deletions

View File

@@ -221,19 +221,25 @@ export async function mpConfirm(
}
/**
* 续费:基于已有订阅创建续费订单pending返回新 subscriptionId
* POST /app/subscription/renew/{id}?period=month|year
* 返回结构与 subscribe 一致(含 subscriptionId前端再调 pay 生成支付码
* 续费:基于已有订阅创建续费订单并生成支付码(一步完成,对齐后端 /renew-pay
* POST /app/subscription/renew-pay/{id}?period=month&method=wechat&envVersion=trial
* - method=balance余额支付返回 PayResultpaid/balance
* - method=wechat微信支付返回小程序码 WechatNativePayResultminiappQrcode
* 后端会基于原 expireTime 或 now取较大者延长到期时间
*/
export async function renewSubscription(
id: number,
period: 'month' | 'year' = 'month'
): Promise<SubscribeResult> {
const res = await request.post<ApiResult<SubscribeResult>>(`${BASE}/renew/${id}`, undefined, {
params: { period }
});
period: 'month' | 'year' = 'month',
method: 'balance' | 'wechat' = 'wechat',
envVersion?: string
): Promise<PayResult | WechatNativePayResult> {
const res = await request.post<ApiResult<PayResult | WechatNativePayResult>>(
`${BASE}/renew-pay/${id}`,
undefined,
{ params: { period, method, envVersion } }
);
if (res.data.code === 0) {
return res.data.data as SubscribeResult;
return res.data.data as PayResult | WechatNativePayResult;
}
return Promise.reject(new Error(res.data.message));
}