123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wanggb
- * Date: 2019/2/21
- * Time: 19:00
- */
- namespace app\api\controller;
- use app\common\constants\AppConstants;
- use app\common\controller\Api;
- use app\common\library\Redis;
- use app\common\service\ReferralService;
- use app\main\constants\CacheConstants;
- use app\main\service\LogService;
- use think\Config;
- use think\Log;
- class Referral extends Api
- {
- protected $wechatRedisKey = 'WECHATPOOLS:';
- public function getreferralshort()
- {
- Log::info('[ API ] [ REFERRAL ] PARAM: ' . json_encode(var_export($this->request->param(), true),
- JSON_UNESCAPED_UNICODE));
- $id = $this->request->param('id');
- $type = $this->request->param('type');
- $channel_id = ReferralService::instance()->getChannelIdByReferralId($id);
- $referral = ReferralService::instance()->getReferralModel()->where('id', '=', $id)->find();
- Log::info('[ API ] [ REFERRAL ] channel_id::' . $channel_id);
- if ($channel_id) {
- $referral_url = getCurrentDomain($channel_id, $referral['source_url']);
- } else {
- $referral_url = $referral['source_url'];
- }
- Log::info('[ API ] [ REFERRAL ] SourceURL:' . $referral_url);
- if ($type == 'code') {
- //$wechat_domains = @file_get_contents(ROOT_PATH . 'public/wechat_domains.txt');
- /*$redis = Redis::instance();
- $wechat_domains = $redis->get($this->wechatRedisKey);
- $data = json_decode($wechat_domains, true);
- $idx = rand(0, (count($data) - 1));*/
- $wechatDomainData = AppConstants::getRandomWechatDomain();
- $appid = $wechatDomainData['appid'];
- $wechatDomain = $wechatDomainData['domain'];
- $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=";
- $url .= urlencode("http://" . $wechatDomain . "/referral.html?t=" . $id . "&channel_id=" . $channel_id);
- $url .= "&response_type=code&scope=snsapi_base&connect_redirect=1#wechat_redirect";
- //$url = "/referral.html?t=" . $id . "&channel_id=" . $channel_id;
- Log::info('[ API ] [ REFERRAL ] [RESULTURL] ' . $url);
- $this->success('返回成功', ['url' => $url]);
- } else {
- //方案一
- /*if ($referral['short_id'] > 0) {
- // 开启导粉域名
- $jump_url = getCurrentDomain($channel_id, '/t/' . $referral['id']);
- $referral_url = replaceShortDomain($jump_url, $referral['short_id']);
- Log::info('[ API ] [ REFERRAL ] replaceShortDomain ' . $referral_url);
- }*/
- //方案二
- $referral_url = $this->getGuideDomain($channel_id, $referral['id']);
- if(empty($referral_url)){
- // 获取业务域名
- $referral_url = getCurrentDomain($channel_id, '/t/' . $referral['id']);
- }
- Log::info('[ API ] [ REFERRAL ] GuideDomain ' . $referral_url);
- Log::info('[ API ] [ REFERRAL ] [RESULTURL] ' . $referral_url);
- $this->success('返回成功', ['url' => $referral_url]);
- }
- }
- /**
- * 获取GuideDomain
- * @param $admin_id
- * @param $referral_id
- * @return string
- */
- public function getGuideDomain($admin_id, $referral_id)
- {
- $adminConfigInfo = model('AdminConfig')->getAdminInfoAll($admin_id);
- // 短链域名&倒粉域名开关 是否开启/data/www/cps/application/api/controller/Referral.php
- if (!empty($adminConfigInfo['guide_domain'])) {
- $guide_domain = model('GuideRelation')->getRandGuideHost($admin_id);
- return sprintf("%s/t/%d", $guide_domain, $referral_id);
- } else {
- return '';
- }
- }
- }
|