소스 검색

增加公共方法加解密emoji

lh 3 년 전
부모
커밋
ca8bc4f79d
2개의 변경된 파일35개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 4
      app/Console/Commands/Test.php
  2. 31 0
      app/Libs/functions/Helpers.php

+ 4 - 4
app/Console/Commands/Test.php

@@ -31,10 +31,10 @@ class Test extends Command
      */
     public function handle()
     {
-        $data = DB::connection('api_mysql')->table('official_accounts')->select('distribution_channel_id', 'nickname', 'name', 'head_img', 'appid', 'appsecret', 'verify_txt', 'alias', 'qrcode_url', 'principal_name', 'service_type_info', 'func_info', 'authorizer_refresh_token', 'is_auth', 'cancel_auth_time', 'official_account_type', 'verify_type_info', 'subscribe_top_num', 'subscribe_day_maximum', 'sort_no', 'is_enabled')->where('appid', 'wxebcb86ec4b80eaca')->first();
-        $data = (array)$data;
-        Log::info('official_accounts_info: '.json_encode($data));
-        Redis::hset('official_account_info:app_id:wxebcb86ec4b80eaca', 'official_account_info', json_encode($data));
+//        $data = DB::connection('api_mysql')->table('official_accounts')->select('distribution_channel_id', 'nickname', 'name', 'head_img', 'appid', 'appsecret', 'verify_txt', 'alias', 'qrcode_url', 'principal_name', 'service_type_info', 'func_info', 'authorizer_refresh_token', 'is_auth', 'cancel_auth_time', 'official_account_type', 'verify_type_info', 'subscribe_top_num', 'subscribe_day_maximum', 'sort_no', 'is_enabled')->where('appid', 'wxebcb86ec4b80eaca')->first();
+//        $data = (array)$data;
+//        Log::info('official_accounts_info: '.json_encode($data));
+//        Redis::hset('official_account_info:app_id:wxebcb86ec4b80eaca', 'official_account_info', json_encode($data));
 
 //        $books = \App\Modules\Book\Services\BookConfigService::getBookByRole('叶安');
 //        dd($books);

+ 31 - 0
app/Libs/functions/Helpers.php

@@ -483,3 +483,34 @@ function getProp($param, $key, $default = '')
 
     return $result;
 }
+
+//把用户输入的文本转义(主要针对特殊符号和emoji表情)
+function textEncode($str)
+{
+    if (!is_string($str)) return $str;
+    if ($str === '0') return '0';
+    if (!$str || $str == 'undefined') return '';
+    $text = json_encode($str); //暴露出unicode
+    return $text;
+    $text = preg_replace_callback("/(\\\u[2edf][0-9a-f]{3})/i", function ($str) {
+        return addslashes($str[0]);
+    }, $text); //将emoji的unicode留下,其他不变
+    return json_decode($text);
+}
+
+//解码上面的转义
+function textDecode($str)
+{
+    if (is_null(json_decode($str))) return $str;
+    return json_decode($str);
+    $text = json_encode($str); //暴露出unicode
+    $text = preg_replace_callback('/\\\\\\\\/i', function ($str) {
+        return '\\';
+    }, $text); //将两条斜杠变成一条,其他不变
+//    return json_decode($text);
+    $text = json_decode($text);
+    if (strstr($text, ''')) {
+        $text = str_replace(''', '\'', $text);
+    }
+    return $text;
+}