当前位置:网站首页>服务器到服务器 (S2S) 事件 (Adjust)

服务器到服务器 (S2S) 事件 (Adjust)

2022-07-07 11:08:00 雏菊小识

服务器到服务器 (S2S) 事件

<?php

namespace App\Services;

use App\Models\GoogleAffiliateModel;
use Illuminate\Support\Facades\Http;

class AdjustService
{
    
    protected $adjust_event_uri;
    protected $app_token;    //控制面板上的 Adjust 应用识别码
    protected $s2s;    //s2s 参数设置为 1
    protected $environment;

    public function __construct()
    {
    
        $this->s2s = 1;
        $this->app_token = 'xxxxxxxx';
        $this->adjust_event_uri = 'https://s2s.adjust.com/event';
        if (app()->environment('production')) {
    
            $this->environment = 'production';
        } else {
    
            $this->environment = 'sandbox';
        }
    }


    /** * adjust 上报数据事件 */
    public function adjustUpload($order)
    {
    
        //拿到google广告ID 注:客户端传给服务端
        $googleAdId = 'xxxxxxxxx';
        if (empty($googleAdId)) {
    
            return;
        }
        //传递请求的参数
        $request = [
            's2s' => $this->s2s,
            'gps_adid' => $googleAdId, //目前只针对安卓 (android:gps_adid ios:idfa)
            'app_token' => $this->app_token,
            'event_token' => 'xxxxxxx',  //控制面板上的 Adjust事件识别码
            'created_at_unix' => time(),
            'revenue' => $order->amount,
            'currency' => $order->currency,
            'orderId' => $order->id,
            'environment' => $this->environment
        ];

        $response = Http::asForm()->withHeaders(['Content-Type' => 'application/x-www-form-urlencoded'])->post($this->adjust_event_uri, $request);

        \Log::info("adjust上报{
      $order->item_category->label()}事件响应参数", [
            'request' => $request,
            'responseStatus' => $response->status(),
            'responseJson' => $response->json()
        ]);

        if ($response->successful()) {
    
            return $response->json();
        }

        \Log::error("adjust上报{
      $order->item_category->label()}事件失败.");
    }
}
原网站

版权声明
本文为[雏菊小识]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43697366/article/details/125621379