فهرست منبع

Merge branch 'liuzj-1001016-dev' into test

liuzejian 1 سال پیش
والد
کامیت
118e30bdd7
2فایلهای تغییر یافته به همراه46 افزوده شده و 4 حذف شده
  1. 39 4
      app/Jobs/WechatPlatform/GZHSendKFMessage.php
  2. 7 0
      config/wechat.php

+ 39 - 4
app/Jobs/WechatPlatform/GZHSendKFMessage.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs\WechatPlatform;
 
+use App\Service\Util\Support\Http\HttpRequestService;
 use App\Service\Util\Support\Trace\TraceContext;
 use App\Service\WechatPlatform\GZHSendKFMessageService;
 use App\Service\WechatPlatform\WechatPlatform;
@@ -89,12 +90,20 @@ class GZHSendKFMessage implements ShouldQueue
 //                        GZHSendKFMessageService::sendText($officialAccount, $opid, $messageStr, $this->traceContext);
                         dump($opid);
                     }
-                    $next_openid = $info['next_openid'];
+                    $next_openid = $info['next_openid'] ?? '';
                     if(!$next_openid) {
                         break;
                     }
                 } elseif (2 == $message->u_type) {
-                    // todo, 从人群包中获取.
+                    $info = $this->getUsersFromUG($gzh->id, $message->ug_id,  $next_openid);
+                    foreach (($info['data']['openid'] ?? []) as $opid) {
+                        //                        GZHSendKFMessageService::sendText($officialAccount, $opid, $messageStr, $this->traceContext);
+                        dump($opid);
+                    }
+                    $next_openid = $info['data']['next_uid'] ?? '';
+                    if(!$next_openid) {
+                        break;
+                    }
                 }
             }
         }
@@ -122,7 +131,7 @@ class GZHSendKFMessage implements ShouldQueue
     }
 
     /**
-     *
+     * 拉取公众号粉丝
      * @param $officialAccount Application
      */
     private function getUserOpenids($officialAccount, $next_openid) {
@@ -135,6 +144,31 @@ class GZHSendKFMessage implements ShouldQueue
     }
 
     /**
+     * 通过用户分群获取
+     * @param $gzhId
+     * @param $ugId
+     * @param $nextUid
+     * @return false|mixed
+     */
+    private function getUsersFromUG($gzhId, $ugId,  $nextUid) {
+        $url = config('wechat.ug.url.listUser');
+        $signKey = config('wechat.ug.signKey');
+        $now = time();
+        $res = HttpRequestService::simpleGet($url, [
+            'timestamp' => $now,
+            'sign' => md5($signKey.$now),
+            'gzhId' => $gzhId,
+            'ugId' => $ugId,
+            'nextUid' => $nextUid,
+            'limit' => 1000
+        ]);
+        if($res && (0 != ($res['code'] ?? 0))) {
+            return $res;
+        }
+        return false;
+    }
+
+    /**
      * 获取公众号调用对象
      * @param $gzh
      * @return \EasyWeChat\OfficialAccount\Application
@@ -168,7 +202,8 @@ class GZHSendKFMessage implements ShouldQueue
                 ['a.id', '=', $this->info['gzhId']],
                 ['a.is_enabled', '=', 1],
                 ['b.is_enabled', '=', 1]
-            ])->select('a.authorizer_appid', 'a.authorizer_refresh_token', 'b.app_id', 'b.secret', 'b.token', 'b.aes_key')
+            ])->select('a.id', 'a.authorizer_appid', 'a.authorizer_refresh_token',
+                'b.app_id', 'b.secret', 'b.token', 'b.aes_key')
             ->first();
         if(!$gzh) {
             myLog('KFMessageSend')->error('公众号不可用', [

+ 7 - 0
config/wechat.php

@@ -4,5 +4,12 @@ return [
     'duanju' => [
         // 短剧主小程序
         'masterAppid' => env('WECHAT_DUANJU_MASTER_APPID', 'wx86822355ccd03a78'),
+    ],
+    'ug' => [
+        'url' => [
+            'listUser' => env('WECHAT_UG_URL_LIST_USER',
+                'http://m.test.duanju.dududus.com/api/audienceManage/outUserGroup/listUser'),
+        ],
+        'signKey' => 'lV9bOCooPTJ68G3a'
     ]
 ];