Bläddra i källkod

SyncOfficialAccounts command

zz 4 år sedan
förälder
incheckning
04c6df5125

+ 73 - 0
app/Console/Commands/Report/SyncOfficialAccounts.php

@@ -0,0 +1,73 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2021/2/22
+ * Time: 11:34
+ */
+
+namespace App\Console\Commands\Report;
+
+use App\Modules\OfficialAccount\Models\OfficialAccount;
+use GuzzleHttp\Client;
+use Illuminate\Console\Command;
+
+class SyncOfficialAccounts extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'sync:official:accounts';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '同步公众号到投放后台';
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        // 获取所有公众号 'id','nickname','appid','distribution_channel_id' 只获取这4个
+        $accounts = OfficialAccount::getAllOfficialAccountDB();
+        $accounts = $accounts ? $accounts->toArray() : [];
+        if (empty($accounts)) {
+            dd('查询不到公众号');
+        }
+
+        $client      = new Client(['timeout' => 10, 'verify' => false]);
+        $accountsArr = array_chunk($accounts, 50);
+        foreach ($accountsArr as $accountList) {
+
+            $reportData = [
+                'platform' => 'wangduyun',
+                'list'     => []
+            ];
+
+            foreach ($accountList as $account) {
+                $reportData['list'][] = [
+                    'id'         => getProp($account, 'id'),
+                    'name'       => getProp($account, 'nickname'),
+                    'app_id'     => getProp($account, 'appid'),
+                    'channel_id' => getProp($account, 'distribution_channel_id'),
+                ];
+            }
+
+            // 执行上报
+            $url = 'https://firetrack.wd.amanbook.com/api/syncOfficialAccounts';
+            $client->post($url, [
+                'headers' => [
+                    'x-code' => 'Mvnx1Yr3O8i!TS5u'
+                ],
+                'json'    => $reportData
+            ]);
+        }
+    }
+}

+ 4 - 1
app/Console/Kernel.php

@@ -160,6 +160,8 @@ class Kernel extends ConsoleKernel
         // temp
         Commands\Temp\NewBookTestType::class,
         Commands\Temp\CheckCidError::class,
+        //同步服务号到fire
+        Commands\Report\SyncOfficialAccounts::class,
 
     ];
 
@@ -398,6 +400,7 @@ class Kernel extends ConsoleKernel
 //         $schedule->command('cp_agent_day_stat')->dailyAt('01:44');
         $schedule->command('new_user_charge_day_statistic')->dailyAt('05:44');
 
-
+        //同步服务号信息到fire
+        $schedule->command('sync:official:accounts')->hourly();
     }
 }

+ 1 - 1
app/Modules/OfficialAccount/Models/OfficialAccount.php

@@ -40,7 +40,7 @@ class OfficialAccount extends Model
     static function getAllOfficialAccountDB()
     {
 
-        return self::select()->get();
+        return self::select('id','nickname','appid','distribution_channel_id')->get();
 
     }