Ver código fonte

auth reduce redircet debug 8

zz 6 anos atrás
pai
commit
4b1ce497ae

+ 64 - 4
app/Http/Controllers/Wap/Oauth/UsersV2Controller.php

@@ -68,10 +68,7 @@ class UsersV2Controller extends Controller
         $unionid = $user_data['unionid'];
         $user = UserService::getUserByUnionAndChannelId($openid,$distribution_channel_id);
         !isset($url_info['path']) && $url_info['path'] = '/';
-        if(array_key_exists($distribution_channel_id,specialChannelAuthInfo())){
-            //$url = urldecode($url);
-            //return redirect()->to($this->joinUrl($url));
-        }
+
         !$user && $user = $this->createUser($openid,$unionid,$distribution_channel_id,$send_order_id);
 
         $query = ['auth_uid'=>$user->id,'atime'=>time()];
@@ -84,6 +81,69 @@ class UsersV2Controller extends Controller
         return redirect()->to($url)->withHeaders(['referer'=>url()->current()]);
     }
 
+    public function wcCallbackParse2(Request $request){
+        Log::info('UsersV2Controller--wcCallbackParse--enter-----------');
+        Log::info($request->all());
+        $appid = $request->get('appid');
+        $secret = $this->getAppSecretByAppId($appid);
+        $url = $request->get('redirect_url');
+        $distribution_channel_id = $request->get('channel_id');
+        $send_order_id = $request->get('sid');
+        $auth_times = $request->get('auth_times',1);
+        $url = urldecode($url);
+        $options = [
+            'app_id'=>$appid,
+            'secret'=>$secret,
+        ];
+        $url_info = parse_url($url);
+        $app = new Application($options);
+
+        $user = $app->oauth->user();
+        $user_data = $user['original'];
+        Log::info('$user_data is: ');
+        Log::info($user_data);
+        if(!isset($user_data['unionid'])){
+            $user_data['unionid'] = $user_data['openid'];
+        }
+        $openid = $user_data['openid'];
+        $unionid = $user_data['unionid'];
+        $user = UserService::getUserByUnionAndChannelId($openid,$distribution_channel_id);
+        !isset($url_info['path']) && $url_info['path'] = '/';
+
+        if(!$user){
+            $auth_redirect_two_appids = specialChannelAuthInfo();
+            if($auth_times == 1 && $auth_redirect_two_appids && isset($auth_redirect_two_appids[$distribution_channel_id])){
+                $params['redirect_url'] = $request->get('redirect_url');
+                $params['timestamp'] = time();
+                $params['channel_id'] = $distribution_channel_id;
+                $params['appid'] = $auth_redirect_two_appids[$distribution_channel_id];
+                $params['sid'] = $send_order_id;
+                $params['auth_times'] = 2;
+                //$params['sign'] = $this->getSign($params, env('OAUTH_KEY'));
+                $secret = $this->getAppSecretByAppId($auth_redirect_two_appids[$distribution_channel_id]);
+                $options = [
+                    'app_id' => $appid,
+                    'secret' => $secret,
+                    'oauth' => [
+                        'scopes' => ['snsapi_base'],
+                        'callback' => env('AUTH_CALLBACK_URL') . '?' . http_build_query($params),],];
+                $app = new Application($options);
+                return $app->oauth->redirect();
+            }else{
+                $user = $this->createUser($openid,$unionid,$distribution_channel_id,$send_order_id);
+            }
+        }
+
+        $query = ['auth_uid'=>$user->id,'atime'=>time()];
+        $sign = get_sign($query);
+        $query['sign'] = $sign;
+        $url = sprintf('%s://%s%s?%s',$url_info['scheme'],$url_info['host'],$url_info['path'],http_build_query($query));
+        Log::info('wcCallbackParse back url is :');
+        Log::info($url);
+        //$previous = url()->previous();
+        return redirect()->to($url);
+    }
+
     private function createUser($openid,$unionid,$distribution_channel_id,$send_order_id){
         $user =  UserService::addUser(
             ['openid' => $openid,

+ 155 - 124
app/Http/Middleware/ReadOauth.php

@@ -42,7 +42,7 @@ class ReadOauth
         }
 
         $uid_cookie = Cookie::get(env('COOKIE_AUTH_WEB_WECHAT'));
-        if(!$uid_cookie) $uid_cookie = $this->authCallBack($request);
+        if (!$uid_cookie) $uid_cookie = $this->authCallBack($request);
 
         $h5_scheme = env('H5_SCHEME', 'https');
         $params = $request->except('_url');
@@ -76,57 +76,32 @@ class ReadOauth
         $yun = $request->get('yun');
         $yun && $uri_send_order_id = $yun;
         if (!$uid_cookie && $test == 0) {
-            $params = [];
-            if($uri_send_order_id){
+            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);
-            Cookie::queue('auth_redirect', urlencode($url), env('U_COOKIE_EXPIRE'));
-            $appid = env('WECHAT_AUTH_APPID');
-            $params['redirect_url'] = urlencode($url);
-            $params['timestamp'] = time();
-            $params['channel_id'] = $distribution_channel_id;
-            $params['gzh_app_id'] = $appid;
-            $params['appid'] = $appid;
-            $params['sid'] = $uri_send_order_id;
-            $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);
-            }*/
-
-            $info = DB::table('official_setting')->where('appid',$appid)->select('secret')->first();
-            if($info && $info->secret){
-                $secter = $info->secret;
-            }else{
-                $secter = '';
-                abort(404);
-            }
 
-            $options = [
-                'app_id'=>env('WECHAT_AUTH_APPID'),
-                'secret'=>$secter,
-                'oauth' => [
-                    'scopes'   => ['snsapi_base'],
-                    'callback' => env('AUTH_CALLBACK_URL').'?'.http_build_query($params),
-                ],
-            ];
-            Log::info('$options is:');
-            Log::info($options);
-            $app = new Application($options);
-            return $app->oauth->redirect();
-            //return redirect()->to($redirect);
+            if (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);
+                return $app->oauth->redirect();
+            }
         }
 
         //个性化推送
