feat(v1.1.0): 支付改由 epay 插件承载、插件纳入版本库,补齐媒体上传/LBS/互动/优惠券/后台看板,并修复余额充值资损
## 一、支付:改由已安装的 epay 插件承载(不再自研签名)
- 下单:\addons\epay\library\Service::submitOrder($amount 元, $orderNo, 'wechat', $body, $notifyUrl, null, 'miniapp', $openid)
- 验签:Service::checkNotify('wechat')(内部 $pay->verify());应答:$pay->success()(v2 = XML)
- 业务编排仍在 application/api/controller/Pay.php,不改插件源码:
POST /pay/prepay(取调起参数,下发前剔除 appId);POST /pay/notify(公开路由:插件验签 → 金额核对 → 幂等分派)
- 配置真源 = addons/epay/config.php(后台「插件管理 → 微信支付宝整合插件 → 配置」);
fc_config 的 wx.mchId / wx.apiKey / wx.payNotifyUrl 废弃;后台「系统设置」支付表单改只读并跳插件配置页
- 插件 API 保持 version=v2(PHP 7.4 可跑);certs/* 为 0 字节占位,不含任何真实密钥
- 修复 BUG-015:Pay::notify() 与基类站内信同名且签名不兼容导致 /pay/* 全 500,动作改名 notifyCallback()
## 二、插件纳入 Git 版本管理
- .gitignore 移除 /addons/* 与 /public/assets/addons/*(保留 .gitkeep 占位)
- 入库 addons/epay、addons/wechat、public/assets/addons/*、addons/.htaccess(deny from all)
- config.php 入库为空白模板;服务器请在填好密钥后执行
git update-index --skip-worktree addons/epay/config.php,避免真实密钥回传仓库
## 三、安全修复:余额充值资损(高危,已实测复现)
- 现象:POST /order/recharge {payType:'balance'} 只加余额不扣款(余额 134.50 → 1022.50),等于凭空增发余额,
可再去买会员 / 付费发布 / 解锁联系方式
- 修复:/order/recharge 仅接受 payType=wxpay,balance → 「余额充值仅支持微信支付」,其它 → 「支付方式不支持」;
订单恒为 status=pending、pay_type=wxpay、paytime=null;入账只发生在 /pay/notify 回调(Order::creditRecharge)
或后台「会员管理 → 余额充值」(fc/userext/recharge)
- 小程序充值页同步为「仅微信支付」+ 防重复提交 + onShow 刷新资产;mock / 用例 / 文档同步
## 四、其他 v1.1.0 能力
- 媒体上传:POST /post/upload(图片 ≤10MB / 视频 ≤50MB,真落盘),发布页 uni.uploadFile 真上传
- LBS:fc_post.lat/lng、首页 sort=nearby(距离升序、无坐标排最后)、卡片 distance、详情页地图
- 互动:举报 POST /report(原因字典)、收藏 / 关注(fc_favorite / fc_follow、/favorite/*、/follow/toggle)
- 交易:余额充值 POST /order/recharge、优惠券 /coupon/list|receive(fc_coupon / fc_user_coupon、我的资产券)
- 发布计费:会员发布折扣(discountRate/discountText)+ 免费发布条数(freeQuota*)
- 后台新增:数据总览 fc/dashboard、系统设置 fc/setting、优惠券管理 fc/coupon(含菜单与权限节点)
## 五、本批审核修复
- 详情页:游客不再请求登录态接口(避免 401 被清 token 踢去登录);微信付费查看改为支付后轮询解锁,
不再读取 wxpay 分支未返回的 contact;加防重复提交
- 发布页:freeLeftToday → freeQuotaLeft / freeQuotaCycle / freeUnlimited(对齐后端出参);
上传图预览拼后端域名(新增 format.js#assetUrl,后端返回相对路径)
- 收藏空态「去首页」:switchTab → reLaunch(项目用自绘 fc-tabbar,无 tabBar,switchTab 必然失败)
- 会员券 days=0 显示「永久有效」;manifest.json 补 requiredPrivateInfos(getLocation / chooseLocation)
- 后端:publishConfig 补 discountRate/discountText 与 memberPostDiscountText();优惠券总开关 coupon.enabled
真生效(关闭后 list/receive 拒绝);后台 fc/Coupon 的 add/edit 补 strip_tags 过滤(防存储型 XSS)、
补 searchFields='name',列表 name 列再做一次 HTML 转义
- FcInstall:补清理后台菜单缓存 __menu__(否则新菜单要等缓存过期才显示),并同步 README 说明
- 后台语言包 fc/setting.php 按「支付只读 + 跳插件配置」的新页面重写
- 文档同步:uniapp/docs/{01,03,04}、uniapp/README.md、docs/05-后端实现规范.md、后台 README 上线步骤
## 六、校验结果(全部通过)
- 后端端到端:tools/verify-api.mjs 226/226(含新增「拒绝余额充值(资损防护)」用例)
- 小程序:uniapp/tests/run.mjs 167/167;validate.mjs 0 错 0 警;check-scss 19/19
- 后台:check-admin-i18n 0 错 0 警;check-theme 0 错 0 警;9 个页面 HTTP 200 全中文
- php -l 改动/新增 PHP 文件 0 语法错误;探针复测:余额不再增长、epay 插件下单/验签链路通
这个提交包含在:
@@ -67,9 +67,12 @@
|
||||
</view>
|
||||
<view class="detail__map-info">
|
||||
<text class="detail__map-name">{{ post.address }}</text>
|
||||
<text class="detail__map-action">地图导航 ›</text>
|
||||
<text class="detail__map-action">{{ hasLocation ? '地图导航 ›' : '暂无定位信息' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="detail__report" @click="openReport">
|
||||
<text class="detail__report-text">举报该信息 ›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 付费查看联系方式 -->
|
||||
@@ -183,8 +186,13 @@
|
||||
|
||||
<script>
|
||||
import postApi from '@/common/api/post.js'
|
||||
import favoriteApi from '@/common/api/favorite.js'
|
||||
import reportApi from '@/common/api/report.js'
|
||||
import { REPORT_REASONS } from '@/common/constants/report.js'
|
||||
import { iconUrl, categoryIconUrl, loadUiConfig } from '@/common/store/ui.js'
|
||||
import { fromNow, maskPhone } from '@/common/utils/format.js'
|
||||
import { pay } from '@/common/utils/pay.js'
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import config from '@/common/config/index.js'
|
||||
|
||||
export default {
|
||||
@@ -198,16 +206,24 @@ export default {
|
||||
comments: [],
|
||||
followed: false,
|
||||
faved: false,
|
||||
favoriteCount: 0,
|
||||
reportReasons: REPORT_REASONS,
|
||||
showComment: false,
|
||||
showPoster: false,
|
||||
score: 5,
|
||||
commentText: '',
|
||||
// 支付/提交中:防连点重复下单(余额支付是即时扣款)
|
||||
submitting: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
timeText() {
|
||||
return fromNow(this.post.createdAt)
|
||||
},
|
||||
/** 详情是否带真实坐标(契约新增 lat/lng) */
|
||||
hasLocation() {
|
||||
return this.post.lat != null && this.post.lng != null
|
||||
},
|
||||
},
|
||||
onLoad(query) {
|
||||
this.id = Number(query.id || 101)
|
||||
@@ -228,20 +244,82 @@ export default {
|
||||
{ id: 5002, user: '果果', score: 4, content: '信息真实,价格合理。', reply: '感谢支持~' },
|
||||
]
|
||||
this.contact = { phone: maskPhone(res.contact), wechat: '' }
|
||||
// 契约:详情出参已带 faved/followed,先用返回值回显;
|
||||
// 兼容旧后端:缺失时再用 /favorite/status 批量回显。
|
||||
this.faved = !!res.faved
|
||||
this.followed = !!res.followed
|
||||
this.favoriteCount = Number(res.favoriteCount || 0)
|
||||
// /favorite/status 强制登录(游客调用会 401 → 被拦截器清 token 并跳登录页),
|
||||
// 因此只在已登录时用它兜底回显;未登录直接用详情返回的 faved/followed。
|
||||
if (this.isLogin()) await this.loadInteractStatus()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '信息加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
/** 是否已登录(未登录时不请求需要登录态的接口) */
|
||||
isLogin() {
|
||||
try {
|
||||
return !!useUserStore().isLogin.value
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
/** 进入详情时回显收藏 / 关注状态(失败静默,保持默认状态) */
|
||||
async loadInteractStatus() {
|
||||
const publisherId = this.post.publisher && this.post.publisher.id
|
||||
try {
|
||||
const res = await favoriteApi.status({ postIds: [this.id], userIds: publisherId ? [publisherId] : [] })
|
||||
if (res && res.faved) this.faved = !!res.faved[this.id]
|
||||
if (res && res.followed && publisherId) this.followed = !!res.followed[publisherId]
|
||||
} catch (e) {
|
||||
// 状态回显失败不影响详情可用性
|
||||
}
|
||||
},
|
||||
async payView(payType) {
|
||||
if (this.submitting) return
|
||||
this.submitting = true
|
||||
try {
|
||||
const res = await postApi.payView(this.id, { payType })
|
||||
this.unlocked = true
|
||||
this.contact = { phone: res.contact.phone, wechat: res.contact.wechat }
|
||||
// 微信支付:下单只返回 {order}(**不含 contact**),解锁由支付回调 /pay/notify 写 fc_pay_view 完成
|
||||
if (res.order) {
|
||||
await pay({ ...res.order, payType })
|
||||
await this.waitUnlock()
|
||||
return
|
||||
}
|
||||
this.applyContact(res)
|
||||
uni.showToast({ title: '已解锁完整联系方式', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '支付失败', icon: 'none' })
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
},
|
||||
/** 写入已解锁的联系方式(余额/会员/重新拉取时复用) */
|
||||
applyContact(res) {
|
||||
const c = (res && res.contact) || {}
|
||||
this.unlocked = true
|
||||
this.contact = { phone: c.phone || '', wechat: c.wechat || '' }
|
||||
},
|
||||
/**
|
||||
* 微信支付成功后轮询解锁结果:回调写 fc_pay_view 有延迟,
|
||||
* 再次调用 /pay-view 只会命中后端「已解锁直接返回」分支(不会重复扣费),最多试 4 次。
|
||||
*/
|
||||
async waitUnlock() {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, i === 0 ? 800 : 1200))
|
||||
try {
|
||||
const res = await postApi.payView(this.id, { payType: config.constants.PAY_TYPE.WXPAY })
|
||||
if (res && res.unlocked) {
|
||||
this.applyContact(res)
|
||||
uni.showToast({ title: '已解锁完整联系方式', icon: 'none' })
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
// 回调尚未到达:继续重试
|
||||
}
|
||||
}
|
||||
uni.showToast({ title: '支付成功,解锁结果稍后生效', icon: 'none' })
|
||||
},
|
||||
async submitComment() {
|
||||
if (!this.commentText.trim()) {
|
||||
uni.showToast({ title: '请输入评价内容', icon: 'none' })
|
||||
@@ -257,22 +335,65 @@ export default {
|
||||
uni.showToast({ title: e.message, icon: 'none' })
|
||||
}
|
||||
},
|
||||
toggleFollow() {
|
||||
this.followed = !this.followed
|
||||
/** 关注:调接口,失败回退本地状态并 Toast(保持可用) */
|
||||
async toggleFollow() {
|
||||
const publisherId = this.post.publisher && this.post.publisher.id
|
||||
if (!publisherId) return uni.showToast({ title: '发布者信息缺失', icon: 'none' })
|
||||
const prev = this.followed
|
||||
this.followed = !prev
|
||||
try {
|
||||
const res = await favoriteApi.follow({ userId: publisherId })
|
||||
this.followed = !!(res && res.followed)
|
||||
uni.showToast({ title: this.followed ? '已关注' : '已取消关注', icon: 'none' })
|
||||
} catch (e) {
|
||||
this.followed = prev
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
toggleFav() {
|
||||
this.faved = !this.faved
|
||||
uni.showToast({ title: this.faved ? '已收藏' : '已取消收藏', icon: 'none' })
|
||||
/** 收藏:调接口,失败回退本地状态并 Toast(保持可用) */
|
||||
async toggleFav() {
|
||||
const prev = this.faved
|
||||
this.faved = !prev
|
||||
try {
|
||||
const res = await favoriteApi.toggle({ postId: this.id })
|
||||
this.faved = !!(res && res.faved)
|
||||
if (res && typeof res.count === 'number') this.favoriteCount = res.count
|
||||
uni.showToast({ title: this.faved ? '已收藏' : '已取消收藏', icon: 'none' })
|
||||
} catch (e) {
|
||||
this.faved = prev
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
/** 举报:原因取自常量(与后端 report.reasons 默认值一致) */
|
||||
openReport() {
|
||||
uni.showActionSheet({
|
||||
itemList: this.reportReasons,
|
||||
success: async (r) => {
|
||||
const reason = this.reportReasons[r.tapIndex]
|
||||
if (!reason) return
|
||||
try {
|
||||
await reportApi.create({ targetType: 'post', targetId: this.id, reason })
|
||||
uni.showToast({ title: '举报已提交,我们会尽快核实', icon: 'none' })
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '举报失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {},
|
||||
})
|
||||
},
|
||||
goVip() {
|
||||
uni.navigateTo({ url: '/pages/member/index' })
|
||||
},
|
||||
openMap() {
|
||||
if (!this.hasLocation) {
|
||||
uni.showToast({ title: '暂无定位信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.openLocation({
|
||||
latitude: 26.647,
|
||||
longitude: 106.63,
|
||||
name: this.post.address,
|
||||
address: this.post.area,
|
||||
latitude: Number(this.post.lat),
|
||||
longitude: Number(this.post.lng),
|
||||
name: this.post.address || this.post.title,
|
||||
address: this.post.area || '',
|
||||
fail: () => uni.showToast({ title: '导航需在小程序内使用', icon: 'none' }),
|
||||
})
|
||||
},
|
||||
@@ -470,6 +591,16 @@ export default {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-primary-text;
|
||||
}
|
||||
/* 举报入口:低调,不抢主操作 */
|
||||
.detail__report {
|
||||
margin-top: 16rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.detail__report-text {
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.detail__locked {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
在新工单中引用
屏蔽一个用户