QappBaiduReport.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace General\Services\Report;
  3. use General\Models\Order\Order;
  4. use General\Models\Qapp\QappSendOrders;
  5. use General\Models\Report\ReportUserBindRecord;
  6. /**
  7. * 抖音数据上报
  8. */
  9. class QappBaiduReport extends BaseReport
  10. {
  11. public function __construct()
  12. {
  13. $this->register_event_type = 'register';
  14. $this->charge_event_type = 'ec_buy';
  15. $this->add_desk_event_type = 'activate';
  16. }
  17. public function getRegisterQueryParams(ReportUserBindRecord $user): array
  18. {
  19. return [];
  20. }
  21. public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
  22. {
  23. //百度回传链接
  24. $this->report_url = $user->link;
  25. //替换a_type的值
  26. $this->getReplaceUrl('a_type',$this->charge_event_type);
  27. //替换a_value的值
  28. $this->getReplaceUrl('a_value',$amount * 100);
  29. //百度akey
  30. $akey = $this->getBaiduAkey($user->uid);
  31. $this->report_url .= '&sign=' . md5($this->report_url.$akey);
  32. return [];
  33. }
  34. /**
  35. * 替换url中的操作类型和值
  36. * @param $type
  37. * @param $value
  38. * @return void
  39. */
  40. protected function getReplaceUrl($type, $value)
  41. {
  42. //获取$type的值
  43. $type_value = $this->matchItemInUrl($type,$this->report_url);
  44. //替换$type的值
  45. $this->report_url = str_replace($type.$type_value,$type.$value,$this->report_url);
  46. }
  47. /**
  48. * 获取百度akey
  49. * @param $uid
  50. * @return mixed|string
  51. */
  52. protected function getBaiduAkey($uid)
  53. {
  54. //获取派单id
  55. $send_order_id = Order::where('uid',$uid)->value('send_order_id');
  56. //获取派单平台配置
  57. $extra_config = QappSendOrders::where('send_order_id',$send_order_id)->value('extra_config');
  58. if(isset($extra_config) && !empty($extra_config)){
  59. $extra_config = json_decode($extra_config,true);
  60. return isset($extra_config['baidu_akey']) ? $extra_config['baidu_akey'] : '';
  61. }
  62. return '';
  63. }
  64. /**
  65. * 获取查询字符串的值
  66. * @param string $item
  67. * @param string $url
  68. * @return mixed|string
  69. */
  70. protected function matchItemInUrl(string $item, string $url)
  71. {
  72. preg_match('/&?' . $item . '=([^&\s]+)&?/i', $url, $arr);
  73. if ($arr) {
  74. return $arr[1];
  75. }
  76. return '';
  77. }
  78. }