fly 4 år sedan
förälder
incheckning
1e88582738

+ 16 - 0
src/Models/Report/BaiDuAdAccount.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace General\Models\Report;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BaiDuAdAccount extends Model
+{
+    protected  $table = 'baidu_ad_accounts';
+    protected  $fillable = [
+        'account_name',
+        'token',
+        'channel_user_id',
+        'is_enabled',
+    ];
+}

+ 1 - 1
src/Models/ReportUserBindRecord.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace App\Modules\Report\Models;
+namespace General\Models\Report;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 1 - 1
src/Models/ReportUserChargeRecord.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace App\Modules\Report\Models;
+namespace General\Models\Report;
 
 use Illuminate\Database\Eloquent\Model;
 

+ 71 - 0
src/Services/Report/BaiduReport.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\BaiDuAdAccount;
+use General\Models\Report\ReportUserBindRecord;
+use GuzzleHttp\Client;
+
+/**
+ * 百度数据上报
+ */
+class BaiduReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 19;
+        $this->register_event_type = 3;
+        $this->report_url = 'https://ocpc.baidu.com/ocpcapi/api/uploadConvertData';
+    }
+
+    private function findToken(int $adid)
+    {
+        return BaiDuAdAccount::find($adid);
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'token' => $this->findToken($user->adid),
+            'conversionTypes' => [
+                'logidUrl' => $user->link,
+                'newType' => $this->charge_event_type,
+            ]
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return  [
+            'token' => $this->findToken($user->adid),
+            'conversionTypes' => [
+                'logidUrl' => $user->link,
+                'newType' => $this->register_event_type,
+            ]
+        ];
+    }
+
+    public function report(array $query_params)
+    {
+        $result = false;
+        $content = '';
+        try {
+            $client = new Client(['timeout' => 4]);
+            $response = $client->post($this->report_url, ['json' => $query_params]);
+            $content = $response->getBody()->getContents();
+            $status_code = $response->getStatusCode();
+            if ($status_code == 200) {
+                $result = true;
+            } else {
+                $result = false;
+            }
+        } catch (Exception $e) {
+            myLog('baidu_report')->error($e->getMessage());
+        } finally {
+            return [
+                'result' => $result,
+                'content' => $content,
+            ];
+        }
+    }
+}

+ 74 - 0
src/Services/Report/BaseReport.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+use Exception;
+use GuzzleHttp\Client;
+
+/**
+ * 数据上报基类
+ */
+abstract class BaseReport implements ReportInterface
+{
+    /**
+     * 充值用户事件类型
+     */
+    protected $charge_event_type;
+    /**
+     * 注册用户事件类型
+     */
+    protected $register_event_type;
+    /**
+     * 充值用户数据上报地址
+     */
+    protected $report_url;
+
+    public abstract function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array;
+
+    public abstract function getRegisterQueryParams(ReportUserBindRecord $user): array;
+
+    /**
+     * 付费上报
+     */
+    public function reportCharge(ReportUserBindRecord $user, float $amount)
+    {
+        $query_params = $this->getChargeQueryParams($user, $amount);
+        return $this->report($query_params);
+    }
+
+    /**
+     * 注册上报
+     */
+    public function reportRegister(ReportUserBindRecord $user)
+    {
+        $query_params = $this->getRegisterQueryParams($user);
+        return $this->report($query_params);
+    }
+
+    public function report(array $query_params)
+    {
+        $result = false;
+        $content = '';
+        try {
+            $url = $this->report_url . '?' . http_build_query($query_params);
+            $client = new Client(['timeout' => 4]);
+            $response = $client->get($url);
+            $content = $response->getBody()->getContents();
+            $status_code = $response->getStatusCode();
+            if ($status_code == 200) {
+                $result = true;
+            } else {
+                $result = false;
+            }
+        } catch (Exception $e) {
+            myLog('report')->error($url);
+            myLog('report')->error($e->getMessage());
+        } finally {
+            return [
+                'result' => $result,
+                'content' => $content,
+            ];
+        }
+    }
+}

+ 31 - 0
src/Services/Report/IqiyiReport.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * 爱奇艺数据上报
+ */
+class IqiyiReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 200;
+        $this->report_url = 'http://tc.cupid.iqiyi.com/dsp_lpapi';
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'link' => $user->link,
+            'event_type' => $this->charge_event_type,
+            'conv_time' => time(),
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return [];
+    }
+}