-        $this->stylePush($request,$uid_cookie,$distribution_channel_id);
+        $this->stylePush($request, $uid_cookie, $distribution_channel_id);
 
         //禁止明文访问
         if ($this->isForbidPrimaryNumberChannleID($origin_distribution_channel_id, $uid_cookie)) {
@@ -143,7 +118,7 @@ class ReadOauth
              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,$uri_send_order_id);
+                $this->apidAndOpenId($distribution_channel_id, $appid, $openid, $uid_cookie, $uri_send_order_id);
                 $channel = ChannelService::getById($distribution_channel_id);
                 $is_yq_move = $this->isQyMove($channel, $distribution_channel_id);
                 if ($is_yq_move) {
@@ -172,7 +147,7 @@ class ReadOauth
             //Log::info('url is: '.$qy_test_url);
             return redirect()->to($qy_test_url);
         }*/
-        $this->yun($request,$uid_cookie,$distribution_channel_id);
+        $this->yun($request, $uid_cookie, $distribution_channel_id);
         //只能推送的统计
         $this->smartPush($request, $uid_cookie);
         //数据分析 长篇推短片的统计
@@ -345,7 +320,7 @@ class ReadOauth
         return $arg;
     }
 
-    private function apidAndOpenId($distribution_channel_id, $appid, $openid, $uid,$send_order_id)
+    private function apidAndOpenId($distribution_channel_id, $appid, $openid, $uid, $send_order_id)
     {
         $appid_info = OfficialAccountService::officialAccountByAppid(['appid' => $appid]);
         if (!$appid_info)
@@ -379,7 +354,7 @@ class ReadOauth
             'openid' => $openid,
             'official_account_id' => 1
         ];
