zilong 4 년 전
부모
커밋
d9760a1f54
1개의 변경된 파일21개의 추가작업 그리고 17개의 파일을 삭제
  1. 21 17
      app/Helpers/functions.php

+ 21 - 17
app/Helpers/functions.php

xqd
@@ -577,24 +577,28 @@ if (!function_exists('send_wechat_message')) {
             }
             $json = vsprintf($json, $official_arr);
             $data = json_decode($json, true);
-            $ret = $app->uniform_message->send($data);
-            if (empty($subscribe_arr) && (!isset($ret['errcode']) || $ret['errcode'] != 0)) {
-                trace(['发送微信模板消息失败,请求参数' => $data, '返回数据' => $ret], 'error');
-            }
-            //如果模板消息发送失败(可能因用户没有关注公众号而失败)再发送订阅消息
-            if (!empty($subscribe_arr) && isset($ret['errcode']) && $ret['errcode'] != 0) {
-                $data = config('config.wechat_subscribe_message_template')[$type];
-                $json = json_encode($data, JSON_UNESCAPED_UNICODE);
-                foreach ($subscribe_arr as $k => &$v) {
-                    $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
-                    $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t","\\f", "\\b");
-                    $v = str_replace($escapers, $replacements, $v);
+            if (empty($data) || !is_array($data)) {
+                $ret = $app->uniform_message->send($data);
+                if (empty($subscribe_arr) && (!isset($ret['errcode']) || $ret['errcode'] != 0)) {
+                    trace(['发送微信模板消息失败,请求参数' => $data, '返回数据' => $ret], 'error');
                 }
-                $json = vsprintf($json, $subscribe_arr);
-                $data = json_decode($json, true);
-                $ret = $app->subscribe_message->send($data);
-                if (isset($ret['errcode']) && $ret['errcode'] != 0) {
-                    trace(['发送微信订阅消息失败,请求参数' => $data ?? '', '返回数据' => $ret ?? ''], 'error');
+                //如果模板消息发送失败(可能因用户没有关注公众号而失败)再发送订阅消息
+                if (!empty($subscribe_arr) && isset($ret['errcode']) && $ret['errcode'] != 0) {
+                    $data = config('config.wechat_subscribe_message_template')[$type];
+                    $json = json_encode($data, JSON_UNESCAPED_UNICODE);
+                    foreach ($subscribe_arr as $k => &$v) {
+                        $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
+                        $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t","\\f", "\\b");
+                        $v = str_replace($escapers, $replacements, $v);
+                    }
+                    $json = vsprintf($json, $subscribe_arr);
+                    $data = json_decode($json, true);
+                    if (!empty($data) && is_array($data)) {
+                        $ret = $app->subscribe_message->send($data);
+                        if (isset($ret['errcode']) && $ret['errcode'] != 0) {
+                            trace(['发送微信订阅消息失败,请求参数' => $data ?? '', '返回数据' => $ret ?? ''], 'error');
+                        }
+                    }
                 }
             }
         } catch (Exception $e) {