|
@@ -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
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|