feat: 初始化雄戈商城服务端代码与Webhook自动部署配置

这个提交包含在:
wikiboss
2026-09-12 16:40:24 +08:00
当前提交 e90ec58e61
共有 6438 个文件被更改,包括 1136083 次插入 和 0 次删除

查看文件

@@ -0,0 +1,58 @@
<?php
namespace addons\shopro\library\notify\channel;
use addons\shopro\notifications\Notification;
class WxMiniProgram
{
public function __construct()
{
}
/**
* 发送 微信模板消息
*
* @param mixed $notifiable // 通知用户
* @param 通知内容
* @return void
*/
public function send($notifiable, Notification $notification)
{
$data = [];
if (method_exists($notification, 'toWxMiniProgram')) {
$data = $notification->toWxMiniProgram($notifiable);
if ($data && isset($data['openid']) && isset($data['template_id']) && $data['template_id']) {
$data['touser'] = $data['openid'];
unset($data['openid']);
try {
// 发送模板消息
$result = (new \addons\shopro\library\Wechat('wxMiniProgram'))->getApp()->subscribe_message->send($data);
if ($result['errcode'] != 0) {
// 小程序模板发送失败
\think\Log::write('小程序模板消息发送失败:用户:'. $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event . ";错误信息:" . json_encode($result));
} else {
// 发送成功
$notification->sendOk('wxMiniProgram');
}
} catch (\Exception $e) {
// 因为配置较麻烦,这里捕获异常防止因为缺少字段,导致队列一直执行不成功
\think\Log::write('小程序模板消息发送失败:用户:' . $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event . ";错误信息:" . $e->getMessage());
}
return true;
}
// 没有openid
\think\Log::write('小程序模板消息发送失败,没有 openid:用户:' . $notifiable['id'] . ';类型:' . get_class($notification) . ";发送类型:" . $notification->event);
}
return true;
}
}