12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2020/2/5
- * Time: 下午12:36
- */
- namespace app\api\controller;
- use app\common\library\Ip;
- use app\common\library\Redis;
- use app\main\constants\CacheConstants;
- use app\main\constants\UcCacheConstants;
- use app\main\service\LogService;
- use think\Request;
- class Ucapi
- {
- public function visitorsave($id)
- {
- $referral = Request::instance()->post('referral');
- if ($referral) {
- $ip = Ip::ip();
- $appid = Request::instance()->post('appid', '');
- $key = UcCacheConstants::getGuideWxSubscribe($ip, $_SERVER['HTTP_USER_AGENT'] ?? '');
- if ($appid) {
- Redis::instance()->set($key, $appid . '和' . $id . '和' . $referral, CacheConstants::TOUTIAO_SUB_WINDOW);
- } else {
- Redis::instance()->set($key, $id . '和' . $referral, CacheConstants::TOUTIAO_SUB_WINDOW);
- }
- LogService::info('UCREF:' . $id . ':' . $appid . ':' . $key . ':' . $_SERVER['HTTP_USER_AGENT']);
- } else {
- LogService::notice('UCNOREF:' . $id);
- }
- }
- public function visitorsave4join()
- {
- $ip = Request::instance()->param('ip', '');
- $ua = Request::instance()->param('ua', '');
- $url = Request::instance()->param('url', '');
- if ($ip && $ua && $url) {
- $key = UcCacheConstants::getGuideWxSubscribe($ip, $ua);
- $appid = Request::instance()->param('appid', '');
- if ($appid) {
- Redis::instance()->set($key, $appid . '和0和' . $url, CacheConstants::TOUTIAO_SUB_WINDOW);
- } else {
- Redis::instance()->set($key, '0和' . $url, CacheConstants::TOUTIAO_SUB_WINDOW);
- }
- LogService::info('UCREF:0:' . $appid . ':' . $key . ':' . $ua . ':' . $url);
- return json(['code' => 0, 'msg' => 'ok']);
- } else {
- return json(['code' => 100, 'msg' => 'params ip,ua,url is required, appid is recommended']);
- }
- }
- }
|