Ucapi.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2020/2/5
  6. * Time: 下午12:36
  7. */
  8. namespace app\api\controller;
  9. use app\common\library\Ip;
  10. use app\common\library\Redis;
  11. use app\main\constants\CacheConstants;
  12. use app\main\constants\UcCacheConstants;
  13. use app\main\service\LogService;
  14. use think\Request;
  15. class Ucapi
  16. {
  17. public function visitorsave($id)
  18. {
  19. $referral = Request::instance()->post('referral');
  20. if ($referral) {
  21. $ip = Ip::ip();
  22. $appid = Request::instance()->post('appid', '');
  23. $key = UcCacheConstants::getGuideWxSubscribe($ip, $_SERVER['HTTP_USER_AGENT'] ?? '');
  24. if ($appid) {
  25. Redis::instance()->set($key, $appid . '和' . $id . '和' . $referral, CacheConstants::TOUTIAO_SUB_WINDOW);
  26. } else {
  27. Redis::instance()->set($key, $id . '和' . $referral, CacheConstants::TOUTIAO_SUB_WINDOW);
  28. }
  29. LogService::info('UCREF:' . $id . ':' . $appid . ':' . $key . ':' . $_SERVER['HTTP_USER_AGENT']);
  30. } else {
  31. LogService::notice('UCNOREF:' . $id);
  32. }
  33. }
  34. public function visitorsave4join()
  35. {
  36. $ip = Request::instance()->param('ip', '');
  37. $ua = Request::instance()->param('ua', '');
  38. $url = Request::instance()->param('url', '');
  39. if ($ip && $ua && $url) {
  40. $key = UcCacheConstants::getGuideWxSubscribe($ip, $ua);
  41. $appid = Request::instance()->param('appid', '');
  42. if ($appid) {
  43. Redis::instance()->set($key, $appid . '和0和' . $url, CacheConstants::TOUTIAO_SUB_WINDOW);
  44. } else {
  45. Redis::instance()->set($key, '0和' . $url, CacheConstants::TOUTIAO_SUB_WINDOW);
  46. }
  47. LogService::info('UCREF:0:' . $appid . ':' . $key . ':' . $ua . ':' . $url);
  48. return json(['code' => 0, 'msg' => 'ok']);
  49. } else {
  50. return json(['code' => 100, 'msg' => 'params ip,ua,url is required, appid is recommended']);
  51. }
  52. }
  53. }