cookieNoCrypt(); $test = 0; if ($request->has('test') && $request->input('test') == 'bonan') { $test = 1; } $uid_cookie = Cookie::get(env('COOKIE_AUTH_WEB_WECHAT')); $h5_scheme = env('H5_SCHEME', 'https'); $params = $request->except('_url'); $url = str_replace('http://', $h5_scheme . '://', url()->current() . '?' . http_build_query($params)); //Log::info('-----------------uid' . $uid_cookie); $send_order_id = $request->input('send_order_id'); if($send_order_id){ Cookie::queue('send_order_id',$send_order_id, env('U_COOKIE_EXPIRE'), null, null, false, false); } $distribution_channel_id = str_replace('site', '', explode('.', _domain())[0]); $origin_distribution_channel_id = $distribution_channel_id; if(!is_numeric($distribution_channel_id)){ $distribution_channel_id = decodeDistributionChannelId($distribution_channel_id); } if(!$distribution_channel_id){ return response()->error('WAP_SYS_ERROR'); } //禁止访问的site $not_allow_access_site = env('NOT_ALLOW_ACCESS_SITE',''); if($not_allow_access_site){ $not_allow_access_site_arr = explode(',',$not_allow_access_site); if(in_array($distribution_channel_id,$not_allow_access_site_arr)){ return response($this->notAccessPage())->header('Content-Type', 'text/html'); } } if (!$uid_cookie && $test == 0) { //$url = str_replace('http://','https://',url()->current())."?".http_build_query($params); $uri = $request->input('_url'); if(strpos($uri,'/yun/') !== false){ $uri_send_order_id = (int)str_ireplace('/yun/','',$uri); Cookie::queue('send_order_id', $uri_send_order_id, env('U_COOKIE_EXPIRE'), null, null, false, false); } $this->share($request); Cookie::queue('auth_redirect', urlencode($url), env('U_COOKIE_EXPIRE')); //$params['redirect_url'] = urlencode(env('PUBLIC_BASE_API').'oauthCallBack'); //$params['redirect_url'] = urlencode('http://47.96.174.172:8093/oauthCallBack'); $domain = _domain(); $params['redirect_url'] = urlencode($h5_scheme . '://' . $domain . '/oauthCallBack'); $params['timestamp'] = time(); //$office_info = $this->getOfficialAccount(_domain()); //$params['gzh_app_id'] = $office_info['appid']; $params['gzh_app_id'] = env('WECHAT_AUTH_APPID'); $params['sign'] = $this->getSign($params, env('OAUTH_KEY')); $redirect = env('AUTH_URL') . '?' . http_build_query($params); $auth_v2_url = $this->authV2($request,$distribution_channel_id); if($auth_v2_url){ return redirect()->to($auth_v2_url); } $redirect_V2 = $this->auth($request,$distribution_channel_id); if($redirect_V2){ return redirect()->to($redirect_V2); } return redirect()->to($redirect); } //禁止明文访问 if($this->isForbidPrimaryNumberChannleID($origin_distribution_channel_id,$uid_cookie)){ return response('该网站地址暂停访问

该网站地址暂停访问,请联系客服微信获取新地址:wuxinchao12

