Bläddra i källkod

[智价云] 订阅推送日志补充

tangyuanwang 1 vecka sedan
förälder
incheckning
5f72224ab1
1 ändrade filer med 16 tillägg och 14 borttagningar
  1. 16 14
      app/Servers/Wechat/Official.php

+ 16 - 14
app/Servers/Wechat/Official.php

@@ -3,6 +3,7 @@
 namespace App\Servers\Wechat;
 
 use EasyWeChat\Factory;
+use App\Facades\Servers\Logs\Log;
 
 /**
  * 微信公众号
@@ -70,19 +71,22 @@ class Official
      */
     public function sendSubscription($params)
     {
-
-        $result    = $this->app->template_message->sendSubscription([
-            'touser' => $params['openid'],
-            'template_id' => 'template-id',
-            'miniprogram' => $params['miniprogram'],
-            'scene' => 1000,
-            'data' => $params['data'],
-        ]);
-        // 判断结果
-        if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
-        // 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
-        return                              $result;
+        try {
+            $result    = $this->app->template_message->sendSubscription([
+                'touser' => $params['openid'],
+                'template_id' => 'template-id',
+                'miniprogram' => $params['miniprogram'],
+                'scene' => 1000,
+                'data' => $params['data'],
+            ]);
+            // 判断结果
+            if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
+            return                              $result;
+        } catch (\Exception $e) {
+            Log::info('wechat_subscribe_error', '订阅消息通知推送队列失败', ['data' => $params, 'error' => $e->getMessage()]);
+        }
     }
+
     /**
      * 发送模板消息
      * @param array $params
@@ -90,7 +94,6 @@ class Official
      */
     public function send($params)
     {
-        // 获取手机号
         $result                                = $this->app->template_message->send([
             'touser' => $params['openid'],
             'template_id' => 'template-id',
@@ -100,7 +103,6 @@ class Official
         ]);
         // 判断结果
         if (!empty($result['errcode']))    return ['error' => $result['errcode'] . '=>' . $result['errmsg']];
-        // 获取不包含区号的手机号(因为绑定手机号字段会有国际区号)
         return                              $result;
     }
 }