1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?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
- ]);
- }
- }
- }
|