'); } if($request->has('appid') && $request->has('openid')){ Log::info('param is:'); Log::info($params); $uri = $request->input('_url'); $openid = $request->get('openid') ; $appid = $request->get('appid') ; /* $user_info = ForceSubscribeService::getUserInfo($appid,$openid); Log::info('appid user id to userinfo'); Log::info($user_info);*/ $back = $request->get('back',''); if($openid && $appid && $distribution_channel_id && $uid_cookie){ $this->apidAndOpenId($distribution_channel_id,$appid,$openid,$uid_cookie); $channel = ChannelService::getById($distribution_channel_id); $is_yq_move = $this->isQyMove($channel,$distribution_channel_id); if($is_yq_move){ $move_user = YqMove::where('zsy_uid',$uid_cookie)->select('zsy_uid')->first(); if(!$move_user){ if(!$back){ $yq_home = $this->getYqChannleIdByAppid($appid); Log::info('$this->getYqChannleIdByAppid($appid) is : '); Log::info($yq_home); if($yq_home){ $params['zsy_channel_id'] = encodeDistributionChannelId($distribution_channel_id); $params['pa'] = $uri; $back_url = $yq_home.'move?'.http_build_query($params); Log::info('$yq_home - $back_url is: '.$back_url); return redirect()->to($back_url); } } $this->moveUserFromYq($distribution_channel_id,$appid,$openid,$uid_cookie); } } } } //只能推送的统计 $this->smartPush($request,$uid_cookie); //数据分析 长篇推短片的统计 $this->dataAnalysis($request,$uid_cookie); //from where的临时统计 $this->tempFromWhere($request,$uid_cookie); //统计访问site数字的uid记录下 //$this->recordPrimaryNumberChannleIDUser($origin_distribution_channel_id,$uid_cookie); $response = $next($request); $stats = $request->get('stats',0); if ($request->has('fromtype') && $request->input('fromtype')) { try { $from = $request->input('fromtype', 'main'); Cookie::queue('from', $from, env('U_COOKIE_EXPIRE'), null, null, false, false); if(!$stats){ Redis::sadd('push:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from . ':date:' . date('Y-m-d'), $uid_cookie); Redis::sadd('push:distribution_channel_id:alluv:from:' . $from , $uid_cookie); Redis::hincrby('push:distribution_channel_id:allpv' ,$from, 1); Redis::hincrby('customer:push:click:distribution_channel_id:' . $distribution_channel_id . 'from:' . $from, date('Y-m-d'), 1); Redis::sadd('wap_from_stats'.date('Y-m-d'),$distribution_channel_id.'-'.$from); } } catch (\Exception $e) { Log::info($e); } } $from = $request->get('fromtype'); $inner_order_id = $request->get('inner_order_id'); if(!$from){ $from = Cookie::get('from'); $this->innerSendOrderIdFromFromtype($uid_cookie,1,$from,$inner_order_id); }else{ $this->innerSendOrderIdFromFromtype($uid_cookie,$stats,$from,$inner_order_id); } //内部派单 if($inner_order_id){ $this->innerSendOrderIdStats($uid_cookie,$inner_order_id,$stats); } //from_title_image $this->fromTitleImage($request,$uid_cookie); if ($test) { Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), 9, env('U_COOKIE_EXPIRE'), null, null, false, false); } return $response; } private function share(Request $request){ if($request->has('fromtype') && 'readershare' == $request->get('fromtype')){ $bid = $request->get('bid'); try{ if($bid){ $bid_arr = Hashids::decode($bid); isset($bid_arr[0]) && $bid = $bid_arr[0]; } }catch (\Exception $e){} $fromflag = $request->get('fromflag',0); $cid = $request->get('fromcid',0); Cookie::queue('reader_share_bid',$bid.'-'.$fromflag,60); Cookie::queue('reader_share_cid',$cid,60); } } private function isQyMove($channel,$distribution_channel_id){ $is_yq_move = 0; // 新站 if(isset($channel->is_yq_move) && $channel->is_yq_move){ $is_yq_move = 1; } // 已经迁移过的站,回复也要有老站 $yqMoveChannel = YqMoveChannel::get_yq_move_channel($distribution_channel_id,1); if(!empty($yqMoveChannel)){ //\Log::info('old_has_move_site:'.$distribution_channel_id); $is_yq_move = 1; } return $is_yq_move; } private function innerSendOrderIdFromFromtype($uid,$stats,$from,$inner_order_id){ //$inner_send_order_id = ReadRecordService::getInnerSendOrderId($uid); $inner_send_order_id = false; if(!$inner_send_order_id){ if($from && (starts_with($from,'custom') || starts_with($from,'template')) && count(explode('_',$from)) == 2){ if(!$inner_order_id){ $this->innerSendOrderIdStats($uid,$from,$stats); } } } } private function innerSendOrderIdStats($uid,$inner_order_id,$stats){ try{ ReadRecordService::setInnerSendOrderId($uid,$inner_order_id); if(!$stats){ Redis::sadd('push:inner_send_order_id:uv:' . $inner_order_id , $uid); Redis::hincrby('push:inner_send_order_id:pv' ,$inner_order_id, 1); } }catch (\Exception $e){} } private function cookieNoCrypt() { $cookie_key = ['send_order_id', 'from', 'send_order_continue', 'send_order_flag']; foreach ($cookie_key as $v) { $temp = Cookie::get($v); if ($temp && strlen($temp) > 150) { try{ $temp = decrypt($temp); }catch (\Exception $e){ } if ($v == 'from') { Cookie::queue('from', $temp, env('U_COOKIE_EXPIRE'), null, null, false, false); //Cookie::queue($v, $temp); } else { Cookie::queue($v, $temp, env('U_COOKIE_EXPIRE'), null, null, false, false); } } } } /** * 公众号签名@华灯初上 * @param $params * @return string */ protected function getSign($params, $key) { $url = $this->arr_to_url($params, false); $url = $url . '&key=' . $key; $sign = md5($url); return $sign; } /** * 公众号签名@华灯初上 * @param $array * @param bool $has_sign * @return string */ protected function arr_to_url($array, $has_sign = false) { ksort($array); reset($array); $arg = ""; while (list ($name, $val) = each($array)) { if ($name == 'sign' && !$has_sign) continue; if (strpos($name, "_") === 0) continue; if (is_array($val)) $val = join(',', $val); if ($val === "") continue; $arg .= $name . "=" . $val . "&"; } $arg = substr($arg, 0, count($arg) - 2); return $arg; } private function apidAndOpenId($distribution_channel_id,$appid,$openid,$uid){ $appid_info = OfficialAccountService::officialAccountByAppid(['appid'=>$appid]); if(!$appid_info) return false; if($appid_info->distribution_channel_id != $distribution_channel_id){ return false; } //ForceSubscribeService:: $res = ForceSubscribeService::forceSubscribeUsersByUid(['uid' =>$uid]); if ($res) return false; $forcesubuser = ForceSubscribeService::forceSubscribeUsersByOpenid(['openid'=>$openid]); if($forcesubuser){ return false; } $send_order_id =ReadRecordService::getSendOrderId($uid); if($send_order_id){ try{ Redis::hset('force_subscribe_from_send_order_id',$appid.'_'.$uid,$send_order_id); }catch (\Exception $e){} } $user_info = ForceSubscribeService::getUserInfoAll($appid,$openid); $forcesubuserdata = [ 'appid'=>$appid, 'uid'=>$uid, 'distribution_channel_id'=>$distribution_channel_id, 'last_interactive_time'=>date('Y-m-d H:i:s'), 'openid'=>$openid, 'official_account_id'=>1 ]; if($user_info){ isset($user_info['province']) && !empty($user_info['province']) && $forcesubuserdata['province'] = $user_info['province']; isset($user_info['nickname']) && !empty($user_info['nickname']) && $forcesubuserdata['nickname'] = $user_info['nickname']; isset($user_info['city']) && !empty($user_info['city']) && $forcesubuserdata['city'] = $user_info['city']; isset($user_info['country']) && !empty($user_info['country']) && $forcesubuserdata['country'] = $user_info['country']; isset($user_info['headimgurl']) && !empty($user_info['headimgurl']) && $forcesubuserdata['headimgurl'] = $user_info['headimgurl']; isset($user_info['sex']) && !empty($user_info['sex']) && $forcesubuserdata['sex'] = $user_info['sex']; } ForceSubscribeService::addForceSubscribeUsers($forcesubuserdata); ForceSubscribeService::tempForceSubscribeUsersLastTimeUpdate([ 'openid'=>$openid, 'last_interactive_time'=>date('Y-m-d H:i:s') ]); return true; } private function getYqChannleIdByAppid($appid){ $client = new Client(['timeout' => 3.0]); $url = 'http://help.imycmh.com/help/getLinkByAppid?appid='.$appid; Log::info('getYqChannleIdByAppid url is: '.$url); try{ $result = $client->request('get',$url)->getBody()->getContents(); $result = json_decode($result,1); Log::info('getYqChannleIdByAppid result is.: '); Log::info($result); if(isset($result['data']['link']) && !empty($result['data']['link'])){ return $result['data']['link']; } }catch (\Exception $e){} return ''; } private function moveUserFromYq($distribution_channel_id,$appid,$openid,$uid){ /*//is_yq_move $channel = ChannelService::getById($distribution_channel_id); if(!$channel->is_yq_move){ return ; } $move_user = YqMove::where('zsy_uid',$uid)->select('zsy_uid')->first(); if($move_user){ return ; }*/ $client = new Client(['timeout' => 3.0]); $url = 'http://help.imycmh.com/getUserInfoByOpenid?openid='.$openid; try{ $result = $client->request('get',$url)->getBody()->getContents(); if(!$result){ return ; } $result = json_decode($result,1); $result_data = isset($result['data'])?$result['data']:''; if(!$result_data){ return ; } if(isset($result_data['uid']) && !empty($result_data['uid'])){ //$result_data['read_count'] = 53; if($result_data['read_count']>50){ //不补偿 $pay_for_balance = 500; $data = [ 'yq_uid'=>$result_data['uid'], 'zsy_uid'=>$uid, 'yq_distribution_channel_id'=>$result_data['user']['distribution_channel_id'], 'zsy_distribution_channel_id'=>$distribution_channel_id, 'read_count'=>$result_data['read_count'], 'yq_balance'=>$result_data['user']['balance'], 'is_pay'=>0, 'pay_for_balance'=>$pay_for_balance, 'openid'=>$openid, 'appid'=>$appid ]; $special = env('YQ_MOVE_SPECIAL'); if($special && in_array($distribution_channel_id,explode(',',$special))){ //特殊梳理 $yq_charge_amount = $result_data['order_amoun']; if($yq_charge_amount>30){ $pay_for_balance = 3000; }else{ $pay_for_balance = $yq_charge_amount*100; } if($pay_for_balance <500){ $pay_for_balance = 500; } if($pay_for_balance>3000){ $pay_for_balance = 3000; } $pay_for_balance = (int)$pay_for_balance; $balance = $pay_for_balance+$result_data['user']['balance']; $data['pay_for_balance'] = $pay_for_balance; $data['is_pay'] = 1; YqMove::create($data); UserService::addBalance($uid,$balance,0,$balance); $flag = false; if(in_array($distribution_channel_id,[160,4236,4237,4241])){ //特殊 回复老站 $flag = true; } $this->movePush($distribution_channel_id,$pay_for_balance,$appid,$result_data['user']['distribution_channel_id'],$openid,$flag); }else{ $data['is_pay'] = 1; YqMove::create($data); UserService::addBalance($uid,$pay_for_balance,0,$pay_for_balance); $this->movePush($distribution_channel_id,$pay_for_balance,$appid,$result_data['user']['distribution_channel_id'],$openid,true); } }else{ //补偿 $yq_charge_amount = $result_data['order_amoun']; if($yq_charge_amount>30){ $pay_for_balance = 3000; }else{ $pay_for_balance = $yq_charge_amount*100; } if($pay_for_balance <500){ $pay_for_balance = 500; } if($pay_for_balance>3000){ $pay_for_balance = 3000; } $pay_for_balance = (int)$pay_for_balance; YqMove::create([ 'yq_uid'=>$result_data['uid'], 'zsy_uid'=>$uid, 'yq_distribution_channel_id'=>$result_data['user']['distribution_channel_id'], 'zsy_distribution_channel_id'=>$distribution_channel_id, 'read_count'=>$result_data['read_count'], 'yq_balance'=>$result_data['user']['balance'], 'is_pay'=>1, 'pay_for_balance'=>$pay_for_balance, 'openid'=>$openid, 'appid'=>$appid ]); $balance = $pay_for_balance+$result_data['user']['balance']; UserService::addBalance($uid,$balance,0,$balance); $this->movePush($distribution_channel_id,$pay_for_balance,$appid,$result_data['user']['distribution_channel_id'],$openid); } } }catch (\Exception $e){ } } private function movePush($distribution_channel_id,$pay_for_balance,$appid,$old_channel_id,$openid,$need_old=false){ $move_not_need_push_channel_id = env('MOVE_NOT_NEED_PUSH_CHANNEL_ID'); if($move_not_need_push_channel_id && in_array($distribution_channel_id,explode(',',$move_not_need_push_channel_id))){ return ; } $data = []; if($pay_for_balance){ if($need_old){ $format = "亲爱的用户:\r\n由于原小说站进行网站维护中,为了让您能够继续阅读更多优质小说,我们将在新站中补偿您%s书币,以表达我们诚挚的歉意\r\n\r\n点此进入新站\r\n\r\n继续老站阅读"; $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/'; $content = sprintf($format,$pay_for_balance,$url); }else{ $format = "亲爱的用户:\r\n由于原小说站进行网站维护中,为了让您能够继续阅读更多优质小说,我们将在新站中补偿您%s书币,以表达我们诚挚的歉意\r\n\r\n点此进入新站"; $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/'; //$old_url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($old_channel_id) . '.chunnuan555.com/continue'; $old_url = 'http://site' . encodeDistributionChannelId($old_channel_id) . '.imycmh.com/continue'; $content = sprintf($format,$pay_for_balance,$url,$old_url); } }else{ $fromat = "亲爱的用户:\r\n%s新增全新站点,新站拥有海量优质小说,同时原先站点可继续看书\r\n点此进入新站\r\n\r\n继续老站阅读"; $new_url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/'; //$old_url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($old_channel_id) . '.chunnuan555.com/continue'; $old_url = 'http://site' . encodeDistributionChannelId($old_channel_id) . '.imycmh.com/continue'; $offical = DB::table('official_accounts')->where('appid',$appid)->select('nickname')->first(); $offical_name = '网站'; if($offical && $offical->nickname){ $offical_name = $offical->nickname; } $content = sprintf($fromat,$offical_name,$new_url,$old_url); } $data['openid'] = $openid; $data['appid'] = $appid; $data['content'] = $content; $data['type'] = 'one_task'; $data['task_id'] = 1; $data['send_time'] = date("Y-m-d H:i:s"); $send_data=array( 'send_time'=>date("Y-m-d H:i:s"), 'data' => $data ); Log::info('movePush info'); Log::info($send_data); $delay = 0; $job = (new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'); dispatch($job); } private function smartPush(Request $request,$uid){ $bid = $request->get('bid'); $fromsource = $request->get('fromsource'); if(!$fromsource || !$bid){ return ; } if($fromsource != 'smart_push'){ return ; } $decode_bid_array = Hashids::decode($bid); if(!$decode_bid_array) return ; $decode_bid = 0; if(isset($decode_bid_array[0]) && !empty($decode_bid_array[0])){ $decode_bid = $decode_bid_array[0]; } if(!$decode_bid) return ; //记录pv uv try{ $uv_key = sprintf('%s_%s_uv',$decode_bid,'smart_push'); Redis::sadd($uv_key,$uid); Redis::HINCRBY('smart_push_test_book',$decode_bid,1); ReadRecordService::setSmartPush($uid,$decode_bid); }catch (\Exception $e){ Log::info($e); } } protected function notAccessPage(){ return '网站正在维护中

