|
@@ -0,0 +1,117 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\Wap\Oauth;
|
|
|
+
|
|
|
+use App\Modules\User\Services\WapReaderPageFissionService;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use Cookie;
|
|
|
+use App\Modules\User\Services\UserService;
|
|
|
+use Log;
|
|
|
+use EasyWeChat\Foundation\Application;
|
|
|
+use DB;
|
|
|
+use Hashids;
|
|
|
+
|
|
|
+class UsersV2Controller extends Controller
|
|
|
+{
|
|
|
+ public function user_oauth(Request $request){
|
|
|
+ Log::info('UsersV2Controller--user_oauth--enter-----------');
|
|
|
+ Log::info($request->all());
|
|
|
+ $url = $request->get('redirect_url');
|
|
|
+ $appid = $request->get('gzh_app_id');
|
|
|
+ $channel_id = $request->get('channel_id');
|
|
|
+ $sid = $request->get('sid');
|
|
|
+ $secter = $this->getAppSecretByAppId($appid);
|
|
|
+ $params['appid'] = $appid;
|
|
|
+ $params['redirect_url'] = $url;
|
|
|
+ $params['channel_id'] = $channel_id;
|
|
|
+ $params['sid'] = $sid;
|
|
|
+ $options = [
|
|
|
+ 'app_id'=>$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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function wcCallbackParse(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');
|
|
|
+ $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(array_key_exists($distribution_channel_id,specialChannelAuthInfo())){
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ !$user && $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['hostname'],$url_info['path'],http_build_query($query));
|
|
|
+ Log::info('wcCallbackParse back url is :');
|
|
|
+ Log::info($url);
|
|
|
+ return redirect()->to($url);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function createUser($openid,$unionid,$distribution_channel_id,$send_order_id){
|
|
|
+ $user = UserService::addUser(
|
|
|
+ ['openid' => $openid,
|
|
|
+ 'unionid' => $unionid,
|
|
|
+ 'distribution_channel_id' =>$distribution_channel_id,
|
|
|
+ 'send_order_id'=>$send_order_id,
|
|
|
+ 'is_new'=>1
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $action_type = 'Register';
|
|
|
+ $param = [
|
|
|
+ 'openid' => $openid,
|
|
|
+ 'uid' => isset($user->id)?$user->id:'0',
|
|
|
+ ];
|
|
|
+ UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
|
|
|
+ return $user;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 根据apid获取secret
|
|
|
+ * @param $appId
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private function getAppSecretByAppId($appId){
|
|
|
+ $info = DB::table('official_setting')->where('appid',$appId)->select('secret')->first();
|
|
|
+ if($info){
|
|
|
+ return $info->secret;
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+}
|