SyncOfficialAccounts.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Console\Commands\Report;
  3. use App\Modules\OfficialAccount\Models\OfficialAccount;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Console\Command;
  6. class SyncOfficialAccounts extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'sync:official:accounts';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '同步公众号到投放后台';
  20. /**
  21. * Execute the console command.
  22. *
  23. * @return mixed
  24. */
  25. public function handle()
  26. {
  27. // 获取所有公众号
  28. $accounts = OfficialAccount::getAllOfficialAccountDB();
  29. $accounts = $accounts ? $accounts->toArray() : [];
  30. if (empty($accounts)) {
  31. dd('查询不到公众号');
  32. }
  33. $client = new Client(['timeout' => 10, 'verify' => false]);
  34. $accountsArr = array_chunk($accounts, 50);
  35. foreach ($accountsArr as $accountList) {
  36. $reportData = [
  37. 'platform' => 'wangduyun',
  38. 'list' => []
  39. ];
  40. foreach ($accountList as $account) {
  41. $reportData['list'][] = [
  42. 'id' => getProp($account, 'id'),
  43. 'name' => getProp($account, 'nickname'),
  44. 'app_id' => getProp($account, 'appid'),
  45. 'channel_id' => getProp($account, 'distribution_channel_id'),
  46. ];
  47. }
  48. // 执行上报
  49. $url = 'https://firetrack.zhuishuyun.com/api/syncOfficialAccounts';
  50. $client->post($url, [
  51. 'headers' => [
  52. 'x-code' => 'Mvnx1Yr3O8i!TS5u'
  53. ],
  54. 'json' => $reportData
  55. ]);
  56. }
  57. }
  58. }