123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace General\Services\Report;
- use General\Models\Order\Order;
- use General\Models\Qapp\QappSendOrders;
- use General\Models\Report\ReportUserBindRecord;
- /**
- * 抖音数据上报
- */
- class QappBaiduReport extends BaseReport
- {
- public function __construct()
- {
- $this->register_event_type = 'register';
- $this->charge_event_type = 'ec_buy';
- $this->add_desk_event_type = 'activate';
- }
- public function getRegisterQueryParams(ReportUserBindRecord $user): array
- {
- return [];
- }
- public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
- {
- //百度回传链接
- $this->report_url = $user->link;
- //替换a_type的值
- $this->getReplaceUrl('a_type',$this->charge_event_type);
- //替换a_value的值
- $this->getReplaceUrl('a_value',$amount * 100);
- //百度akey
- $akey = $this->getBaiduAkey($user->uid);
- $this->report_url .= '&sign=' . md5($this->report_url.$akey);
- return [];
- }
- /**
- * 替换url中的操作类型和值
- * @param $type
- * @param $value
- * @return void
- */
- protected function getReplaceUrl($type, $value)
- {
- //获取$type的值
- $type_value = $this->matchItemInUrl($type,$this->report_url);
- //替换$type的值
- $this->report_url = str_replace($type.$type_value,$type.$value,$this->report_url);
- }
- /**
- * 获取百度akey
- * @param $uid
- * @return mixed|string
- */
- protected function getBaiduAkey($uid)
- {
- //获取派单id
- $send_order_id = Order::where('uid',$uid)->value('send_order_id');
- //获取派单平台配置
- $extra_config = QappSendOrders::where('send_order_id',$send_order_id)->value('extra_config');
- if(isset($extra_config) && !empty($extra_config)){
- $extra_config = json_decode($extra_config,true);
- return isset($extra_config['baidu_akey']) ? $extra_config['baidu_akey'] : '';
- }
- return '';
- }
- /**
- * 获取查询字符串的值
- * @param string $item
- * @param string $url
- * @return mixed|string
- */
- protected function matchItemInUrl(string $item, string $url)
- {
- preg_match('/&?' . $item . '=([^&\s]+)&?/i', $url, $arr);
- if ($arr) {
- return $arr[1];
- }
- return '';
- }
- }
|