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 ''; } } }