Gdtapi.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Created by: PhpStorm
  4. * User: lytian
  5. * Date: 2020/3/11
  6. * Time: 9:55
  7. */
  8. namespace app\api\controller;
  9. use app\common\controller\Api;
  10. use app\common\library\Redis;
  11. use app\main\constants\CacheConstants;
  12. use think\Log;
  13. class Gdtapi extends Api
  14. {
  15. public function saveclick()
  16. {
  17. $click_id = $this->request->param('click_id');
  18. $gzh_appid = $this->request->param('gzh_appid');
  19. $ip = $this->request->param('ip');
  20. $user_agent = $this->request->param('user_agent');
  21. $user_agent = $user_agent ? urldecode($user_agent) : '';
  22. Log::info("接收数据:". json_encode($this->request->param("")));
  23. if (empty($click_id)) {
  24. exit(json_encode(['ret' => 101, 'msg' => '缺少参数']));
  25. }
  26. $data = [
  27. 'click_id' => $click_id,
  28. ];
  29. if ($gzh_appid) {
  30. $data['gzh_appid'] = trim($gzh_appid);
  31. }
  32. $key = CacheConstants::gdtClickKey($ip, $user_agent);
  33. Redis::instance()->hMSet($key, $data);
  34. Redis::instance()->expire($key, CacheConstants::GDT_CLICLK_CACHE_EXPIRE_TIME);
  35. exit(json_encode(['ret' => 0, 'msg' => '接收成功']));
  36. }
  37. }