QappTikTokUserCharge.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * Create a new job instance.
  41. *
  42. * @return void
  43. */
  44. public function __construct(int $uid, float $amount, string $pay_time, string $type, string $book_id, string $book_name, int $molecule = 1, int $denominator = 1)
  45. {
  46. $this->uid = $uid;
  47. $this->amount = $amount;
  48. $this->pay_time = $pay_time;
  49. $this->type = $type;
  50. $this->book_id = $book_id;
  51. $this->book_name = $book_name;
  52. $this->molecule = $molecule;
  53. $this->denominator = $denominator;
  54. }
  55. /**
  56. * Execute the job.
  57. *
  58. * @return void
  59. */
  60. public function handle()
  61. {
  62. $client = new Client();
  63. $params = [
  64. 'uid' => $this->uid,
  65. 'amount' => $this->amount,
  66. 'pay_time' => $this->pay_time,
  67. 'type' => $this->type,
  68. 'book_id' => $this->book_id,
  69. 'book_name' => $this->book_name,
  70. 'molecule' => $this->molecule,
  71. 'denominator' => $this->denominator,
  72. 'source' => 'zsy'
  73. ];
  74. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  75. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  76. myLog('new_user_charge')->info($response);
  77. $result = json_decode($response);
  78. if ($result) {
  79. if ($result->code != 0) {
  80. myLog('new_user_charge')->info($response);
  81. }
  82. }
  83. }
  84. }