NewTikTokUserCharge.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 NewTikTokUserCharge implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private $uid;
  17. private $amount;
  18. private $pay_time;
  19. private $type;
  20. /**
  21. * 分子
  22. */
  23. private $molecule;
  24. /**
  25. * 分母
  26. */
  27. private $denominator;
  28. protected $url = 'https://newtrackapi.zhuishuyun.com/api/user/charge';
  29. /**
  30. * 一般情况都上传
  31. */
  32. const COMMON = 'common';
  33. /**
  34. * 只有当天注册当天充值用户才上传
  35. */
  36. const CURRENT_DAY_REGISTER = 'current_day_register';
  37. /**
  38. * Create a new job instance.
  39. *
  40. * @return void
  41. */
  42. public function __construct(int $uid, float $amount, string $pay_time, string $type = null, int $molecule = 1, int $denominator = 1)
  43. {
  44. $this->uid = $uid;
  45. $this->amount = $amount;
  46. $this->pay_time = $pay_time;
  47. $this->type = $type ? $type : self::CURRENT_DAY_REGISTER;
  48. $this->molecule = $molecule;
  49. $this->denominator = $denominator;
  50. }
  51. /**
  52. * Execute the job.
  53. *
  54. * @return void
  55. */
  56. public function handle()
  57. {
  58. $client = new Client();
  59. $params = [
  60. 'uid' => $this->uid,
  61. 'amount' => $this->amount,
  62. 'pay_time' => $this->pay_time,
  63. 'type' => $this->type,
  64. 'molecule' => $this->molecule,
  65. 'denominator' => $this->denominator,
  66. 'source' => 'wdy'
  67. ];
  68. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  69. $response = $client->request('post', $this->url, ['form_params' => $params])->getBody()->getContents();
  70. myLog('new_user_charge')->info($response);
  71. $result = json_decode($response);
  72. if ($result) {
  73. if ($result->code != 0) {
  74. myLog('new_user_charge')->info($response);
  75. }
  76. }
  77. }
  78. }