+ 48 - 0
src/Services/Report/KuaishouReport.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * 快手数据上报
+ */
+class KuaishouReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 3;
+        $this->register_event_type = 1;
+        $this->report_url = 'http://ad.partner.gifshow.com/track/activate';
+    }
+
+    private function getCallback(string $link)
+    {
+        preg_match('/&callback=([^&\s]+)&?/i', $link, $callback_arr);
+        if ($callback_arr) {
+            return $callback_arr[1];
+        } else {
+            return '';
+        }
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'callback' => $this->getCallback($user->link),
+            'event_type' => $this->charge_event_type,
+            'event_time' => time() * 1000,
+            'purchase_amount' => $amount,
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return  [
+            'callback' => $this->getCallback($user->link),
+            'event_type' => $this->register_event_type,
+            'event_time' => time() * 1000,
+            'source' => $user->source,
+        ];
+    }
+}

+ 40 - 0
src/Services/Report/QappKuaishouReport.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * 快手数据上报
+ */
+class QappKuaishouReport extends BaseReport
+{
+
+    public function __construct()
+    {
+        $this->charge_event_type = 3;
+        $this->register_event_type = 1;
+        $this->report_url = 'http://ad.partner.gifshow.com/track/activate';
+    }
+
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return [
+            'callback' => $user->callback,
+            'event_type' => $this->register_event_type,
+            'event_time' => time() * 1000,
+            'source' => 'zsy',
+        ];
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return [
+            'callback' => $user->callback,
+            'event_type' => $this->charge_event_type,
+            'event_time' => time() * 1000,
+            'purchase_amount' => $amount,
+        ];
+    }
+}

+ 43 - 0
src/Services/Report/QappTiktokReport.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\QappReportUserChargeRecord;
+use General\Models\Report\ReportUserBindRecord;
+use Exception;
+use GuzzleHttp\Client;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 抖音数据上报
+ */
+class QappTiktokReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 2;
+        $this->register_event_type = 0;
+        $this->report_url = 'https://ad.toutiao.com/track/activate';
+    }
+
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return  [
+            'callback' => $user->callback,
+            'event_type' => $this->register_event_type,
+            'os' => $user->os,
+            'muid' => $user->muid,
+        ];
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'callback' => $user->callback,
+            'event_type' => $this->charge_event_type,
+            'os' => $user->os,
+            'muid' => $user->muid,
+        ];
+    }
+}

+ 21 - 0
src/Services/Report/ReportInterface.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+interface ReportInterface
+{
+    /**
+     * 上报数据
+     */
+    public function report(array $query_params);
+    /**
+     * 获取充值数据上报参数
+     */
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array;
+    /**
+     * 获取注册数据上报参数
+     */
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array;
+}

+ 32 - 0
src/Services/Report/TiktokReport.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * 抖音数据上报
+ */
+class TiktokReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 2;
+        $this->report_url = 'https://ad.toutiao.com/track/activate';
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'link' => $user->link,
+            'event_type' => $this->charge_event_type,
+            'conv_time' => time(),
+            'source' => 'zsy',
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return [];
+    }
+}

+ 38 - 0
src/Services/Report/UcReport.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * UC数据上报
+ */
+class UcReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->charge_event_type = 1000;
+        $this->register_event_type = 5;
+        $this->report_url = 'https://huichuan.uc.cn/callback/ct/add';
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'link' => $user->link,
+            'event_type' => $this->charge_event_type,
+            'event_time' => time(),
+            'source' => 'zsy',
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return  [
+            'link' => $user->link,
+            'event_type' => $this->register_event_type,
+            'event_time' => now(),
+            'source' => 'zsy',
+        ];
+    }
+}

+ 46 - 0
src/Services/Report/WeiboReport.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace General\Services\Report;
+
+use General\Models\Report\ReportUserBindRecord;
+
+/**
+ * UC数据上报
+ */
+class WeiboReport extends BaseReport
+{
+    public function __construct()
+    {
+        $this->register_event_type = 5;
+        $this->charge_event_type = 6;
+        $this->report_url = 'https://appmonitor.biz.weibo.com/sdkserver/active';
+    }
+
+    private function getIMP(string $link)
+    {
+        preg_match('/&?IMP=([^&\s]+)&?/i', $link, $imp_arr);
+        if ($imp_arr) {
+            return $imp_arr[1];
+        } else {
+            return '';
+        }
+    }
+
+    public function getChargeQueryParams(ReportUserBindRecord $user, float $amount): array
+    {
+        return  [
+            'IMP' => $this->getIMP($user->link),
+            'action_type' => $this->charge_event_type,
+            'active_time' => time(),
+        ];
+    }
+
+    public function getRegisterQueryParams(ReportUserBindRecord $user): array
+    {
+        return  [
+            'IMP' => $this->getIMP($user->link),
+            'action_type' => $this->register_event_type,
+            'active_time' => time(),
+        ];
+    }
+}