Browse Source

测试获取所有用户openid

liuzejian 1 year ago
parent
commit
d650f8144a

+ 6 - 20
app/Console/Commands/WechatPlatform/Test.php

@@ -33,27 +33,13 @@ class Test extends Command
      */
     public function handle()
     {
-        $config = [
-            'app_id' => 'wxf313b3506bac2647',
-            'secret' => 'aaf348571cbc5d554e4de1bcd3cb0342',
-            'token' => 'jXP3Cdl6GofhWVsQTtgwLv2tMZG9nHlPgErZm6ixaSl',
-            'aes_key' => 'GtG7s1v7QV8kRfpWeGmDnwhwdPPKSrA35rIhmrwenpq',
-            'http' => [
-                'max_retries' => 1,
-                'retry_delay' => 500,
-                'timeout' => 5.0,
-            ],
+        $info = [
+            'gzhId' => 8,
+            'messageId' => 6,
+            'traceInfo' => (new TraceContext())->getTraceInfo()
         ];
-        $openPlatform = Factory::openPlatform($config);
-        $openPlatform->rebind('cache', Cache::store('redis'));
+        $skf = new GZHSendKFMessage($info);
 
-        $officialAccount = $openPlatform->officialAccount('wxebcb86ec4b80eaca',
-            'refreshtoken@@@pOdN-RBZ1f475kZxXM66IcG2keHkv8V0mDs97JYa2TQ');
-
-        $text = new Text('kkkkkk');
-        $res = $officialAccount->customer_service->message($text)
-            ->to('oHhd20dzCcfVjWt4OcGzFWISp6A4')
-            ->send();
-        dump($res);
+        $skf->handle();
     }
 }

+ 5 - 2
app/Jobs/WechatPlatform/GZHSendKFMessage.php

@@ -86,7 +86,8 @@ class GZHSendKFMessage implements ShouldQueue
                 if(1 == $message->u_type) {
                     $info = $this->getUserOpenids($officialAccount, $next_openid);
                     foreach ($info['openid'] as $opid){
-                        GZHSendKFMessageService::sendText($officialAccount, $opid, $messageStr, $this->traceContext);
+//                        GZHSendKFMessageService::sendText($officialAccount, $opid, $messageStr, $this->traceContext);
+                        dump($opid);
                     }
                     $next_openid = $info['next_openid'];
                     if(!$next_openid) {
@@ -131,6 +132,8 @@ class GZHSendKFMessage implements ShouldQueue
                     'next_openid' => $next_openid,
                 ]
             ])->toArray();
+        $result = $officialAccount->user->list($next_openid);
+
         if(0 != ($result['errcode'] ?? 0)) {
             return false;
         }
@@ -154,7 +157,7 @@ class GZHSendKFMessage implements ShouldQueue
     private function getOfficialAccount($gzh) {
         try{
             return WechatPlatform::buildApplication($gzh)
-                ->getOfficialAccountWithRefreshToken($gzh->authorizer_appid, $gzh->authorizer_refresh_token);
+                ->officialAccount($gzh->authorizer_appid, $gzh->authorizer_refresh_token);
         } catch (\Throwable $exception) {
             myLog('KFMessageSend')->error('获取公众号调用对象失败', [
                 'exceptionMessage' => $exception->getMessage(),

+ 23 - 0
tests/Jobs/WechatPlatform/GZHSendKFMessageTest.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Tests\Jobs\WechatPlatform;
+
+use App\Jobs\WechatPlatform\GZHSendKFMessage;
+use App\Service\Util\Support\Trace\TraceContext;
+use PHPUnit\Framework\TestCase;
+
+class GZHSendKFMessageTest extends \Tests\TestCase
+{
+
+    public function testHandle()
+    {
+        $info = [
+            'gzhId' => 8,
+            'messageId' => 6,
+            'traceInfo' => (new TraceContext())->getTraceInfo()
+        ];
+        $skf = new GZHSendKFMessage($info);
+
+        $skf->handle();
+    }
+}