NewQappTikTokUserCharge.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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;
  18. /**
  19. * QappTikTokUserCharge constructor.
  20. * @param QappTikTokUserChargeRequest $reportParams
  21. */
  22. public function __construct(QappTikTokUserChargeRequest $reportParams)
  23. {
  24. $this->reportParams = $reportParams;
  25. $this->url = env('TIKTOK_API_URL'). 'api/qappuser/new_charge';
  26. }
  27. /**
  28. * Execute the job.
  29. * @throws \GuzzleHttp\Exception\GuzzleException
  30. */
  31. public function handle()
  32. {
  33. $client = new Client();
  34. $params = [
  35. 'uid' => (int)$this->reportParams->uid,
  36. 'amount' => (float)$this->reportParams->amount,
  37. 'pay_time' => (string)$this->reportParams->pay_time,
  38. 'order_no' => (string)$this->reportParams->order_no,
  39. 'book_id' => (string)$this->reportParams->book_id,
  40. 'book_name' => (string)$this->reportParams->book_name,
  41. 'source' => 'zsy',
  42. ];
  43. // 避免签名错误
  44. if ($this->reportParams->send_order_id) {
  45. $params['send_order_id'] = $this->reportParams->send_order_id;
  46. }
  47. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  48. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  49. myLog('qapp_user_charge')->info($response);
  50. $result = json_decode($response);
  51. if ($result) {
  52. if ($result->code != 0) {
  53. myLog('qapp_user_charge')->info($response);
  54. }
  55. }
  56. }
  57. }