- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
76 行
2.4 KiB
PHP
76 行
2.4 KiB
PHP
<?php
|
||
|
||
namespace app\common\library;
|
||
|
||
use think\Db;
|
||
use think\Log;
|
||
|
||
/**
|
||
* 微信小程序订阅消息
|
||
*
|
||
* 配置(fa_fc_config,后台「系统配置 → 小程序配置」):
|
||
* wx.tplAudit 审核结果通知模板 ID
|
||
* wx.tplTransfer 提现到账通知模板 ID
|
||
*
|
||
* 说明:
|
||
* - 模板字段名由微信侧模板决定,调用方传入的 data 需与模板一致;
|
||
* - 用户未授权 / 模板未配置 / openid 非真实微信用户时静默跳过(不影响主流程);
|
||
* - 发送失败只记日志,绝不阻断支付/审核等业务。
|
||
*/
|
||
class WxSubscribe
|
||
{
|
||
/** 场景 → 配置键 */
|
||
const SCENES = [
|
||
'audit' => 'wx.tplAudit',
|
||
'transfer' => 'wx.tplTransfer',
|
||
];
|
||
|
||
/**
|
||
* 发送订阅消息
|
||
*
|
||
* @param int $userId
|
||
* @param string $scene audit | transfer
|
||
* @param array $data ['thing1' => '...', 'phrase2' => '...']
|
||
* @param string $page 点击消息跳转的小程序页面
|
||
* @return bool
|
||
*/
|
||
public static function send($userId, $scene, array $data, $page = 'pages/index/index')
|
||
{
|
||
if (!isset(self::SCENES[$scene]) || !WxMini::isConfigured()) {
|
||
return false;
|
||
}
|
||
|
||
$tpl = trim((string)WxMini::config(self::SCENES[$scene], ''));
|
||
if ($tpl === '') {
|
||
return false;
|
||
}
|
||
|
||
$ext = Db::name('fc_user_ext')->where('user_id', (int)$userId)->find();
|
||
$openid = $ext ? trim((string)$ext['openid']) : '';
|
||
// 派生 openid(本地联调/h5)不是真实微信用户,发不出去
|
||
if ($openid === '' || strpos($openid, 'openid_') === 0 || strpos($openid, 'h5_') === 0) {
|
||
return false;
|
||
}
|
||
|
||
try {
|
||
$res = WxMini::app()->subscribe_message->send([
|
||
'touser' => $openid,
|
||
'template_id' => $tpl,
|
||
'page' => $page,
|
||
'data' => $data,
|
||
]);
|
||
} catch (\Throwable $e) {
|
||
Log::record('订阅消息发送异常:' . $e->getMessage(), 'error');
|
||
return false;
|
||
}
|
||
|
||
$arr = $res instanceof \EasyWeChat\Kernel\Support\Collection ? $res->all() : (array)$res;
|
||
if (isset($arr['errcode']) && (int)$arr['errcode'] !== 0) {
|
||
Log::record('订阅消息发送失败:' . json_encode($arr, JSON_UNESCAPED_UNICODE), 'error');
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|