zilong 4 лет назад
Родитель
Сommit
e440026a13
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      app/Helpers/functions.php

+ 10 - 0
app/Helpers/functions.php

xqd xqd
@@ -570,6 +570,11 @@ if (!function_exists('send_wechat_message')) {
             //先发送模板消息
             $data = config('config.wechat_official_message_template')[$type];
             $json = json_encode($data, JSON_UNESCAPED_UNICODE);
+            foreach ($official_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, $official_arr);
             $data = json_decode($json, true);
             $ret = $app->uniform_message->send($data);
@@ -580,6 +585,11 @@ if (!function_exists('send_wechat_message')) {
             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);
                 $ret = $app->subscribe_message->send($data);