-        if($send_order_id){
+        if ($send_order_id) {
             $forcesubuserdata['send_order_id'] = $send_order_id;
         }
         if ($user_info) {
@@ -394,8 +369,8 @@ class ReadOauth
 
         ForceSubscribeService::tempForceSubscribeUsersLastTimeUpdate([
             'openid' => $openid,
-        	'appid' => $appid,
-        	'distribution_channel_id' => $distribution_channel_id,
+            'appid' => $appid,
+            'distribution_channel_id' => $distribution_channel_id,
             'last_interactive_time' => date('Y-m-d H:i:s')
         ]);
 
@@ -787,41 +762,44 @@ class ReadOauth
     }
 
     //个性化推送
-    private function stylePush(Request $request,$uid,$distribution_channel_id){
+    private function stylePush(Request $request, $uid, $distribution_channel_id)
+    {
         $gxhp = $request->get('gxhp');
-        if(!$gxhp || !$uid || !$distribution_channel_id) return ;
+        if (!$gxhp || !$uid || !$distribution_channel_id) return;
 
         $date = date('Y-m-d');
-        $uv_key = sprintf('push:stylepush:uv:%s:gxhp:%s:date:%s',$distribution_channel_id,$gxhp,$date);
-        $pv_key = sprintf('push:stylepush:pv:%s:gxhp:%s:date:%s',$distribution_channel_id,$gxhp,$date);
-        try{
+        $uv_key = sprintf('push:stylepush:uv:%s:gxhp:%s:date:%s', $distribution_channel_id, $gxhp, $date);
+        $pv_key = sprintf('push:stylepush:pv:%s:gxhp:%s:date:%s', $distribution_channel_id, $gxhp, $date);
+        try {
             Redis::hset('book_read:' . $uid, 'gxhp', $gxhp);
             Redis::sadd($uv_key, $uid);
             Redis::incr($pv_key);
-            Redis::sadd(sprintf('push:stylepush:date:%s',$date),sprintf('%s_%s',$distribution_channel_id,$gxhp));
-        }catch (\Exception $e){}
+            Redis::sadd(sprintf('push:stylepush:date:%s', $date), sprintf('%s_%s', $distribution_channel_id, $gxhp));
+        } catch (\Exception $e) {
+        }
     }
-    private function yqTest(Request $request, $uid,$channel_id)
+
+    private function yqTest(Request $request, $uid, $channel_id)
     {
         if (!$request->has('fromtype')) return '';
         $from_type = $request->get('fromtype');
-        if(empty($from_type)){
+        if (empty($from_type)) {
             return '';
         }
-        if($from_type == 'main'){
+        if ($from_type == 'main') {
             return '';
         }
-        if($request->has('r') ){
+        if ($request->has('r')) {
             return '';
         }
         //Log::info('1111111111111111111111111111111');
         $param = $request->except('_url');
-        if (isset($param['bid']))  unset($param['bid']);
-        if(isset($param['cid']))  unset($param['cid']);
+        if (isset($param['bid'])) unset($param['bid']);
+        if (isset($param['cid'])) unset($param['cid']);
         //unset($param['from_type']);
         $other_str = 'r=1';
-        if($param){
-            $other_str = http_build_query($param).'&'.$other_str;
+        if ($param) {
+            $other_str = http_build_query($param) . '&' . $other_str;
         }
         //$uri = $request->input('_url');
         $bid = $request->get('bid');
@@ -841,28 +819,28 @@ class ReadOauth
             return '';
         }
         $flag = $yq_book_user->flag;
-        if(empty($flag)){
+        if (empty($flag)) {
             return '';
         }
         //Log::info('44444444444444444444444444444');
         //如果是group_1 不错操作
-        if($flag == 'group_1'){
-            YqUserBidRelationService::create($uid,$bid,'GROUP_1',0);
-            if ($yq_book_user->type == 'INIT'){
-                BookUserService::updateUser($uid, ['type'=>'GROUP_1']);
+        if ($flag == 'group_1') {
+            YqUserBidRelationService::create($uid, $bid, 'GROUP_1', 0);
+            if ($yq_book_user->type == 'INIT') {
+                BookUserService::updateUser($uid, ['type' => 'GROUP_1']);
             }
             return '';
         }
         //Log::info('5555555555555555555555555555');
-        if($flag != 'group_2'){
+        if ($flag != 'group_2') {
             return '';
         }
         //Log::info('66666666666666666666666666666');
         //用户的类型是初始类型  区域还没获取
         if ($yq_book_user->type == 'INIT') {
-            if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']){
+            if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
                 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
-            }else{
+            } else {
                 $ip = get_client_ip();
             }
             $area = $this->getIpArea($ip);
@@ -872,7 +850,7 @@ class ReadOauth
             if ('ENABLE' == $type) {
                 $yq_zsy_test = YqZsyTestService::getByBid($bid);
                 if ($yq_zsy_test) {
-                    YqUserBidRelationService::create($uid,$bid,'GROUP_2',$bid);
+                    YqUserBidRelationService::create($uid, $bid, 'GROUP_2', $bid);
                     //书在测试列表中
                     $data['bid'] = $bid;
                     BookUserService::updateUser($uid, $data);
@@ -881,7 +859,7 @@ class ReadOauth
                 //Log::info('7777777777777777777777777');
                 //书不在在测试列表中
                 //获取随机获取一本书,获取不到则返回
-                $redirect_bids = YqZsyTestService::getRandomBooks($uid,1);
+                $redirect_bids = YqZsyTestService::getRandomBooks($uid, 1);
                 $redirect_bid = 0;
                 if ($redirect_bids && isset($redirect_bids[0])) {
                     $redirect_bid = $redirect_bids[0];
@@ -894,13 +872,13 @@ class ReadOauth
                 //Log::info($redirect_bids);
                 $redirect_book_info = BookConfigService::getBookById($redirect_bid);
                 if ($redirect_book_info) {
-                    $redirect = $this->getBookReaderUrl($redirect_bid,$channel_id);
-                    if($redirect){
+                    $redirect = $this->getBookReaderUrl($redirect_bid, $channel_id);
+                    if ($redirect) {
                         $data['bid'] = $redirect_bid;
                     }
-                    YqUserBidRelationService::create($uid,$bid,'GROUP_2',$redirect_bid);
+                    YqUserBidRelationService::create($uid, $bid, 'GROUP_2', $redirect_bid);
                     BookUserService::updateUser($uid, $data);
-                    return $redirect.'&'.$other_str;
+                    return $redirect . '&' . $other_str;
                 }
                 //Log::info('9999999999999999999999999');
                 return '';
@@ -914,33 +892,33 @@ class ReadOauth
             }
             //Log::info('aaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
         }
-        if($yq_book_user->type == 'DISABLED'){
+        if ($yq_book_user->type == 'DISABLED') {
             return '';
         }
         //Log::info('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
         $yq_zsy_test = YqZsyTestService::getByBid($bid);
         //如果书在测试样本中 不跳转
         if ($yq_zsy_test) {
-            YqUserBidRelationService::create($uid,$bid,'GROUP_2',0);
+            YqUserBidRelationService::create($uid, $bid, 'GROUP_2', 0);
             return '';
         }
         //Log::info('ccccccccccccccccccccccccccccc');
         // 用户符合条件 且看的书不样本中
-        $relate_info = YqUserBidRelationService::getByUidAndBid($uid,$bid);
-        if($relate_info && $relate_info->to_bid){
+        $relate_info = YqUserBidRelationService::getByUidAndBid($uid, $bid);
+        if ($relate_info && $relate_info->to_bid) {
             //已经有对应关系
             //如果有阅读记录
-            $record_url = $this->readerRecpord($uid,$relate_info->to_bid,$channel_id);
-            if($record_url) return $record_url.'&'.$other_str;
+            $record_url = $this->readerRecpord($uid, $relate_info->to_bid, $channel_id);
+            if ($record_url) return $record_url . '&' . $other_str;
             //没有阅读记录
-            $book_url = $this->getBookReaderUrl($relate_info->to_bid,$channel_id);
+            $book_url = $this->getBookReaderUrl($relate_info->to_bid, $channel_id);
             //Log::info('dddddddddddddddddddddddddd');
             //Log::info($book_url.'&'.$other_str);
-            return $book_url.'&'.$other_str;
-        }else{
+            return $book_url . '&' . $other_str;
+        } else {
             //没有对应关系
             //随机获取一本书
-            $redirect_bids = YqZsyTestService::getRandomBooks($uid,1);
+            $redirect_bids = YqZsyTestService::getRandomBooks($uid, 1);
             $redirect_bid = 0;
             if ($redirect_bids && isset($redirect_bids[0])) {
                 $redirect_bid = $redirect_bids[0];
@@ -949,21 +927,22 @@ class ReadOauth
                 return '';
             };
             //Log::info('eeeeeeeeeeeeeeeeeeeeeeeeeeeee');
-            $redirect = $this->getBookReaderUrl($redirect_bid,$channel_id);
-            if($redirect){
+            $redirect = $this->getBookReaderUrl($redirect_bid, $channel_id);
+            if ($redirect) {
                 $data['bid'] = $redirect_bid;
                 //更新对应关系
                 BookUserService::updateUser($uid, $data);
                 //Log::info('ffffffffffffffffffffffff');
-                YqUserBidRelationService::create($uid,$bid,'GROUP_2',$redirect_bid);
-                return $redirect.'&'.$other_str;
+                YqUserBidRelationService::create($uid, $bid, 'GROUP_2', $redirect_bid);
+                return $redirect . '&' . $other_str;
             }
             //Log::info('gggggggggggggggggggggggggggggggg');
             return '';
         }
     }
 
-    private function getBookReaderUrl($bid,$channel_id){
+    private function getBookReaderUrl($bid, $channel_id)
+    {
         $redirect_book_info = BookConfigService::getBookById($bid);
         if ($redirect_book_info) {
             //Log::info('getBookReaderUrl');
@@ -979,7 +958,8 @@ class ReadOauth
         return '';
     }
 
-    private function readerRecpord($uid,$bid,$channel_id){
+    private function readerRecpord($uid, $bid, $channel_id)
+    {
         $record_info = null;
         try {
             $record_info = ReadRecordService::getRecordByUidBid($uid, $bid);
@@ -992,7 +972,7 @@ class ReadOauth
 
         if (isset($record_info_arr[0])) {
             $cid = $record_info_arr[0];
-            if(!$cid) return '';
+            if (!$cid) return '';
             $redirect = sprintf(
                 'https://site%s.iycdm.com/reader?bid=%s&cid=%s',
                 encodeDistributionChannelId($channel_id),
@@ -1003,14 +983,15 @@ class ReadOauth
         }
         return '';
     }
+
     private function isLimit($area)
     {
-        if($area == 'unknown'){
+        if ($area == 'unknown') {
             return 'DISABLED';
         }
-        $limit_area = ['上海', '北京','杭州','南京','广州'];
+        $limit_area = ['上海', '北京', '杭州', '南京', '广州'];
         foreach ($limit_area as $a) {
-            Log::info('$area: '.$area.',$a: '.$a.PHP_EOL);
+            Log::info('$area: ' . $area . ',$a: ' . $a . PHP_EOL);
             if (mb_strpos($area, $a) !== false) {
                 return 'DISABLED';
             }
@@ -1037,29 +1018,30 @@ class ReadOauth
         return $area;
     }
 
-    private function yun(Request $request,$uid,$distribution_channel_id){
+    private function yun(Request $request, $uid, $distribution_channel_id)
+    {
         $uri = $request->input('_url');
         if ($uri && strpos($uri, '/yun/') !== false) {
-            return ;
+            return;
         }
         $param = $request->get('yun');
         //Log::info('$param is : '.$param);
-        if(!$param) return ;
+        if (!$param) return;
         $bid = $request->get('bid');
         //Log::info('$bid = $request is : '.$bid);
         $send_order_info = SendOrderService::getRedirectUrlById($param);
         //Log::info('$send_order_info  is : ');
         //Log::info($send_order_info);
-        if($bid){
+        if ($bid) {
             $bid_arr = Hashids::decode($bid);
             isset($bid_arr[0]) && $bid = $bid_arr[0];
         }
         //Log::info('bid is'.$bid);
-        if(!$send_order_info) return ;
-        if($send_order_info->book_id &&  $send_order_info->book_id != $bid) return ;
-        if($send_order_info->distribution_channel_id != $distribution_channel_id) return ;
+        if (!$send_order_info) return;
+        if ($send_order_info->book_id && $send_order_info->book_id != $bid) return;
+        if ($send_order_info->distribution_channel_id != $distribution_channel_id) return;
 
-        is_numeric($bid) && $this->specialChannelIdStats($param,$distribution_channel_id,$uid,$bid);
+        is_numeric($bid) && $this->specialChannelIdStats($param, $distribution_channel_id, $uid, $bid);
         $key = date('Y-m-d');
         Cookie::queue('send_order_id', $param, env('U_COOKIE_EXPIRE'), null, null, false, false);
         $send_order_flag = Cookie::get('send_order_flag');
@@ -1087,7 +1069,7 @@ class ReadOauth
 
         $uv = Redis::hget('send_order_uv_' . $param, $key);
 
-        $uv && $uv>=20 && SendOrderService::updateSendOrderTime($param);
+        $uv && $uv >= 20 && SendOrderService::updateSendOrderTime($param);
     }
 
     /**
@@ -1102,29 +1084,78 @@ class ReadOauth
         int $distribution_channel_id,
         int $uid,
         int $bid
-    ):void{
+    ):void
+    {
 
-        if(!$bid || !$distribution_channel_id || !$uid || !$send_order_id)
-            return ;
-        $specialChannelIdStats = env('SPECIAL_CHANNEL_STATS',211);
-        if(!in_array($distribution_channel_id,explode(',',$specialChannelIdStats)) ){
-            return ;
+        if (!$bid || !$distribution_channel_id || !$uid || !$send_order_id)
+            return;
+        $specialChannelIdStats = env('SPECIAL_CHANNEL_STATS', 211);
+        if (!in_array($distribution_channel_id, explode(',', $specialChannelIdStats))) {
+            return;
         }
-        WapVisitStatService::specialChannelIdStatsMarkUser($uid,$bid,$send_order_id);
-        return ;
+        WapVisitStatService::specialChannelIdStatsMarkUser($uid, $bid, $send_order_id);
+        return;
     }
 
-    private function authCallBack(Request $request){
-        Log::info('----------------------------------------------------------');
-        Log::info($request->header());
+    private function authCallBack(Request $request)
+    {
         $auth_uid = $request->get('auth_uid');
         $atime = $request->get('atime');
         $sign = $request->get('sign');
-        if(!$auth_uid || !$atime || !$sign) return 0;
-        if(!is_numeric($auth_uid) || !is_numeric($atime)) return 0;
-        if( (time()-$atime) >20) return 0;
-        if(get_sign(compact('auth_uid','atime')) !== $sign ) return 0;
+        if (!$auth_uid || !$atime || !$sign) return 0;
+        if (!is_numeric($auth_uid) || !is_numeric($atime)) return 0;
+        if ((time() - $atime) > 20) return 0;
+        if (get_sign(compact('auth_uid', 'atime')) !== $sign) return 0;
         Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), $auth_uid, env('U_COOKIE_EXPIRE'), null, null, false, false);
         return $auth_uid;
     }
+
+    private function getAppSecretByAppId($appId)
+    {
+        $info = DB::table('official_setting')->where('appid', $appId)->select('secret')->first();
+        if ($info) {
+            return $info->secret;
+        }
+        return '';
+    }
+
+    private function authReduceRedirect(Request $request,$distribution_channel_id,$send_order_id){
+        $h5_scheme = env('H5_SCHEME', 'https');
+        $params = $request->except('_url');
+        $url = str_replace('http://', $h5_scheme . '://', url()->current() . '?' . http_build_query($params));
+        $params['redirect_url'] = urlencode($url);
+        $params['timestamp'] = time();
+        $params['channel_id'] = $distribution_channel_id;
+        $params['sid'] = $send_order_id;
+        $params['sign'] = $this->getSign($params, env('OAUTH_KEY'));
+
+        //新的授权
+        $auth_redirect_one_appids = specialChannelAuthInfoV2();
+        $auth_redirect_two_appids = specialChannelAuthInfo();
+        if($auth_redirect_one_appids && isset($auth_redirect_one_appids[$distribution_channel_id])){
+            //授权一次
+            $callback = env('AUTH_CALLBACK_URL_V2');
+            $appid = $auth_redirect_one_appids[$distribution_channel_id];
+        }elseif($auth_redirect_two_appids && isset($auth_redirect_two_appids[$distribution_channel_id]) ){
+            //授权二次
+            $callback = env('AUTH_CALLBACK_URL_V2_2');
+            $appid = $auth_redirect_two_appids[$distribution_channel_id];
+        }else{
+            //默认授权
+            $callback = env('AUTH_CALLBACK_URL_V2');
+            $appid = env('WECHAT_AUTH_APPID');
+        }
+        $params['appid'] = $appid;
+        $secret = $this->getAppSecretByAppId($appid);
+
+        $options = [
+            'app_id' => $appid,
+            'secret' => $secret,
+            'oauth' => [
+                'scopes' => ['snsapi_base'],
+                'callback' => $callback . '?' . http_build_query($params),
+            ],
+        ];
+        return $options;
+    }
 }

+ 1 - 0
app/Http/Routes/Wap/WapRoutes.php

@@ -23,6 +23,7 @@ Route::group(['domain'=>env('OFFICIAL_AUTH_FOMAIN'),'namespace'=>'App\Http\Contr
 
     Route::any('/user_oauth_v2','Oauth\UsersV2Controller@user_oauth');
     Route::get('/wxAuthCallBackv2','Oauth\UsersV2Controller@wcCallbackParse');
+    Route::get('/wxAuthCallBack2v2','Oauth\UsersV2Controller@wcCallbackParse2');
 });
 
 Route::group(['domain'=>env('HELP_DOMAIN'),'namespace'=>'App\Http\Controllers\Wap\Help'],function(){