Browse Source

测试 easy 5.0, 设置Redis 缓存

liuzejian 1 year ago
parent
commit
d9598397fb

+ 2 - 8
app/Service/WechatPlatform/GZHSendKFMessageService.php

@@ -19,14 +19,8 @@ class GZHSendKFMessageService
      */
     public static function sendText($officialAccount, $openid, $content, $traceContext) {
         try {
-            $officialAccount->getClient()
-                ->postJson('cgi-bin/message/custom/send',  [
-                    'touser' => $openid,
-                    'msgtype' => 'text',
-                    'text' => [
-                        'content' => $content
-                    ]
-                ])->toArray();
+            $officialAccount->customer_service->message($content)
+                ->to($openid)->send();
             return true;
         } catch (\Throwable $exception) {
             myLog('KFMessageSend')->error('发送客服消息失败', [

+ 5 - 9
app/Service/WechatPlatform/WechatPlatform.php

@@ -2,6 +2,7 @@
 
 namespace App\Service\WechatPlatform;
 
+use EasyWeChat\Factory;
 use EasyWeChat\OpenPlatform\Application;
 use Illuminate\Support\Facades\Cache;
 
@@ -13,14 +14,10 @@ class WechatPlatform
             'secret' => $componentInfo->secret,   // 开放平台账号的 secret
             'token' => $componentInfo->token,  // 开放平台账号的 token
             'aes_key' => $componentInfo->aes_key,   // 明文模式请勿填写 EncodingAESKey
-            'http' => [
-                'throw'  => true, // 状态码非 200、300 时是否抛出异常,默认为开启
-                'timeout' => 5.0,
-                'retry' => true, // 使用默认重试配置
-            ],
         ];
-        $app = new Application($config);
-        $app->setCache(Cache::store('redis'));
+
+        $app = Factory::openPlatform(array_merge($config, config('easywechat')));
+        $app->rebind('cache',Cache::store('redis'));
         return $app;
     }
 
@@ -31,7 +28,6 @@ class WechatPlatform
      * @return \EasyWeChat\OfficialAccount\Application
      */
     public static function officialAccount($app, $appid, $refreshToken) {
-
-        return $app->getOfficialAccountWithRefreshToken($appid, $refreshToken);
+        return $app->officialAccount($appid, $refreshToken);
     }
 }

+ 23 - 0
config/easywechat.php

@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * easywechat 5.0 公共配置
+ */
+return [
+    'response_type' => 'array',
+    'http' => [
+        'throw'  => true, // 状态码非 200、300 时是否抛出异常,默认为开启
+        'timeout' => 5.0,
+        'retry' => true, // 使用默认重试配置
+    ],
+    'log' => [
+        'default' => 'prod',
+        'channels' => [
+            'prod' => [
+                'driver' => 'daily',
+                'path' => storage_path('logs/easyWechat.log'),
+                'level' => env('EASY_WECHAT_LOG_LEVEL', 'debug'),
+            ]
+        ]
+    ]
+];