AppflyerEventController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\AppFlyerEvent\AppflyerEvent;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\AccountsInfo;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Redis;
  10. class AppflyerEventController extends Controller
  11. {
  12. /**
  13. * af 事件
  14. * @param string $appsflyer_id
  15. * @param string $appsflyer_event # 充值事件--af_purchase
  16. * @param int $user_id
  17. * @param int $value
  18. * @return bool|string
  19. */
  20. public function index(Request $request)
  21. {
  22. $appsflyer_id = $request->appsflyer_id ?: '';
  23. $user_id = $request->user_id ?: '';
  24. $appsflyer_event = $request->event ?: '';
  25. $amount = $request->amount ?: '';
  26. $packag_name=$request->pack;
  27. $devKey=$request->devKey;
  28. if(!empty($user_id))if (!Redis::hexists('appsflyer_data:' . $user_id, 'appsflyer_id')) {
  29. Redis::hmset('appsflyer_data:' . $user_id, [
  30. 'appsflyer_id' => $appsflyer_id,
  31. 'event' => $appsflyer_event,
  32. 'amount' => $amount,
  33. 'package_name' => $packag_name,
  34. 'dev_key' => $devKey,
  35. 'ip' => $request->ip(),
  36. 'user_agent' => $request->userAgent()
  37. ]);
  38. $UnderWrite=json_encode([$appsflyer_id,$packag_name,$devKey]);
  39. AccountsInfo::where('UserID',$user_id)->update(['UnderWrite'=>$UnderWrite]);
  40. }
  41. return $this->event($user_id,$packag_name, $appsflyer_id,$devKey, $appsflyer_event, $amount);
  42. }
  43. public function event($user_id,$packag_name, $appsflyer_id,$devKey, $appsflyer_event = '', $value = 0)
  44. {
  45. if (empty($appsflyer_id)) {
  46. return 'false';
  47. }
  48. $purchase_event = array(
  49. 'appsflyer_id' => $appsflyer_id,
  50. );
  51. $purchase_event['eventName'] = $appsflyer_event;
  52. if ($value>0) {
  53. $data['af_revenue'] = $value;
  54. $data['af_currency'] = env('CONFIG_24680_CURRENCY','BRL');
  55. $purchase_event['eventValue'] = \GuzzleHttp\json_encode($data);
  56. }
  57. if(!empty($user_id)){
  58. $purchase_event['customer_user_id']=$user_id;
  59. }
  60. $data_string = json_encode($purchase_event);
  61. if (is_string($data_string)) {
  62. Log::channel('AppflyerEvent')->info('af请求数据:' . $data_string);
  63. }
  64. $res = (new AppflyerEvent())->curl($packag_name, $data_string,$devKey);
  65. Log::channel('AppflyerEvent')->info('af返回结果:' . $res);
  66. return $res;
  67. }
  68. // 模拟appfly发送
  69. public function zdR($packag_name = 'com.teempatti.q3acard')
  70. {
  71. return 'false';
  72. $appsflyer_id = '1631349999926-1407734466452985304';
  73. $value = 100;
  74. $af_purchase_r1000['appsflyer_id'] = $appsflyer_id;
  75. $af_purchase_r1000['eventName'] = 'af_purchase_r1000';
  76. $af_purchase_r1000Data['af_revenue'] = $value;
  77. $af_purchase_r1000Data['af_currency'] = 'INR';
  78. $af_purchase_r1000['eventValue'] = \GuzzleHttp\json_encode($af_purchase_r1000Data);
  79. $data_string = json_encode($af_purchase_r1000);
  80. if (is_string($data_string)) {
  81. Log::channel('AppflyerEvent')->info('af中R请求数据:' . $data_string);
  82. }
  83. $r = (new AppflyerEvent())->curl($packag_name, $data_string);
  84. Log::channel('AppflyerEvent')->info('af小于1000返回结果:' . $r);
  85. return $r;
  86. $af_purchase_Rr['appsflyer_id'] = $appsflyer_id;
  87. $af_purchase_Rr['eventName'] = 'af_purchase_Rr';
  88. $af_purchase_RrData['af_revenue'] = $value;
  89. $af_purchase_RrData['af_currency'] = 'INR';
  90. $af_purchase_Rr['eventValue'] = \GuzzleHttp\json_encode($af_purchase_RrData);
  91. $data_string = json_encode($af_purchase_Rr);
  92. if (is_string($data_string)) {
  93. Log::channel('AppflyerEvent')->info('af中R请求数据:' . $data_string);
  94. }
  95. $r = (new AppflyerEvent())->curl($packag_name, $data_string);
  96. Log::channel('AppflyerEvent')->info('af中R返回结果:' . $r);
  97. $af_purchase_R['appsflyer_id'] = $appsflyer_id;
  98. $af_purchase_R['eventName'] = 'af_purchase_R';
  99. $af_purchase_RData['af_revenue'] = $value;
  100. $af_purchase_RData['af_currency'] = 'INR';
  101. $af_purchase_R['eventValue'] = \GuzzleHttp\json_encode($af_purchase_RData);
  102. $data_string = json_encode($af_purchase_R);
  103. $r = (new AppflyerEvent())->curl($packag_name, $data_string);
  104. return $r;
  105. }
  106. }