feat: add WeChat Pay, Redis logging, storage tiers and personal albums
Replace virtual payments with WeChat Pay API v3 and verify callbacks and order polling. Cache WeChat access tokens in Redis and write structured Zap logs. Support configurable capacity plans across the API, admin and mini program, with purchase snapshots and quota enforcement. Allow personal albums before binding and share them with the current partner. Update deployment configuration and domain routing.
This commit is contained in:
@@ -138,7 +138,7 @@ Page(withDataCache(withListPagination({
|
||||
if (!ticket) return;
|
||||
try {
|
||||
var self = this;
|
||||
var albumId = this.data.albumId;
|
||||
var albumId = /^-\d+$/.test(String(this.data.albumId)) ? null : this.data.albumId;
|
||||
if (!albumId) {
|
||||
var albums = itemsOf(await api.albumList({page:1,page_size:1}));
|
||||
if (albums && albums.length > 0) {
|
||||
@@ -322,18 +322,11 @@ Page(withDataCache(withListPagination({
|
||||
await requestSubscribeAfterAction('photo');
|
||||
|
||||
try {
|
||||
// 上传前先预热 session,确保认证状态有效
|
||||
// 解决 Android 端首次上传时 session 未初始化的问题
|
||||
try {
|
||||
wx.showLoading({ title: '准备中...', mask: true });
|
||||
await api.checkAuth();
|
||||
wx.hideLoading();
|
||||
} catch (e) {
|
||||
wx.hideLoading();
|
||||
console.warn('Session 预热失败(不影响后续上传)', e);
|
||||
var albumId = /^-\d+$/.test(String(this.data.albumId)) ? null : this.data.albumId;
|
||||
if (!albumId) {
|
||||
const albums = itemsOf(await api.albumList({ page: 1, page_size: 1 }));
|
||||
albumId = albums.length ? albums[0].id : null;
|
||||
}
|
||||
|
||||
var albumId = this.data.albumId;
|
||||
if (!albumId) {
|
||||
wx.showLoading({ title: '创建相册...' });
|
||||
var album = await api.albumAdd({ title: '默认相册', description: '我们的甜蜜照片' });
|
||||
@@ -341,6 +334,7 @@ Page(withDataCache(withListPagination({
|
||||
this.setData({ albumId: albumId });
|
||||
wx.hideLoading();
|
||||
}
|
||||
this.setData({ albumId: albumId });
|
||||
var batchId = Date.now().toString();
|
||||
|
||||
// 自动定位:为未填写位置的照片自动获取地理位置(发布后自动显示)
|
||||
|
||||
@@ -1036,7 +1036,7 @@ Page(withDataCache({
|
||||
loadStorageInfo: async function() {
|
||||
try {
|
||||
const d = await api.storageInfo();
|
||||
const freeBytes = d.free_bytes || d.freeBytes || 0;
|
||||
const freeBytes = d.quota_bytes != null ? d.quota_bytes : (d.quotaBytes != null ? d.quotaBytes : (d.free_bytes || d.freeBytes || 0));
|
||||
const usedBytes = d.used_bytes || d.usedBytes || 0;
|
||||
const isVip = !!(d.is_vip || d.isVip);
|
||||
const usedText = formatStorageBytes(usedBytes);
|
||||
@@ -1045,11 +1045,11 @@ Page(withDataCache({
|
||||
const expire = d.vip_expire_at || d.vipExpireAt;
|
||||
this.setData({
|
||||
storageVip: true,
|
||||
storageText: '无限空间',
|
||||
storageText: (d.is_unlimited || d.isUnlimited) ? '无限空间' : formatStorageBytes(freeBytes),
|
||||
storagePercent: 0,
|
||||
storageOverQuota: false,
|
||||
storageOverQuota: !(d.is_unlimited || d.isUnlimited) && usedBytes>freeBytes,
|
||||
storageUsedText: usedText,
|
||||
storageExpireText: expire ? ('有效期至 ' + String(expire).slice(0, 10)) : '已开通无限空间'
|
||||
storageExpireText: expire ? ('有效期至 ' + String(expire).slice(0, 10)) : '已开通容量套餐'
|
||||
});
|
||||
} else {
|
||||
const percent = freeBytes > 0 ? Math.min(100, Math.round(usedBytes / freeBytes * 100)) : 0;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<view wx:if="{{storageVip}}" class="j-storage-card j-storage-vip" bindtap="goStorage">
|
||||
<view class="j-storage-top">
|
||||
<text class="j-storage-label">存储空间</text>
|
||||
<text class="j-storage-val j-vip">👑 无限空间</text>
|
||||
<text class="j-storage-val j-vip">👑 {{storageText}}</text>
|
||||
</view>
|
||||
<view class="j-storage-bottom">
|
||||
<text class="j-storage-hint">已用 {{storageUsedText}}{{storageExpireText ? ' · ' + storageExpireText : ''}}</text>
|
||||
@@ -28,7 +28,7 @@
|
||||
<view class="j-storage-bar"><view class="j-storage-fill" style="width:{{storagePercent}}%;"></view></view>
|
||||
<view class="j-storage-bottom">
|
||||
<text class="j-storage-hint">{{storageOverQuota ? '已超出免费空间,升级后可继续上传' : '已用 ' + storagePercent + '% 免费空间'}}</text>
|
||||
<text class="j-storage-cta">{{storageOverQuota ? '升级无限空间 ›' : '查看 ›'}}</text>
|
||||
<text class="j-storage-cta">{{storageOverQuota ? '扩容 ›' : '查看 ›'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="profile-statistics">
|
||||
|
||||
@@ -21,12 +21,15 @@ Page({
|
||||
percent: 0,
|
||||
overQuota: false,
|
||||
isVip: false,
|
||||
isUnlimited:false,
|
||||
quotaText:"200 MB",
|
||||
vipExpireText: '',
|
||||
plans: [],
|
||||
paying: false,
|
||||
},
|
||||
|
||||
onLoad: function () { this.setData(getLayout()); },
|
||||
onLoad: function () { this._unloaded = false; this.setData(getLayout()); },
|
||||
onUnload: function () { this._unloaded = true; },
|
||||
onShow: function () { this.loadInfo(); },
|
||||
onPullDownRefresh: function () { this.loadInfo().then(function () { wx.stopPullDownRefresh(); }); },
|
||||
|
||||
@@ -34,7 +37,8 @@ Page({
|
||||
var self = this;
|
||||
this.setData({ loading: true, error: false });
|
||||
return api.storageInfo().then(function (d) {
|
||||
var freeBytes = d.free_bytes || d.freeBytes || 0;
|
||||
var freeBytes = d.quota_bytes != null ? d.quota_bytes : (d.quotaBytes != null ? d.quotaBytes : (d.free_bytes || d.freeBytes || 0));
|
||||
var unlimited=!!(d.is_unlimited || d.isUnlimited);
|
||||
var usedBytes = d.used_bytes || d.usedBytes || 0;
|
||||
var percent = freeBytes > 0 ? Math.min(100, Math.round(usedBytes / freeBytes * 100)) : 0;
|
||||
var overQuota = usedBytes > freeBytes;
|
||||
@@ -43,25 +47,30 @@ Page({
|
||||
return {
|
||||
key: p.key,
|
||||
name: p.name,
|
||||
priceText: (cents / 100).toFixed(cents % 100 === 0 ? 0 : 1),
|
||||
unit: p.key === 'year' ? '年' : '月',
|
||||
productId: p.product_id || p.productId,
|
||||
priceCents:cents,
|
||||
version:p.updated_at || p.updatedAt,
|
||||
priceText: (cents / 100).toFixed(2),
|
||||
unit: (p.months || (p.key==='year'?12:1))+'个月',
|
||||
description: (Number(p.quota_mb != null ? p.quota_mb : p.quotaMb || 0)===0 ? '无限空间' : formatBytes(Number(p.quota_mb != null ? p.quota_mb : p.quotaMb)*1024*1024))+' · 有效期'+(p.months || (p.key==='year'?12:1))+'个月',
|
||||
|
||||
};
|
||||
});
|
||||
var vipExpireText = '';
|
||||
if (d.is_vip || d.isVip) {
|
||||
var expire = d.vip_expire_at || d.vipExpireAt ? String(d.vip_expire_at || d.vipExpireAt).slice(0, 10) : '';
|
||||
vipExpireText = expire ? ('有效期至 ' + expire) : '已开通无限空间';
|
||||
vipExpireText = expire ? ('有效期至 ' + expire) : '已开通容量套餐';
|
||||
}
|
||||
self.setData({
|
||||
loading: false,
|
||||
usedBytes: usedBytes,
|
||||
usedText: formatBytes(usedBytes),
|
||||
freeMb: d.free_mb || d.freeMb || 200,
|
||||
freeMb: d.free_mb != null ? d.free_mb : (d.freeMb != null ? d.freeMb : 200),
|
||||
freeText: formatBytes(freeBytes),
|
||||
percent: percent,
|
||||
overQuota: overQuota,
|
||||
isVip: !!(d.is_vip || d.isVip),
|
||||
isUnlimited:unlimited,
|
||||
quotaText:unlimited?"无限空间":formatBytes(freeBytes),
|
||||
vipExpireText: vipExpireText,
|
||||
plans: plans,
|
||||
});
|
||||
@@ -83,14 +92,14 @@ Page({
|
||||
|
||||
wx.showLoading({ title: '下单中...', mask: true });
|
||||
this.setData({ paying: true });
|
||||
api.storageCreateOrder({ plan_key: key }).then(function (order) {
|
||||
api.storageCreateOrder({ plan_key: key, expected_price_cents:plan.priceCents, expected_plan_version:plan.version }).then(function (order) {
|
||||
wx.hideLoading();
|
||||
if (!order || !(order.sign_data || order.signData)) {
|
||||
self.setData({ paying: false });
|
||||
wx.showToast({ title: '下单失败', icon: 'none' });
|
||||
if (order && order.pay_provider === 'wechat' && order.payment) {
|
||||
self.callWechatPay(order);
|
||||
return;
|
||||
}
|
||||
self.callVirtualPay(order);
|
||||
self.setData({ paying: false });
|
||||
wx.showToast({ title: '支付参数不完整,请重新下单', icon: 'none' });
|
||||
}).catch(function (err) {
|
||||
wx.hideLoading();
|
||||
self.setData({ paying: false });
|
||||
@@ -98,37 +107,54 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
callVirtualPay: function (order) {
|
||||
callWechatPay: function (order) {
|
||||
var self = this;
|
||||
if (!wx.requestVirtualPayment) {
|
||||
var payment = order.payment;
|
||||
if (!wx.requestPayment) {
|
||||
this.setData({ paying: false });
|
||||
wx.showModal({
|
||||
title: '版本过低',
|
||||
content: '请升级微信至最新版本后再试。',
|
||||
showCancel: false
|
||||
});
|
||||
wx.showToast({ title: '当前环境不支持微信支付,请使用微信真机', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
// wx.requestVirtualPayment 仅接受 signData / paySig / signature / mode 四个参数;
|
||||
// offerId、env、productId、goodsPrice 等均已编码在 signData JSON 字符串内,不可再平铺为顶层参数。
|
||||
wx.requestVirtualPayment({
|
||||
signData: order.sign_data || order.signData,
|
||||
paySig: order.pay_sig || order.paySig,
|
||||
signature: order.signature,
|
||||
mode: order.mode || 'short_series_goods',
|
||||
success: function () {
|
||||
self.setData({ paying: false });
|
||||
wx.showToast({ title: '支付成功', icon: 'success' });
|
||||
setTimeout(function () { self.loadInfo(); }, 1200);
|
||||
},
|
||||
fail: function (err) {
|
||||
self.setData({ paying: false });
|
||||
var msg = '支付未完成';
|
||||
var m = (err && err.errMsg) || '';
|
||||
if (m.indexOf('cancel') >= 0) msg = '已取消支付';
|
||||
else if (m.indexOf('fail') >= 0) msg = '支付失败,请稍后重试';
|
||||
wx.showToast({ title: msg, icon: 'none' });
|
||||
wx.requestPayment({
|
||||
timeStamp: payment.time_stamp,
|
||||
nonceStr: payment.nonce_str,
|
||||
package: payment.package,
|
||||
signType: payment.sign_type,
|
||||
paySign: payment.pay_sign,
|
||||
success: function () { return self.confirmWechatPayment(order.out_trade_no); },
|
||||
fail: function (error) {
|
||||
// Even a cashier error can occur after payment; query the server once.
|
||||
var message = String(error && error.errMsg || '').indexOf('cancel') >= 0 ? '已取消支付' : '支付未完成';
|
||||
return self.confirmWechatPayment(order.out_trade_no, message);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
confirmWechatPayment: async function (number, failureMessage) {
|
||||
if (this._confirming) return;
|
||||
this._confirming = true;
|
||||
try {
|
||||
for (var attempt = 0; attempt < (failureMessage ? 1 : 5); attempt++) {
|
||||
var result = await api.storageOrderStatus(number);
|
||||
if (this._unloaded) return;
|
||||
if (result.status === 'success') {
|
||||
wx.showToast({ title: '支付成功,会员已开通', icon: 'success' });
|
||||
await this.loadInfo();
|
||||
return;
|
||||
}
|
||||
if (result.status === 'closed') {
|
||||
wx.showToast({ title: '订单已关闭,请重新下单', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!failureMessage && attempt < 4) await new Promise(function (resolve) { setTimeout(resolve, 1200); });
|
||||
}
|
||||
if (!this._unloaded) wx.showToast({ title: failureMessage || '支付结果确认中,请稍后刷新', icon: 'none' });
|
||||
} catch (e) {
|
||||
if (!this._unloaded) wx.showToast({ title: '支付结果暂未确认,请稍后刷新', icon: 'none' });
|
||||
} finally {
|
||||
this._confirming = false;
|
||||
if (!this._unloaded) this.setData({ paying: false });
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
@@ -9,27 +9,27 @@
|
||||
<view class="storage-card">
|
||||
<view class="storage-card-head">
|
||||
<view class="storage-title">已用空间</view>
|
||||
<view class="storage-vip" wx:if="{{isVip}}">👑 无限空间</view>
|
||||
<view class="storage-vip" wx:if="{{isVip}}">👑 {{quotaText}}</view>
|
||||
</view>
|
||||
<view class="storage-used">
|
||||
<text class="storage-num">{{usedText}}</text>
|
||||
<text class="storage-of" wx:if="{{!isVip}}"> / {{freeText}} 免费</text>
|
||||
<text class="storage-of" wx:if="{{!isUnlimited}}"> / {{quotaText}}</text>
|
||||
</view>
|
||||
<view class="storage-bar" wx:if="{{!isVip}}">
|
||||
<view class="storage-bar" wx:if="{{!isUnlimited}}">
|
||||
<view class="storage-bar-fill" style="width: {{percent}}%;"></view>
|
||||
</view>
|
||||
<view class="storage-hint" wx:if="{{isVip}}">{{vipExpireText}}</view>
|
||||
<view class="storage-hint over" wx:elif="{{overQuota}}">已超出免费空间,升级后即可继续上传</view>
|
||||
<view class="storage-hint" wx:else>已使用 {{percent}}% 免费空间</view>
|
||||
<view class="storage-hint" wx:else>已使用 {{percent}}% 存储空间</view>
|
||||
</view>
|
||||
|
||||
<!-- 套餐 -->
|
||||
<view class="section-heading">升级无限空间</view>
|
||||
<view class="section-heading">选择容量套餐</view>
|
||||
<view class="plan-list">
|
||||
<view class="plan-card" wx:for="{{plans}}" wx:key="key" bindtap="buyPlan" data-key="{{item.key}}">
|
||||
<view class="plan-info">
|
||||
<view class="plan-name">{{item.name}}</view>
|
||||
<view class="plan-desc">无限存储空间,照片视频想存就存</view>
|
||||
<view class="plan-desc">{{item.description}}</view>
|
||||
</view>
|
||||
<view class="plan-price">
|
||||
<text class="plan-amount">¥{{item.priceText}}</text>
|
||||
@@ -38,12 +38,13 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="storage-hint" wx:if="{{!loading && !plans.length}}">暂无上架套餐</view>
|
||||
<!-- 说明 -->
|
||||
<view class="storage-note">
|
||||
<view class="note-title">📌 说明</view>
|
||||
<view class="note-item">• 默认提供 {{freeMb}}MB 免费空间</view>
|
||||
<view class="note-item">• 开通会员后,照片、视频等不再限制存储空间</view>
|
||||
<view class="note-item">• 会员到期后,已上传内容仍可正常查看</view>
|
||||
<view class="note-item">• 套餐容量为总可用容量,不与免费额度叠加;情侣共享当前有效的最大容量</view>
|
||||
<view class="note-item">• 套餐到期后已上传内容仍可查看,超出可用容量将暂停新增上传</view>
|
||||
</view>
|
||||
|
||||
<page-state wx:if="{{error}}" kind="error" title="加载失败" action="重试" bind:action="loadInfo" />
|
||||
|
||||
Reference in New Issue
Block a user