网站正在维护中,请联系客服

'; } private function fromTitleImage(Request $request,$uid){ $from_title_image = $request->get('from_title_image'); if($from_title_image){ $key = 'smart_push_from_title_image:'.$from_title_image; try{ Redis::hincrby($key ,'click_num', 1); Redis::sadd('smart_push_from_title_image_click_uv:'.$from_title_image,$uid); }catch (\Exception $e){} } } //短片推唱片 private function dataAnalysis(Request $request,$uid){ if(!$request->has('ru')){ return ; } $su = $request->get('ru'); if(!$su) return ; $su_array = explode('_',$su); if(count($su_array) !== 2){ return ; } $data = []; $arr = ['title'=>1,'over'=>2]; if(isset($arr[$su_array[0]])){ $data['type'] = $arr[$su_array[0]]; $data['material_id'] = $su_array[1]; $data['uid'] = $uid; $data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s'); try{ DB::table('data_analysis_visit_stats')->insert($data); }catch (\Exception $e){} } } /** * 临时统计 * @param Request $request * @param $uid */ private function tempFromWhere(Request $request,$uid){ $temp_from_where = env('TEMP_FROM_WHERE'); if(!$temp_from_where){ return ; } $from_where = $request->get('fromwhere'); if(!$from_where){ return ; } $url = $request->get('_url','0'); if(stripos($url,'reader') !== false){ $temp_from_where_start_end = explode(',',$temp_from_where); if(count($temp_from_where_start_end) == 2){ if(time() > $temp_from_where_start_end[0] && time()< $temp_from_where_start_end[1]){ try{ Redis::sadd('temp_from_where:'.$from_where,$uid); }catch (\Exception $e){} return ; } } } return ; } private function recordPrimaryNumberChannleIDUser($distribution_channel_id,$uid){ if(!is_numeric($distribution_channel_id)){ return ; } try{ Redis::sadd('recordPrimaryNumberChannleIDUser',$uid); }catch (\Exception $e){} } /** * 禁止site+数字站点的访问 保留已经充值过的用户和4267站点所有用户 * true禁止 false 不禁止 * @param $distribution_channel_id * @return bool */ private function isForbidPrimaryNumberChannleID($distribution_channel_id,$uid){ $forbid_primary_number_channel_id = env('FORBID_PRIMARY_NUMBER_CHANNEL_ID','14,2,4267'); if(is_numeric($distribution_channel_id) && !in_array($distribution_channel_id,explode(',',$forbid_primary_number_channel_id)) && !DB::table('orders')->where('uid',$uid)->where('status','PAID')->first() ){ return true; } return false; } /** * 特殊渠道的授权登陆 * @param Request $request * @return string */ private function authV2(Request $request,$channel_id){ if(!$request->has('auth')) return ''; $auth = $request->get('auth'); if($auth != 'v2'){ return ''; } $h5_scheme = env('PROTOCOL','https'); $domain = _domain(); $params['redirect_url'] = urlencode($h5_scheme . '://' . $domain . '/oauthCallBackV2'); $params['timestamp'] = time(); $info = specialChannelAuthInfo(); if(!$info || !isset($info[$channel_id]) ){ return ''; } $appid = $info[$channel_id]; if(!$appid){ return ''; } $params['gzh_app_id'] = $appid; $params['sign'] = $this->getSign($params, env('OAUTH_KEY')); $redirect = env('AUTH_URL') . '?' . http_build_query($params); return $redirect; } /** * @param Request $request * @param $channel_id * @return string */ private function auth(Request $request,$channel_id){ $appid = env('WECHAT_AUTH_APPID'); $h5_scheme = env('PROTOCOL','https'); $domain = _domain(); $params['redirect_url'] = urlencode($h5_scheme . '://' . $domain . '/oauthCallBack'); $params['timestamp'] = time(); $info = specialChannelAuthInfoV2(); if($info && isset($info[$channel_id]) && !empty($info[$channel_id]) ){ $appid = $info[$channel_id]; } $params['gzh_app_id'] = $appid; $params['sign'] = $this->getSign($params, env('OAUTH_KEY')); $redirect = env('AUTH_URL') . '?' . http_build_query($params); return $redirect; } }