cookieNoCrypt(); $test = 0; if ($request->has('test') && $request->input('test') == 'bonan') { $test = 1; } $uid_cookie = Cookie::get(env('COOKIE_AUTH_WEB_WECHAT')); if (!$uid_cookie) $uid_cookie = $this->authCallBack($request); $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'); } $uri_send_order_id = 0; $uri = $request->input('_url'); if (strpos($uri, '/yun/') !== false) { $uri_send_order_id = (int)str_ireplace('/yun/', '', $uri); } $yun = $request->get('yun'); $yun && $uri_send_order_id = $yun; if (!$uid_cookie && $test == 0) { if ($uri_send_order_id) { Cookie::queue('send_order_id', $uri_send_order_id, env('U_COOKIE_EXPIRE'), null, null, false, false); } $this->share($request); $old_auth = false; if ($old_auth && !in_array($distribution_channel_id, explode(',', env('NEW_AUTH_CHANNEL_ID', 1)))) { //旧的授权 Cookie::queue('auth_redirect', urlencode($url), env('U_COOKIE_EXPIRE')); $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); } } else { //新的授权 $options = $this->authReduceRedirect($request,$distribution_channel_id,$uri_send_order_id); $app = new Application($options); //Log::info($options); return $app->oauth->redirect(); } } //禁止访问的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) && !OrderService::isPaidUser($uid_cookie)) { return response($this->notAccessPage())->header('Content-Type', 'text/html'); } } //个性化推送 //$this->stylePush($request, $uid_cookie, $distribution_channel_id); //禁止明文访问 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'); if ($openid && $appid && $distribution_channel_id && $uid_cookie) { $this->apidAndOpenId($distribution_channel_id, $appid, $openid, $uid_cookie, $uri_send_order_id); } } $this->yun($request, $uid_cookie, $distribution_channel_id); //只能推送的统计 $this->smartPush($request, $uid_cookie); //from where的临时统计 $this->tempFromWhere($request, $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); } //crm $this->crmParam($request); //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 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, $send_order_id) { $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::forceSubscribeUsersByUidAndAppid($appid, $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 ($send_order_id) { $forcesubuserdata['send_order_id'] = $send_order_id; } 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['nick_name'] = $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, 'appid' => $appid, 'distribution_channel_id' => $distribution_channel_id, 'last_interactive_time' => date('Y-m-d H:i:s') ]); try { $send_data = array( 'type' => 'subscribe', 'data' => ['openid'=>'','uid'=>$uid] ); $send = new SendStatisticsList($send_data); $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list'); dispatch($job); } catch (\Exception $e) { Log::info($e); } return true; } 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 '网站正在维护中,请联系客服