QappTikTokUserCharge.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 QappTikTokUserCharge implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private $reportParams;
  17. protected $url;
  18. /**
  19. * 一般情况都上传
  20. */
  21. const COMMON = 'common';
  22. /**
  23. * 只有当天注册当天充值用户才上传
  24. */
  25. const CURRENT_DAY_REGISTER = 'current_day_register';
  26. /**
  27. * 注册24小时之内充值
  28. */
  29. const REGISTER_24_CHARGE = 'register_24_charge';
  30. /**
  31. * QappTikTokUserCharge constructor.
  32. * @param QappTikTokUserChargeRequest $reportParams
  33. */
  34. public function __construct(QappTikTokUserChargeRequest $reportParams)
  35. {
  36. $this->reportParams = $reportParams;
  37. $this->url = env('TIKTOK_API_URL'). 'api/qappuser/charge';
  38. }
  39. /**
  40. * Execute the job.
  41. * @throws \GuzzleHttp\Exception\GuzzleException
  42. */
  43. public function handle()
  44. {
  45. $client = new Client();
  46. $params = [
  47. 'uid' => (int)$this->reportParams->uid,
  48. 'amount' => (float)$this->reportParams->amount,
  49. 'pay_time' => (string)$this->reportParams->pay_time,
  50. 'type' => (string)$this->reportParams->type,
  51. 'book_id' => (string)$this->reportParams->book_id,
  52. 'book_name' => (string)$this->reportParams->book_name,
  53. 'molecule' => (int)$this->reportParams->molecule,
  54. 'denominator' => (int)$this->reportParams->denominator,
  55. 'source' => 'zsy',
  56. 'send_order_id' => $this->reportParams->send_order_id,
  57. ];
  58. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  59. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  60. myLog('qapp_user_charge')->info($response);
  61. $result = json_decode($response);
  62. if ($result) {
  63. if ($result->code != 0) {
  64. myLog('qapp_user_charge')->info($response);
  65. }
  66. }
  67. }
  68. }