QappTikTokUserCharge.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Jobs;
  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 $uid;
  17. private $amount;
  18. private $pay_time;
  19. private $type;
  20. private $book_id;
  21. private $book_name;
  22. /**
  23. * 分子
  24. */
  25. private $molecule;
  26. /**
  27. * 分母
  28. */
  29. private $denominator;
  30. protected $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/charge';
  31. /**
  32. * 一般情况都上传
  33. */
  34. const COMMON = 'common';
  35. /**
  36. * 只有当天注册当天充值用户才上传
  37. */
  38. const CURRENT_DAY_REGISTER = 'current_day_register';
  39. /**
  40. * 注册24小时之内充值
  41. */
  42. const REGISTER_24_CHARGE = 'register_24_charge';
  43. /**
  44. * Create a new job instance.
  45. *
  46. * @return void
  47. */
  48. public function __construct(int $uid, float $amount, string $pay_time, string $type, string $book_id, string $book_name, int $molecule = 1, int $denominator = 1)
  49. {
  50. $this->uid = $uid;
  51. $this->amount = $amount;
  52. $this->pay_time = $pay_time;
  53. $this->type = $type;
  54. $this->book_id = $book_id;
  55. $this->book_name = $book_name;
  56. $this->molecule = $molecule;
  57. $this->denominator = $denominator;
  58. }
  59. /**
  60. * Execute the job.
  61. *
  62. * @return void
  63. */
  64. public function handle()
  65. {
  66. $client = new Client();
  67. $params = [
  68. 'uid' => $this->uid,
  69. 'amount' => $this->amount,
  70. 'pay_time' => $this->pay_time,
  71. 'type' => $this->type,
  72. 'book_id' => $this->book_id,
  73. 'book_name' => $this->book_name,
  74. 'molecule' => $this->molecule,
  75. 'denominator' => $this->denominator,
  76. 'source' => 'zsy'
  77. ];
  78. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  79. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  80. myLog('qapp_user_charge')->info($response);
  81. $result = json_decode($response);
  82. if ($result) {
  83. if ($result->code != 0) {
  84. myLog('qapp_user_charge')->info($response);
  85. }
  86. }
  87. }
  88. }