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 插件下单/验签链路通
这个提交包含在:
16
uniapp/common/api/coupon.js
普通文件
16
uniapp/common/api/coupon.js
普通文件
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 接口模块 · 优惠券(用户端)
|
||||
* 对应契约 §2.1:
|
||||
* GET /coupon/list {page,size} → 分页(可领取 + 已领取标记 received)
|
||||
* POST /coupon/receive {couponId} → {userCouponId}
|
||||
*/
|
||||
import { get, post } from '../utils/request.js'
|
||||
|
||||
export const couponApi = {
|
||||
/** 可领取优惠券列表(含 received 已领取标记) */
|
||||
list: (params = {}) => get('/coupon/list', params, { silent: true }),
|
||||
/** 领取优惠券 */
|
||||
receive: (couponId) => post('/coupon/receive', { couponId }, { silent: true }),
|
||||
}
|
||||
|
||||
export default couponApi
|
||||
22
uniapp/common/api/favorite.js
普通文件
22
uniapp/common/api/favorite.js
普通文件
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 接口模块 · 收藏与关注(用户端)
|
||||
* 对应契约 §2.1:
|
||||
* GET /favorite/list 分页(list 项为 Post 结构)
|
||||
* POST /favorite/toggle {postId} → {faved,count}
|
||||
* POST /follow/toggle {userId} → {followed}
|
||||
* POST /favorite/status {postIds:[],userIds:[]} → {faved:{},followed:{}}
|
||||
*/
|
||||
import { get, post } from '../utils/request.js'
|
||||
|
||||
export const favoriteApi = {
|
||||
/** 我的收藏(分页,list 项为 Post 结构) */
|
||||
list: (params = {}) => get('/favorite/list', params, { silent: true }),
|
||||
/** 收藏 / 取消收藏(返回最新状态与收藏总数) */
|
||||
toggle: (payload = {}) => post('/favorite/toggle', payload, { silent: true }),
|
||||
/** 关注 / 取消关注发布者 */
|
||||
follow: (payload = {}) => post('/follow/toggle', payload, { silent: true }),
|
||||
/** 批量回显收藏 / 关注状态 */
|
||||
status: (payload = {}) => post('/favorite/status', payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default favoriteApi
|
||||
@@ -9,7 +9,12 @@ export const homeApi = {
|
||||
banners: () => get('/home/banners', {}, { silent: true }),
|
||||
/** 分类导航 */
|
||||
categories: () => get('/home/categories', {}, { silent: true }),
|
||||
/** 信息流(LBS + 筛选排序) */
|
||||
/**
|
||||
* 信息流(LBS + 筛选排序)
|
||||
* 入参:{ page, size, categoryId, keyword, area, sort, lat, lng }
|
||||
* sort: new 最新 / hot 最热 / price 价格 / nearby 附近(按 distance 升序,无坐标排最后)
|
||||
* 出参列表项含 distance(float|km,一位小数;信息无坐标时 null)
|
||||
*/
|
||||
feed: (params = {}) => get('/home/feed', params, { silent: true }),
|
||||
/** 热门搜索词 */
|
||||
hotKeywords: () => get('/home/search/hot', {}, { silent: true }),
|
||||
|
||||
@@ -10,3 +10,9 @@ export { distributionApi } from './distribution.js'
|
||||
export { messageApi } from './message.js'
|
||||
export { settingApi } from './setting.js'
|
||||
export { adminApi } from './admin.js'
|
||||
// v1.1.0 新增(契约 §2.1)
|
||||
export { favoriteApi } from './favorite.js'
|
||||
export { reportApi } from './report.js'
|
||||
export { orderApi } from './order.js'
|
||||
export { payApi } from './pay.js'
|
||||
export { couponApi } from './coupon.js'
|
||||
|
||||
17
uniapp/common/api/order.js
普通文件
17
uniapp/common/api/order.js
普通文件
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 接口模块 · 订单(用户端)
|
||||
* 对应契约 §2.1:POST /order/recharge {amount,payType} → {orderNo,amount,status,payType}
|
||||
* 说明:与后端 application/api/controller/Order.php 不是同一文件,仅为前端封装。
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
|
||||
export const orderApi = {
|
||||
/**
|
||||
* 余额充值下单
|
||||
* ⚠️ 只支持微信支付(payType='wxpay'):订单落 pending,走 /pay/prepay 调起收银台后由 /pay/notify 回调入账。
|
||||
* 服务端禁止 payType='balance'(用余额给余额加钱会凭空增发余额,属资损)。
|
||||
*/
|
||||
recharge: (payload = {}) => post('/order/recharge', payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default orderApi
|
||||
15
uniapp/common/api/pay.js
普通文件
15
uniapp/common/api/pay.js
普通文件
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 接口模块 · 支付(用户端)
|
||||
* 对应契约 §2.1:POST /pay/prepay {orderNo} → {orderNo,payType:'wxpay',payParams:{timeStamp,nonceStr,package,signType,paySign}}
|
||||
* 说明:与后端 application/api/controller/Pay.php 不是同一文件,仅为前端封装。
|
||||
* 页面不要直接调用本模块,统一走 common/utils/pay.js。
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
|
||||
export const payApi = {
|
||||
/** 微信支付统一下单:拿 JSAPI 调起参数(未配置商户参数时后端返回「微信支付未配置」) */
|
||||
prepay: (payload = {}) =>
|
||||
post('/pay/prepay', typeof payload === 'string' ? { orderNo: payload } : payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default payApi
|
||||
@@ -2,9 +2,48 @@
|
||||
* 接口模块 · 信息发布 与 信息详情(用户端)
|
||||
* 对应模块:发布表单 / 付费置帖 / 套餐发帖 / 草稿箱 / 内容展示 / 付费查看 / 评价互动
|
||||
*/
|
||||
import { get, post, del } from '../utils/request.js'
|
||||
import { get, post, del, buildUrl, buildHeaders } from '../utils/request.js'
|
||||
|
||||
export const postApi = {
|
||||
/**
|
||||
* 上传发布媒体(图片 / 视频)
|
||||
* 契约 §2.1:POST /post/upload multipart `file`(+可选 `type=image|video`)→ {url,type,size,name}
|
||||
* 小程序环境走 uni.uploadFile(multipart/form-data,带 Authorization),
|
||||
* Node 测试 / H5 环境回落 mock 路由,保证离线可跑。
|
||||
* @param {String} filePath uni.chooseImage / uni.chooseVideo 得到的临时路径
|
||||
* @param {'image'|'video'} type
|
||||
* @returns {Promise<{url:string,type:string,size:number,name:string}>}
|
||||
*/
|
||||
uploadMedia(filePath, type = 'image') {
|
||||
const kind = type === 'video' ? 'video' : 'image'
|
||||
if (typeof uni === 'undefined' || !uni.uploadFile) {
|
||||
return post('/post/upload', { file: filePath, type: kind }, { silent: true })
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const header = buildHeaders()
|
||||
// uni.uploadFile 自行设置 multipart 边界,不能带 application/json
|
||||
delete header['Content-Type']
|
||||
uni.uploadFile({
|
||||
url: buildUrl('/post/upload'),
|
||||
filePath,
|
||||
name: 'file',
|
||||
formData: { type: kind },
|
||||
header,
|
||||
success: (res) => {
|
||||
let body = res && res.data
|
||||
try {
|
||||
body = JSON.parse(res.data)
|
||||
} catch (e) {}
|
||||
if (body && body.code === 0) {
|
||||
resolve(body.data)
|
||||
return
|
||||
}
|
||||
reject(new Error((body && body.message) || '上传失败'))
|
||||
},
|
||||
fail: () => reject(new Error('上传失败')),
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 发布信息(返回审核状态,付费时返回支付订单;金额由服务端按后台配置计算) */
|
||||
create: (payload) => post('/post/create', payload, { silent: true }),
|
||||
/** 我的发布(status: all 默认 / pending 待审核 / passed 已通过 / rejected 已驳回 / offline 已下架) */
|
||||
|
||||
15
uniapp/common/api/report.js
普通文件
15
uniapp/common/api/report.js
普通文件
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 接口模块 · 举报(用户端)
|
||||
* 对应契约 §2.1:POST /report {targetType:'post'|'comment', targetId, reason, detail?} → {reportId}
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
import { REPORT_REASONS } from '../constants/report.js'
|
||||
|
||||
export const reportApi = {
|
||||
/** 提交举报(原因取自常量清单,默认与后端 report.reasons 一致) */
|
||||
create: (payload = {}) => post('/report', payload, { silent: true }),
|
||||
/** 举报原因清单(供页面 uni.showActionSheet 使用) */
|
||||
reasons: REPORT_REASONS,
|
||||
}
|
||||
|
||||
export default reportApi
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 举报相关常量(用户端)
|
||||
* 与后端 fc_config 的 `report.reasons`(JSON 数组)保持同一份默认值,
|
||||
* 前端不再各页面硬编码原因列表。
|
||||
*/
|
||||
|
||||
/** 举报原因(默认清单,后端可通过 report.reasons 覆盖下发) */
|
||||
export const REPORT_REASONS = ['虚假信息', '违法违禁', '垃圾广告', '重复发布', '其他']
|
||||
|
||||
/** 举报对象类型(与 api/v1/report 的 targetType 一致) */
|
||||
export const REPORT_TARGET = { POST: 'post', COMMENT: 'comment' }
|
||||
|
||||
export default { REPORT_REASONS, REPORT_TARGET }
|
||||
@@ -44,7 +44,7 @@ export const datasets = {
|
||||
/** 热门搜索 */
|
||||
hotKeywords: ['租房 一室一厅', '二手电动车', '急招快递员', '钢琴家教', '空调维修'],
|
||||
|
||||
/** 信息流(含待审核/已通过/已驳回,供两端联调) */
|
||||
/** 信息流(含待审核/已通过/已驳回,供两端联调;lat/lng 为 LBS 坐标,distance 单位 km 一位小数) */
|
||||
posts: [
|
||||
{
|
||||
id: 101, categoryId: 1, categoryName: '招聘求职', title: '急招快递分拣员(日结)',
|
||||
@@ -53,7 +53,7 @@ export const datasets = {
|
||||
contact: '139****8888', contactFull: '13988888888', views: 1892, likes: 32,
|
||||
isPaid: false, auditStatus: 1, createdAt: iso(0.2), tags: ['日结', '包吃'],
|
||||
publisher: { id: 2001, name: '顺捷物流', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 12, distance: 1200,
|
||||
commentCount: 12, lat: 26.6157, lng: 106.6979, distance: 7.6,
|
||||
},
|
||||
{
|
||||
id: 102, categoryId: 2, categoryName: '房产租售', title: '整租·未来方舟精装一室一厅',
|
||||
@@ -62,7 +62,7 @@ export const datasets = {
|
||||
contact: '135****6666', contactFull: '13566666666', views: 3204, likes: 88,
|
||||
isPaid: true, auditStatus: 1, createdAt: iso(0.5), tags: ['精装', '近地铁'],
|
||||
publisher: { id: 2002, name: '安家房产', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 26, distance: 3400,
|
||||
commentCount: 26, lat: 26.5716, lng: 106.7314, distance: 13.1,
|
||||
},
|
||||
{
|
||||
id: 103, categoryId: 3, categoryName: '二手闲置', title: '九成新山地自行车 转让',
|
||||
@@ -71,7 +71,7 @@ export const datasets = {
|
||||
contact: '137****1234', contactFull: '13712341234', views: 640, likes: 21,
|
||||
isPaid: false, isTop: true, auditStatus: 1, createdAt: iso(1), tags: ['自提', '9成新'],
|
||||
publisher: { id: 2003, name: '骑行爱好者', avatar: '', isMerchant: false, verified: false },
|
||||
commentCount: 4, distance: 820,
|
||||
commentCount: 4, lat: 26.6300, lng: 106.6250, distance: 1.9,
|
||||
},
|
||||
{
|
||||
id: 104, categoryId: 4, categoryName: '车辆买卖', title: '2019 款家用轿车 一手车',
|
||||
@@ -80,7 +80,7 @@ export const datasets = {
|
||||
contact: '138****0000', contactFull: '13800000000', views: 1120, likes: 40,
|
||||
isPaid: true, auditStatus: 0, createdAt: iso(0.1), tags: ['无事故', '可检测'],
|
||||
publisher: { id: 2004, name: '车行天下', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 0, distance: 5100,
|
||||
commentCount: 0, lat: 26.6049, lng: 106.7194, distance: 10.0,
|
||||
},
|
||||
{
|
||||
id: 105, categoryId: 5, categoryName: '本地服务', title: '专业空调清洗 / 加氟上门',
|
||||
@@ -89,7 +89,7 @@ export const datasets = {
|
||||
contact: '131****5678', contactFull: '13156785678', views: 2310, likes: 66,
|
||||
isPaid: false, auditStatus: 0, createdAt: iso(0.05), tags: ['上门', '不满意不收费'],
|
||||
publisher: { id: 2005, name: '洁净到家', avatar: '', isMerchant: true, verified: true },
|
||||
commentCount: 18, distance: 2600,
|
||||
commentCount: 18, lat: 26.5600, lng: 106.6870, distance: 11.2,
|
||||
},
|
||||
{
|
||||
id: 106, categoryId: 3, categoryName: '二手闲置', title: 'iPad 2021 64G 深空灰',
|
||||
@@ -98,7 +98,7 @@ export const datasets = {
|
||||
contact: '150****3344', contactFull: '15033443344', views: 480, likes: 15,
|
||||
isPaid: false, auditStatus: 2, createdAt: iso(2), tags: ['验机'],
|
||||
publisher: { id: 2006, name: '小王同学', avatar: '', isMerchant: false, verified: false },
|
||||
commentCount: 1, distance: 1500,
|
||||
commentCount: 1, lat: 26.6230, lng: 106.6400, distance: 2.8,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -114,17 +114,25 @@ export const datasets = {
|
||||
* 发布配置(后台「发布与费用配置」下发;与 fa_fc_config 的 post.* 对齐)
|
||||
* mode:free 免费发布 / paid 付费发布(付费模式下按 singlePrice 或套餐额度)
|
||||
* quotaLeft:当前用户的剩余发布条数(套餐额度,随会员有效期)
|
||||
* discountRate:会员发布折扣率(1 = 无折扣,0.8 = 8 折);单条金额 = round(singlePrice * discountRate, 2)
|
||||
* discountText:折扣展示文案(如「8 折」),无折扣时为空
|
||||
*/
|
||||
publishRule: {
|
||||
mode: 'paid',
|
||||
singlePrice: 5,
|
||||
discountRate: 1,
|
||||
discountText: '',
|
||||
monthPrice: 19.9,
|
||||
monthQuota: 30,
|
||||
yearPrice: 168,
|
||||
yearQuota: 500,
|
||||
quotaLeft: 30,
|
||||
freePerDay: 2, // 每日免费发布条数(付费模式下仍保留的免费次数)
|
||||
freeUsedToday: 0,
|
||||
// 免费发布条数(字段名与后端 Post::publishConfig 对齐:freeQuota/freeQuotaCycle/freeQuotaUsed/freeQuotaLeft/freeUnlimited)
|
||||
freeQuota: 2, // 周期内免费发布条数
|
||||
freeQuotaCycle: 'daily',
|
||||
freeQuotaUsed: 0,
|
||||
freeQuotaLeft: 2, // -1 表示不限制
|
||||
freeUnlimited: false,
|
||||
quotaExpireAt: iso(-25),
|
||||
isMember: true,
|
||||
memberExpireAt: iso(-25),
|
||||
@@ -183,13 +191,38 @@ export const datasets = {
|
||||
benefits: ['每日免费查看 20 条联系方式', '发布信息 8 折', '专属会员标识', '分销佣金加速结算'],
|
||||
},
|
||||
|
||||
/** 我的资产 */
|
||||
/** 我的资产(coupons / couponCount 由 /member/assets 从 fc_user_coupon 实时聚合) */
|
||||
assets: {
|
||||
balance: 128.5,
|
||||
coupons: [{ id: 1, name: '发布立减 3 元', amount: 3, expireAt: iso(-20) }],
|
||||
points: 320,
|
||||
},
|
||||
|
||||
/** 可领取的优惠券定义(fc_coupon) */
|
||||
coupons: [
|
||||
{ id: 1, name: '发布立减 3 元', type: 'fixed', amount: 3, minAmount: 0, total: 1000, receivedCount: 12, enabled: true, sort: 1, days: 30 },
|
||||
{ id: 2, name: '满 50 减 10', type: 'fixed', amount: 10, minAmount: 50, total: 500, receivedCount: 88, enabled: true, sort: 2, days: 15 },
|
||||
{ id: 3, name: '会员开通 9 折', type: 'discount', amount: 0.9, minAmount: 0, total: 200, receivedCount: 30, enabled: true, sort: 3, days: 7 },
|
||||
{ id: 4, name: '已停发券', type: 'fixed', amount: 5, minAmount: 20, total: 100, receivedCount: 100, enabled: false, sort: 4, days: 10 },
|
||||
],
|
||||
|
||||
/** 我已领取的优惠券(fc_user_coupon) */
|
||||
userCoupons: [
|
||||
{ id: 1, couponId: 1, status: 'unused', orderNo: '', usetime: '', expiretime: iso(-20), createtime: iso(2) },
|
||||
],
|
||||
|
||||
/** 我的收藏(fc_favorite:user_id + post_id) */
|
||||
favorites: [
|
||||
{ id: 1, postId: 101, createtime: iso(1) },
|
||||
],
|
||||
|
||||
/** 我的关注(fc_follow:user_id + target_user_id) */
|
||||
follows: [
|
||||
{ id: 1, targetUserId: 2001, createtime: iso(2) },
|
||||
],
|
||||
|
||||
/** 微信支付商户参数是否已配置(未配置时 /pay/prepay 返回「微信支付未配置」,余额支付不受影响) */
|
||||
wxPayConfigured: true,
|
||||
|
||||
/** 订单(发布/会员/充值 三类,供用户端与后台共用) */
|
||||
orders: [
|
||||
{ id: 3001, orderNo: 'PO20240101001', type: 'post', title: '单条付费发布', amount: 5, payType: 'wxpay', status: 'paid', createdAt: iso(1) },
|
||||
|
||||
@@ -43,6 +43,63 @@ function paginate(list, page = 1, size = 10) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 保留一位小数 */
|
||||
function round1(n) {
|
||||
return Math.round(Number(n) * 10) / 10
|
||||
}
|
||||
|
||||
/** 保留两位小数(金额) */
|
||||
function round2(n) {
|
||||
return Math.round(Number(n) * 100) / 100
|
||||
}
|
||||
|
||||
/**
|
||||
* 经纬度球面距离(km,Haversine)
|
||||
* 与后端 fc_post.lat/lng 的 LBS 口径一致:出参 distance 单位 km、一位小数。
|
||||
*/
|
||||
function haversineKm(lat1, lng1, lat2, lng2) {
|
||||
const R = 6371
|
||||
const rad = (d) => (d * Math.PI) / 180
|
||||
const dLat = rad(lat2 - lat1)
|
||||
const dLng = rad(lng2 - lng1)
|
||||
const a =
|
||||
Math.sin(dLat / 2) ** 2 +
|
||||
Math.cos(rad(lat1)) * Math.cos(rad(lat2)) * Math.sin(dLng / 2) ** 2
|
||||
return 2 * R * Math.asin(Math.min(1, Math.sqrt(a)))
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析后台配置的会员发布折扣文案(如 '8 折' → 0.8)
|
||||
* 解析失败或不含折扣时视作 1(与契约 §2.1 一致)。
|
||||
*/
|
||||
export function parseDiscountRate(text) {
|
||||
if (text == null || text === '') return 1
|
||||
if (typeof text === 'number') return text > 0 && text <= 1 ? text : 1
|
||||
const s = String(text)
|
||||
const m = s.match(/(\d+(?:\.\d+)?)\s*折/)
|
||||
if (!m) return 1
|
||||
const zhe = Number(m[1])
|
||||
if (!zhe || zhe <= 0 || zhe > 10) return 1
|
||||
return Math.round((zhe / 10) * 100) / 100
|
||||
}
|
||||
|
||||
/** 聚合我的优惠券(fc_user_coupon + fc_coupon),字段与后端 /member/assets 一致 */
|
||||
function buildUserCoupons() {
|
||||
return datasets.userCoupons.map((uc) => {
|
||||
const c = datasets.coupons.find((x) => x.id === uc.couponId) || {}
|
||||
return {
|
||||
id: uc.id,
|
||||
couponId: uc.couponId,
|
||||
name: c.name || '',
|
||||
type: c.type || 'fixed',
|
||||
amount: c.amount || 0,
|
||||
minAmount: c.minAmount || 0,
|
||||
status: uc.status,
|
||||
expireAt: uc.expiretime,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const mockRoutes = {
|
||||
// ==================== 用户端 · 认证与登录 ====================
|
||||
'POST /auth/wx-login': ({ data }) => {
|
||||
@@ -96,14 +153,56 @@ export const mockRoutes = {
|
||||
if (data && data.categoryId) list = list.filter((p) => p.categoryId === Number(data.categoryId))
|
||||
if (data && data.keyword) list = list.filter((p) => p.title.includes(data.keyword))
|
||||
if (data && data.area) list = list.filter((p) => p.area === data.area)
|
||||
|
||||
// LBS:带坐标时按坐标实时计算距离(km,一位小数);信息自身无坐标时 distance = null
|
||||
const hasLoc =
|
||||
!!(data && data.lat != null && data.lng != null && data.lat !== '' && data.lng !== '')
|
||||
list = list.map((p) => {
|
||||
const hasPostLoc = p.lat != null && p.lng != null
|
||||
if (hasLoc) {
|
||||
return {
|
||||
...p,
|
||||
distance: hasPostLoc
|
||||
? round1(haversineKm(Number(data.lat), Number(data.lng), Number(p.lat), Number(p.lng)))
|
||||
: null,
|
||||
}
|
||||
}
|
||||
// 请求未带坐标:与后端 Home::feed 口径一致,一律 distance = null
|
||||
// (不再回退数据集里的静态距离,否则前端会显示"假距离")
|
||||
return { ...p, distance: null }
|
||||
})
|
||||
|
||||
list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || (new Date(b.createdAt) - new Date(a.createdAt)))
|
||||
if (data && data.sort === 'price') list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || ((a.price || 0) - (b.price || 0)))
|
||||
if (data && data.sort === 'hot') list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || (b.views - a.views))
|
||||
// 附近:按距离升序,无坐标的排最后(置顶仍优先)
|
||||
if (data && data.sort === 'nearby') {
|
||||
const byDistance = (a, b) => {
|
||||
if (a.distance == null && b.distance == null) return 0
|
||||
if (a.distance == null) return 1
|
||||
if (b.distance == null) return -1
|
||||
return a.distance - b.distance
|
||||
}
|
||||
list.sort((a, b) => (Number(b.isTop) - Number(a.isTop)) || byDistance(a, b))
|
||||
}
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'GET /home/search/hot': () => ok(datasets.hotKeywords),
|
||||
|
||||
// ==================== 用户端 · 信息发布 ====================
|
||||
'POST /post/upload': ({ data }) => {
|
||||
// 真实后端为 multipart 上传落盘;mock 只返回**相对路径**(与后端一致,由前端拼域名展示)
|
||||
if (!data || !data.file) fail('未接收到上传文件')
|
||||
const type = data.type === 'video' ? 'video' : 'image'
|
||||
const ext = type === 'video' ? '.mp4' : '.jpg'
|
||||
const path = `/uploads/mock/post_${Date.now()}${ext}`
|
||||
return ok({
|
||||
url: path,
|
||||
type,
|
||||
size: type === 'video' ? 1024 * 1024 : 120 * 1024,
|
||||
name: `post_${Date.now()}${ext}`,
|
||||
})
|
||||
},
|
||||
'POST /post/create': ({ data }) => {
|
||||
if (!data || !data.title) fail('标题不能为空')
|
||||
if (!data.content) fail('内容不能为空')
|
||||
@@ -113,18 +212,25 @@ export const mockRoutes = {
|
||||
let plan = data.plan || (data.paid ? 'single' : 'free')
|
||||
if (plan === 'month' || plan === 'year') fail('发布方式不支持,请先开通会员套餐')
|
||||
|
||||
// 会员折扣率由服务端下发(未下发 / 解析失败时视作 1),金额仍只由服务端计算
|
||||
const discountRate = Number(rule.discountRate) > 0 ? Number(rule.discountRate) : parseDiscountRate(rule.discountText)
|
||||
|
||||
let amount = 0
|
||||
if (rule.mode === 'paid') {
|
||||
if (plan === 'single') {
|
||||
amount = Number(rule.singlePrice)
|
||||
amount = round2(Number(rule.singlePrice) * discountRate)
|
||||
if (![config.constants.PAY_TYPE.WXPAY, config.constants.PAY_TYPE.BALANCE].includes(data.payType)) {
|
||||
fail('支付方式不支持')
|
||||
}
|
||||
} else if (rule.quotaLeft > 0) {
|
||||
rule.quotaLeft -= 1 // 套餐额度内免费发布
|
||||
plan = 'quota'
|
||||
} else if (Number(rule.freePerDay) > Number(rule.freeUsedToday)) {
|
||||
rule.freeUsedToday += 1 // 每日免费额度内免费发布
|
||||
} else if (rule.freeUnlimited || Number(rule.freeQuotaLeft) > 0) {
|
||||
// 免费发布条数内免费发布(freeUnlimited = 不限制,不扣减)
|
||||
if (!rule.freeUnlimited) {
|
||||
rule.freeQuotaUsed = Number(rule.freeQuotaUsed) + 1
|
||||
rule.freeQuotaLeft = Math.max(0, Number(rule.freeQuota) - rule.freeQuotaUsed)
|
||||
}
|
||||
plan = 'free'
|
||||
} else {
|
||||
fail('请选择发布方式')
|
||||
@@ -137,24 +243,30 @@ export const mockRoutes = {
|
||||
? {
|
||||
orderNo: 'PO' + Date.now(),
|
||||
amount,
|
||||
discountRate,
|
||||
payType: data.payType,
|
||||
type: 'post',
|
||||
status: data.payType === config.constants.PAY_TYPE.BALANCE ? 'paid' : 'pending',
|
||||
}
|
||||
: null
|
||||
|
||||
// 落入「我的发布」,供 /post/mine 与全链路测试读取
|
||||
const id = Date.now()
|
||||
const media = Array.isArray(data.media) ? data.media.slice() : []
|
||||
datasets.myPosts.unshift({
|
||||
id,
|
||||
title: data.title,
|
||||
content: data.content,
|
||||
categoryId: Number(data.categoryId) || 1,
|
||||
categoryName: '招聘求职',
|
||||
cover: '',
|
||||
cover: media[0] || '',
|
||||
media,
|
||||
price: Number(data.price) || 0,
|
||||
priceUnit: data.priceUnit || '面议',
|
||||
area: data.area || '',
|
||||
address: data.address || '',
|
||||
lat: data.lat != null && data.lat !== '' ? Number(data.lat) : null,
|
||||
lng: data.lng != null && data.lng !== '' ? Number(data.lng) : null,
|
||||
auditStatus: config.constants.AUDIT.PENDING,
|
||||
auditReason: '',
|
||||
status: 1,
|
||||
@@ -173,12 +285,15 @@ export const mockRoutes = {
|
||||
order,
|
||||
plan,
|
||||
amount,
|
||||
discountRate,
|
||||
quotaLeft: rule.mode === 'paid' ? rule.quotaLeft : 0,
|
||||
})
|
||||
},
|
||||
'GET /post/publish-config': () => {
|
||||
const r = datasets.publishRule
|
||||
return ok({ ...r, freeLeftToday: Math.max(0, Number(r.freePerDay) - Number(r.freeUsedToday)) })
|
||||
// 与后端 Post::publishConfig 出参对齐:freeQuotaLeft(-1 = 不限制)+ discountRate/discountText
|
||||
const freeQuotaLeft = r.freeUnlimited ? -1 : Math.max(0, Number(r.freeQuota) - Number(r.freeQuotaUsed))
|
||||
return ok({ ...r, freeQuotaLeft })
|
||||
},
|
||||
'GET /post/mine': ({ data }) => {
|
||||
const status = (data && data.status) || 'all'
|
||||
@@ -213,11 +328,30 @@ export const mockRoutes = {
|
||||
'GET /post/:id': ({ params }) => {
|
||||
const post = datasets.posts.find((p) => String(p.id) === String(params.id)) || datasets.posts[0]
|
||||
if (!post) fail('信息不存在', 404)
|
||||
return ok(post)
|
||||
const faved = datasets.favorites.some((f) => String(f.postId) === String(post.id))
|
||||
const publisherId = post.publisher && post.publisher.id
|
||||
const followed = !!publisherId && datasets.follows.some((f) => String(f.targetUserId) === String(publisherId))
|
||||
// 契约 §2.1:详情出参新增 lat/lng/faved/followed/favoriteCount
|
||||
const favoriteCount = datasets.favorites.filter((f) => String(f.postId) === String(post.id)).length
|
||||
return ok({
|
||||
...post,
|
||||
lat: post.lat != null ? Number(post.lat) : null,
|
||||
lng: post.lng != null ? Number(post.lng) : null,
|
||||
faved,
|
||||
followed,
|
||||
favoriteCount,
|
||||
})
|
||||
},
|
||||
'POST /post/:id/pay-view': ({ data }) => {
|
||||
const pt = data && data.payType
|
||||
if (![config.constants.PAY_TYPE.WXPAY, config.constants.PAY_TYPE.BALANCE].includes(pt)) fail('支付方式不支持')
|
||||
// 与后端 Post::payView 对齐:wxpay 只返回待支付订单(**不含 contact**,解锁由 /pay/notify 回调写 fc_pay_view 后
|
||||
// 再调本接口才拿到 unlocked+contact);余额/会员免费才同步返回 unlocked+contact
|
||||
if (pt === config.constants.PAY_TYPE.WXPAY) {
|
||||
return ok({
|
||||
order: { orderNo: 'VO' + Date.now(), amount: 2, payType: pt, type: 'payview', status: 'pending' },
|
||||
})
|
||||
}
|
||||
return ok({ unlocked: true, contact: datasets.secretContact })
|
||||
},
|
||||
'POST /post/:id/comment': ({ data }) => {
|
||||
@@ -248,7 +382,148 @@ export const mockRoutes = {
|
||||
})
|
||||
},
|
||||
'GET /member/orders': ({ data }) => ok(paginate(datasets.orders, data && data.page, data && data.size)),
|
||||
'GET /member/assets': () => ok(datasets.assets),
|
||||
'GET /member/assets': () => {
|
||||
// coupons 来自 fc_user_coupon + fc_coupon(字段与后端一致);couponCount 供「我的资产」直接展示
|
||||
const coupons = buildUserCoupons()
|
||||
return ok({ ...datasets.assets, coupons, couponCount: coupons.length })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 收藏与关注 ====================
|
||||
'GET /favorite/list': ({ data }) => {
|
||||
const list = datasets.favorites
|
||||
.map((f) => datasets.posts.find((p) => String(p.id) === String(f.postId)))
|
||||
.filter(Boolean)
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'POST /favorite/toggle': ({ data }) => {
|
||||
const postId = Number(data && data.postId)
|
||||
if (!postId) fail('缺少信息 ID')
|
||||
const idx = datasets.favorites.findIndex((f) => String(f.postId) === String(postId))
|
||||
let faved
|
||||
if (idx > -1) {
|
||||
datasets.favorites.splice(idx, 1)
|
||||
faved = false
|
||||
} else {
|
||||
datasets.favorites.unshift({ id: Date.now(), postId, createtime: new Date().toISOString() })
|
||||
faved = true
|
||||
}
|
||||
return ok({ faved, count: datasets.favorites.length })
|
||||
},
|
||||
'POST /follow/toggle': ({ data }) => {
|
||||
const userId = Number(data && data.userId)
|
||||
if (!userId) fail('缺少用户 ID')
|
||||
const idx = datasets.follows.findIndex((f) => String(f.targetUserId) === String(userId))
|
||||
let followed
|
||||
if (idx > -1) {
|
||||
datasets.follows.splice(idx, 1)
|
||||
followed = false
|
||||
} else {
|
||||
datasets.follows.push({ id: Date.now(), targetUserId: userId, createtime: new Date().toISOString() })
|
||||
followed = true
|
||||
}
|
||||
return ok({ followed })
|
||||
},
|
||||
'POST /favorite/status': ({ data }) => {
|
||||
const postIds = (data && data.postIds) || []
|
||||
const userIds = (data && data.userIds) || []
|
||||
const faved = {}
|
||||
const followed = {}
|
||||
postIds.forEach((id) => {
|
||||
faved[id] = datasets.favorites.some((f) => String(f.postId) === String(id))
|
||||
})
|
||||
userIds.forEach((id) => {
|
||||
followed[id] = datasets.follows.some((f) => String(f.targetUserId) === String(id))
|
||||
})
|
||||
return ok({ faved, followed })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 举报 ====================
|
||||
'POST /report': ({ data }) => {
|
||||
if (!data || !data.targetType) fail('缺少举报对象类型')
|
||||
if (!['post', 'comment'].includes(data.targetType)) fail('举报对象类型不合法')
|
||||
if (!data.targetId) fail('缺少举报对象')
|
||||
if (!data.reason) fail('请选择举报原因')
|
||||
const id = Date.now()
|
||||
datasets.reports.unshift({
|
||||
id,
|
||||
targetType: data.targetType,
|
||||
targetId: Number(data.targetId),
|
||||
reason: data.reason,
|
||||
detail: data.detail || '',
|
||||
reporter: String(datasets.user.id),
|
||||
status: 'pending',
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
return ok({ reportId: id })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 余额充值 与 微信支付 ====================
|
||||
'POST /order/recharge': ({ data }) => {
|
||||
const amount = round2(data && data.amount)
|
||||
// 与后端 application/api/controller/Order::recharge 对齐:金额 0/超限同一文案;
|
||||
// 充值只允许微信支付(balance = 用余额给余额加钱,属资损,后端已禁止)
|
||||
if (!amount || amount <= 0 || amount > 100000) fail('充值金额不合法')
|
||||
const payType = data && data.payType
|
||||
if (payType === config.constants.PAY_TYPE.BALANCE) fail('余额充值仅支持微信支付')
|
||||
if (payType !== config.constants.PAY_TYPE.WXPAY) fail('支付方式不支持')
|
||||
|
||||
const orderNo = 'RO' + Date.now()
|
||||
datasets.orders.unshift({
|
||||
id: Date.now(),
|
||||
orderNo,
|
||||
type: 'recharge',
|
||||
title: '余额充值',
|
||||
amount,
|
||||
payType,
|
||||
status: 'pending',
|
||||
createdAt: new Date().toISOString(),
|
||||
})
|
||||
return ok({ orderNo, amount, status: 'pending', payType })
|
||||
},
|
||||
'POST /pay/prepay': ({ data }) => {
|
||||
const orderNo = data && data.orderNo
|
||||
if (!orderNo) fail('缺少订单号')
|
||||
if (!datasets.wxPayConfigured) fail('微信支付未配置')
|
||||
return ok({
|
||||
orderNo,
|
||||
payType: config.constants.PAY_TYPE.WXPAY,
|
||||
payParams: {
|
||||
timeStamp: String(Math.floor(Date.now() / 1000)),
|
||||
nonceStr: 'mocknonce' + Date.now(),
|
||||
package: 'prepay_id=mock_prepay_' + orderNo,
|
||||
signType: 'MD5',
|
||||
paySign: 'MOCKSIGN',
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 优惠券 ====================
|
||||
'GET /coupon/list': ({ data }) => {
|
||||
const receivedIds = datasets.userCoupons.map((u) => u.couponId)
|
||||
const list = datasets.coupons
|
||||
.filter((c) => c.enabled)
|
||||
.sort((a, b) => (a.sort || 0) - (b.sort || 0))
|
||||
.map((c) => ({ ...c, received: receivedIds.includes(c.id) }))
|
||||
return ok(paginate(list, data && data.page, data && data.size))
|
||||
},
|
||||
'POST /coupon/receive': ({ data }) => {
|
||||
const couponId = Number(data && data.couponId)
|
||||
const coupon = datasets.coupons.find((c) => c.id === couponId)
|
||||
if (!coupon) fail('优惠券不存在')
|
||||
if (!coupon.enabled) fail('该优惠券已停止发放')
|
||||
if (datasets.userCoupons.some((u) => u.couponId === couponId)) fail('您已领取过该优惠券')
|
||||
const id = Date.now()
|
||||
datasets.userCoupons.push({
|
||||
id,
|
||||
couponId,
|
||||
status: 'unused',
|
||||
orderNo: '',
|
||||
usetime: '',
|
||||
expiretime: new Date(Date.now() + (Number(coupon.days) || 30) * 86400000).toISOString(),
|
||||
createtime: new Date().toISOString(),
|
||||
})
|
||||
return ok({ userCouponId: id })
|
||||
},
|
||||
|
||||
// ==================== 用户端 · 分销中心 ====================
|
||||
'GET /distribution/overview': () => ok(datasets.distOverview),
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
* 格式化工具集
|
||||
*/
|
||||
|
||||
import config from '../config/index.js'
|
||||
|
||||
/** 金额分转元 */
|
||||
export function fen2yuan(fen) {
|
||||
return (Number(fen || 0) / 100).toFixed(2)
|
||||
@@ -56,4 +58,40 @@ export function formatDistance(meters) {
|
||||
return `${(m / 1000).toFixed(1)}km`
|
||||
}
|
||||
|
||||
export default { fen2yuan, yuan2fen, formatTime, fromNow, maskPhone, formatDistance }
|
||||
/**
|
||||
* 距离格式化(千米,一位小数)
|
||||
* 契约 §2.1:feed / 详情下发的 distance 单位为 km(一位小数),无坐标时为 null。
|
||||
*/
|
||||
export function formatKm(km) {
|
||||
if (km === null || km === undefined || km === '') return ''
|
||||
const n = Number(km)
|
||||
if (isNaN(n)) return ''
|
||||
return `${n.toFixed(1)}km`
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源地址:后端统一返回**相对路径**(/uploads/YYYYMMDD/xxx.jpg,与用户头像口径一致),
|
||||
* 小程序 `<image src="/uploads/...">` 会被当成包内路径而裂图,因此展示前必须拼上后端域名。
|
||||
* 已是 http(s)/data/blob 的地址原样返回。
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
export function assetUrl(url) {
|
||||
const s = String(url == null ? '' : url)
|
||||
if (!s) return ''
|
||||
if (/^(https?:)?\/\//i.test(s) || /^(data|blob):/i.test(s)) return s
|
||||
// config.baseURL 形如 https://host/api,这里只取域名部分(uploads 挂在站点根目录)
|
||||
const origin = String(config.baseURL || '').replace(/^(https?:\/\/[^/]+).*$/i, '$1')
|
||||
return origin + (s.charAt(0) === '/' ? s : '/' + s)
|
||||
}
|
||||
|
||||
export default {
|
||||
fen2yuan,
|
||||
yuan2fen,
|
||||
formatTime,
|
||||
fromNow,
|
||||
maskPhone,
|
||||
formatDistance,
|
||||
formatKm,
|
||||
assetUrl,
|
||||
}
|
||||
|
||||
@@ -1,37 +1,65 @@
|
||||
/**
|
||||
* 统一支付封装
|
||||
* 支持:微信支付(uni.requestPayment)/ 余额支付(服务端直接扣减)
|
||||
* 统一支付封装(所有支付点必须走这里,页面不直接调 /pay/prepay)
|
||||
*
|
||||
* 语义:
|
||||
* · 余额支付 balance —— 服务端下单即扣款(订单直接 paid),前端只需确认成功;
|
||||
* · 微信支付 wxpay —— 先 POST /pay/prepay 拿 JSAPI 调起参数,再 uni.requestPayment;
|
||||
* 未配置商户参数 / 下单失败时给出中文提示。
|
||||
*/
|
||||
import config from '../config/index.js'
|
||||
import payApi from '../api/pay.js'
|
||||
|
||||
function toErr(message, code = 'PAY_FAIL') {
|
||||
const e = new Error(message)
|
||||
e.code = code
|
||||
return e
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param {Object} order 订单信息 { orderNo, amount, payType }
|
||||
* @returns {Promise<{success:boolean, payType:string, orderNo:string}>}
|
||||
* @param {Object} order 订单信息 { orderNo, amount, payType, payParams? }
|
||||
* @returns {Promise<{success:boolean,payType:string,orderNo:string,mock?:boolean}>}
|
||||
*/
|
||||
export function pay(order = {}) {
|
||||
const payType = order.payType || config.constants.PAY_TYPE.WXPAY
|
||||
const orderNo = order.orderNo || ''
|
||||
|
||||
// 余额支付:直接调用服务端确认接口(此处由调用方传入回调)
|
||||
// 余额支付:服务端已即时扣款,无需收银台
|
||||
if (payType === config.constants.PAY_TYPE.BALANCE) {
|
||||
return Promise.resolve({ success: true, payType, orderNo: order.orderNo })
|
||||
return Promise.resolve({ success: true, payType, orderNo })
|
||||
}
|
||||
|
||||
// 微信支付
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof uni === 'undefined' || !uni.requestPayment) {
|
||||
// 非小程序环境(如 H5/测试)直接视为成功,便于联调
|
||||
return resolve({ success: true, payType, orderNo: order.orderNo, mock: true })
|
||||
}
|
||||
uni.requestPayment({
|
||||
// 微信支付:先拿调起参数(已在订单里带上 payParams 时直接复用)
|
||||
const fetchPayParams = () => {
|
||||
if (order.payParams) return Promise.resolve(order.payParams)
|
||||
if (!orderNo) return Promise.reject(toErr('缺少订单号,无法发起微信支付'))
|
||||
return payApi.prepay({ orderNo }).then((res) => {
|
||||
const params = res && res.payParams
|
||||
if (!params) throw toErr('微信支付未配置')
|
||||
return params
|
||||
})
|
||||
}
|
||||
|
||||
return fetchPayParams().then((payParams) => {
|
||||
const params = {
|
||||
provider: 'wxpay',
|
||||
timeStamp: order.timeStamp,
|
||||
nonceStr: order.nonceStr,
|
||||
package: order.package,
|
||||
signType: order.signType || 'RSA',
|
||||
paySign: order.paySign,
|
||||
success: () => resolve({ success: true, payType, orderNo: order.orderNo }),
|
||||
fail: (err) => reject(Object.assign(new Error('支付已取消'), { raw: err, code: 'PAY_CANCEL' })),
|
||||
timeStamp: String(payParams.timeStamp || ''),
|
||||
nonceStr: payParams.nonceStr || '',
|
||||
package: payParams.package || '',
|
||||
// JSAPI v2 默认 MD5;若服务端下发 signType 以服务端为准
|
||||
signType: payParams.signType || 'MD5',
|
||||
paySign: payParams.paySign || '',
|
||||
}
|
||||
if (typeof uni === 'undefined' || !uni.requestPayment) {
|
||||
// H5 / Node 测试环境:视为支付成功,便于离线联调
|
||||
return { success: true, payType, orderNo, mock: true, payParams: params }
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.requestPayment({
|
||||
...params,
|
||||
success: () => resolve({ success: true, payType, orderNo }),
|
||||
fail: (err) => reject(Object.assign(new Error('支付已取消'), { raw: err, code: 'PAY_CANCEL' })),
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户