NewTikTokUserChargeV2.php 1.8 KB

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