channel_id = $channel_id; } /** * 签到回复模板 * @param $title * @param $continueBook * @param $readLogs * @param $recommandBooks */ public function getSignReplayTemplate($title,$readLogs,$recommandBooks, $admin_id = 0, $user){ $this->setTitle($title."\r\n\r\n"); if (!$this->setSignReply($admin_id, $user)) { if ($readLogs) { $book = current($readLogs); $this->setContinueReadBook("【点此继续阅读】", $book); //二期导粉 $this->leadConfig($admin_id, $user['id']); } else { //二期导粉 $this->leadConfig($admin_id, $user['id']); } $this->setReadBookLogs($readLogs); $this->setRecommandBook($recommandBooks); } $this->setTopUrl(); $guideArr = AppGuideService::instance()->getAppGuideInfo($admin_id); if (count($guideArr) && (Ua::getOs() != "iOS")) { $this->setSignText($admin_id); } return $this->content; } /** * 二期导粉配置 * @param $admin_id * @param $user_id * @return bool */ public function leadConfig($admin_id, $user_id) { $export = ExportFansService::instance()->checkFansLead($admin_id, $user_id)->data; if ($export) { if ($export['content']) { $url = getCurrentDomain($admin_id, '/index/share/landpage?id='.$export['id'].'&type=sign&from=wx'); $data = nl2br($export['content']); if (strrpos($data, '
') != false) { foreach (explode('
', $data) as $v) { $v = preg_replace('|\s|', '', $v); if ($v) { $this->content .= "{$v}\r\n"; } } $this->content .= "\r\n"; } else { $this->content .= "{$export['content']}\r\n\r\n"; } } return true; } return false; } public function setExportFans($admin_id, $user_id) { $export = ExportFansService::instance()->checkFansSignToExport($admin_id, $user_id)->data; if ($export) { $url = getCurrentDomain($admin_id, '/index/share/exportfans'); $this->content .= "劲爆爽文,免费领取,戳我立即阅读"; return true; } return false; } public function setSignReply($admin_id, $user = null) { $cacheKey = CacheConstants::getSignReplyCache($admin_id); $userOs = UserVipExtendService::instance()->getUserOs($user['id']); $cacheKey = $cacheKey.'OS:'.$userOs; $content = Redis::instance()->get($cacheKey); if ($content !== false) { //二期导粉 if ($content) { $this->leadConfig($admin_id, $user['id']); } $this->content .= $content; return $content; } else { $find = model('wechat_autoreply')->where(['admin_id'=>$admin_id,'title'=>'签到', 'type'=>'text', 'status'=>'normal'])->find(); if ($find && $find['text_content']) { $list = json_decode($find['text_content'], JSON_UNESCAPED_UNICODE); $content .= $find['text_tip_word']."\r\n\r\n"; foreach ($list as $item) { if (isset($item['url_type'])) { switch ($item['url_type']) { case '1'://推广链接 $url = $item['referral_url']; break; case '2'://活动链接 $url = $item['activity_url']; break; case '3'://最近阅读 $url = getCurrentDomain($admin_id, '/index/user/recent'); break; default: break; } } else { $url = $item['url']; } $url = UrlService::instance()->replaceReferralHost($admin_id, $url, false)->data; $userInfo = UserService::instance()->getUserModel()->getUserInfo($user['id']); $channelInfo =AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($userInfo['channel_id']); $isBlockIosUser = UserVipExtendService::instance()->isBlockIosUser($channelInfo,$user['id'], $url); if(!$isBlockIosUser){ $content .= "{$item['title']}\r\n\r\n"; } } $this->leadConfig($admin_id, $user['id']); $this->content .= $content; Redis::instance()->setex($cacheKey, 120, $content); return true; } else { Redis::instance()->setex($cacheKey, 120, ''); return false; } } } /** * 自定义二维码推广链接回复模板 * @param $title * @param $url */ public function getQRCodeRefReplayTemplate($title,$url){ $this->setTitle($title."\r\n\r\n"); $this->setContinueReadRef($url); $this->setTopUrl(); return $this->content; } /** * 永久二维码关注回复模板 * @param $title * @param $continueBook */ public function getQRCodeReplayTemplate($title,$continueBook){ $this->setTitle($title."\r\n\r\n"); $this->setContinueReadBook("点此继续阅读《%s》",$continueBook); $this->setTopUrl(); return $this->content; } /** * 默认关注回复模板 * @param $title * @param $continueBook * @param $recommandBooks */ public function getFollowReplayTemplate($title,$continueBook,$recommandBooks){ if($continueBook){ $this->setTitle($title."\r\n\r\n"); }else{ $this->setTitle($title); } $this->setContinueReadBook("【点此继续阅读】",$continueBook); $this->setRecommandBook($recommandBooks); $this->setTopUrl(); $switch = AdminService::instance()->getSubscribeSwitchCache($this->channel_id); if (!empty($switch) && $switch['status'] == 1) { if ($switch['type'] == 1) {//系统默认 $this->setSignTip(); } else {//自定义 $we = Redis::instance()->get('OSCCT:' . $this->channel_id); if (empty($we)) { $where = []; $where['admin_id'] = ['eq', $this->channel_id]; $where['status'] = ['eq', 'normal']; $where['type'] = ['eq', 'text']; $where['starttime'] = ['<=', time()]; $where['endtime'] = ['>', time()]; $wechatSubcribeConfigObj = model('WechatSubscribeConfig')->where($where)->order('id', 'desc')->find(); if (!empty($wechatSubcribeConfigObj)) { $we = $wechatSubcribeConfigObj->getData(); } else { $we['sign_type'] = 1; } if (isset($we['endtime'])) { if ($we['endtime'] - time() >= 604800) { $expire = 604800; } else { if ($we['endtime'] > time()) { $expire = $we['endtime'] - time(); } else { $expire = 0; } } } else { $expire = 604800; } Redis::instance()->setex('OSCCT:' . $this->channel_id, $expire, json_encode($we, JSON_UNESCAPED_UNICODE)); } else { $we = json_decode($we, true); } if (!empty($we) && isset($we['sign_type']) && $we['sign_type'] == 2) { $this->content .= "\r\n\r\n"; $this->content .= "{$we['sign_txt']}"; } else { $this->setSignTip(); } } } else { $this->setSignTip(); } return $this->content; } /** * 设置title * @param $title */ protected function setTitle($title){ $this->content.= $title; } /** * 设置推广链接继续阅读 * @param $url * @param $title */ protected function setContinueReadRef($url,$title = null){ $this->content .= "".($title ?? "【点此继续阅读】")."\r\n\r\n"; } /** * 设置继续阅读 * @param $book */ protected function setContinueReadBook($tpl,$book){ if($book){ $params['book_id'] = $book['book_id']; $params['sid'] = $book['chapter_id']; $url = getCurrentDomain($this->channel_id,'/index/book/chapter',$params); $this->content .= "".sprintf($tpl,$book['book_name'])."\r\n\r\n"; } } /** * 设置阅读记录 * @param $readLogs */ protected function setReadBookLogs($readLogs){ //阅读记录 if($readLogs){ $this->content.= "历史阅读记录:\r\n\r\n"; foreach($readLogs as $book){ $params['book_id'] = $book['book_id']; $params['sid'] = $book['chapter_id']; $url = getCurrentDomain($this->channel_id,'/index/book/chapter',$params); $this->content .= "{$book['book_name']}\r\n\r\n"; } } } /** * 设置推荐书籍 * @param $recommandBook */ protected function setRecommandBook($recommandBook){ if($recommandBook){ $this->content.= "推荐几本热门的小说,给你看看:\r\n\r\n"; foreach($recommandBook as $book){ $params['book_id'] = $book['book_id']; $url = getCurrentDomain($this->channel_id,'/index/book/chapter',$params); $this->content .= "{$book['book_name']}\r\n\r\n"; } } } /** * 设置置顶URL * @param string $url */ protected function setTopUrl($url = ''){ if(!$url){ $top = model('ManageKey')->getOneByKey('top'); if($top){ $url .= $top['image']; } } $this->content .= "为方便下次阅读,请置顶公众号"; } /** * 设置签到提示文字(关注时自动回复) */ protected function setSignTip(){ $kandian = Config::get('site.kandian_sign'); if($kandian){ $this->content .= "\r\n\r\n回复“签到”或点击“签到送币”菜单,最高获得{$kandian}书币"; } } /** * 下载APP客户端 */ protected function setSignText($admin_id) { if($admin_id){ $guide_data = AppGuideService::instance()->getAppGuideInfo($admin_id); if (!empty($guide_data['replysigntxt'])) { $link_text = $guide_data['replysigntxt']; //$url = getCurrentDomain($this->channel_id, '/clientweb/signagent/index'); $url = $guide_data['app_url']; $this->content .= "\r\n\r\n{$link_text}"; } } } }