NewQappTikTokUserCharge.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Jobs\QappTikTok;
  3. use App\Consts\SysConsts;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Queue\SerializesModels;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. /**
  11. * 抖音用户充值
  12. */
  13. class NewQappTikTokUserCharge implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private $reportParams;
  17. protected $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/new_charge';
  18. /**
  19. * QappTikTokUserCharge constructor.
  20. * @param QappTikTokUserChargeRequest $reportParams
  21. */
  22. public function __construct(QappTikTokUserChargeRequest $reportParams)
  23. {
  24. $this->reportParams = $reportParams;
  25. }
  26. /**
  27. * Execute the job.
  28. * @throws \GuzzleHttp\Exception\GuzzleException
  29. */
  30. public function handle()
  31. {
  32. $client = new Client();
  33. $params = [
  34. 'uid' => (int)$this->reportParams->uid,
  35. 'amount' => (float)$this->reportParams->amount,
  36. 'pay_time' => (string)$this->reportParams->pay_time,
  37. 'order_no' => (string)$this->reportParams->order_no,
  38. 'book_id' => (string)$this->reportParams->book_id,
  39. 'book_name' => (string)$this->reportParams->book_name,
  40. 'source' => 'zsy',
  41. ];
  42. // 避免签名错误
  43. if ($this->reportParams->send_order_id) {
  44. $params['send_order_id'] = $this->reportParams->send_order_id;
  45. }
  46. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  47. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  48. myLog('qapp_user_charge')->info($response);
  49. $result = json_decode($response);
  50. if ($result) {
  51. if ($result->code != 0) {
  52. myLog('qapp_user_charge')->info($response);
  53. }
  54. }
  55. }
  56. }