get('bid'); if(empty($bid)){ $default_ink = $this->getLink(); return redirect()->to($default_ink); } $openid = $request->get('openid'); //授权 $params = $request->except('_url'); if(empty($openid)){ //$url = str_replace('http://', env('PROTOCOL') . '://', url()->current() . '?' . http_build_query($params)); $url = url()->current() . '?' . http_build_query($params); $params['redirect_url'] = urlencode($url); $app = new Application($this->auth($params)); return $app->oauth->redirect(); } try{ $bid = Hashids::decode($bid)[0]; }catch (Exception $e){ return redirect()->to($this->getLink()); } //获取用户 $user = $this->getUsers($openid); if(!$user[0]){ $user[1] = 123; } //有阅读纪录的跳转 $read_record = ReadRecordService::getByField($user[0],$bid); if($read_record){ $cid = explode('_',$read_record)[0]; }else{ //没有阅读记录的跳转 $book_info = BookConfigService::getBookById($bid); $cid = $book_info->first_cid; } $params['cid'] = $cid; if(isset($params['openid'])) unset($params['openid']); if(isset($params['unionid'])) unset($params['unionid']); $url = $this->getLink($user[1]).'reader?'.http_build_query($params); return redirect()->to($url); } public function freeCurrencyView(Request $request){ $openid = $request->get('openid'); //授权 $params = $request->except('_url'); if(empty($openid)){ //$url = str_replace('http://', env('PROTOCOL') . '://', url()->current() . '?' . http_build_query($params)); $url = url()->current() . '?' . http_build_query($params); $params['redirect_url'] = urlencode($url); $app = new Application($this->auth($params)); return $app->oauth->redirect(); } $user = $this->getUsers($openid); if(!$user || !$user[0] || !$user[1]) return redirect()->to($this->getLink()); $get_free_currency = UserBindHkWelfareService::isHasGet($user[0]); if($get_free_currency){ //已经领过 return view('jump.bindHkFreeCurrency',['url'=>$this->getLink($get_free_currency->distribution_channel_id),'is_get'=>1,'uid'=>$get_free_currency->uid]); }else{ return view('jump.bindHkFreeCurrency',['url'=>$this->getLink($user[1]),'is_get'=>0,'uid'=>$user[0]]); } } public function freeCurrencyPost(Request $request){ $uid = $request->post('uid'); $result = UserBindHkWelfareService::getfreeCurrency($uid); if($result){ UserService::addBalance($uid,200,0,200); } return response()->success(['uid'=>$uid,'result'=>$result]); } public function activity(Request $request){ $token = $request->get('token'); if(empty($token)){ $default_ink = $this->getLink(); return redirect()->to($default_ink); } $openid = $request->get('openid'); //授权 $params = $request->except('_url'); if(empty($openid)){ $url = url()->current() . '?' . http_build_query($params); $params['redirect_url'] = urlencode($url); $app = new Application($this->auth($params)); return $app->oauth->redirect(); } $activity = ActivityService::getByToken($token); if($activity){ $user = $this->getUsers($openid); if($user[0]){ $url_format = '%s://site%s.%s.com%s'; $url = sprintf( $url_format, env('PROTOCOL'), encodeDistributionChannelId($user[1]), env('CUSTOM_HOST'), $activity->activity_page ); return redirect()->to($url); } } $default_ink = $this->getLink(); return redirect()->to($default_ink); } private function getUsers($openid){ $users = User::where('openid',$openid)->select('id','distribution_channel_id')->get(); if($users->isEmpty()) return [0,0]; $temp = null; $distribution_channel_id = 0; $uid = 0; foreach ($users as $user){ $last_read = ReadRecordService::getByField($user->id,'last_read'); if(!$last_read) continue; if(!$temp ){ $distribution_channel_id = $user->distribution_channel_id; $uid = $user->id; $temp = $last_read; }else{ $temp_last_read_info = explode('_',$temp); $last_read_info = explode('_',$last_read); if($last_read_info[2] > $temp_last_read_info[2]){ $uid = $user->id; $distribution_channel_id = $user->distribution_channel_id; $temp = $last_read; } } } return [$uid,$distribution_channel_id]; } private function getLink($distribution_channel_id=123){ $url_format = '%s://site%s.%s.com/'; return sprintf( $url_format, env('PROTOCOL'), encodeDistributionChannelId($distribution_channel_id), env('CUSTOM_HOST') ); } private function auth($param){ $param['appid'] = 'wx9d389a73b88bbeae'; $options = [ 'app_id' => 'wx9d389a73b88bbeae', 'secret' => '2f6594bb595dfa256b5512e43a32a3d3', 'oauth' => [ 'scopes' => ['snsapi_base'], 'callback' => env('AUTH_CALLBACK_URL') . '?' . http_build_query($param), ], ]; return $options; } }