dever 6 năm trước cách đây
mục cha
commit
3a34f11214
1 tập tin đã thay đổi với 55 bổ sung4 xóa
  1. 55 4
      lib/Client.php

+ 55 - 4
lib/Client.php

@@ -20,6 +20,12 @@ class Client extends Base
 	 */
 	protected $session = null;
 
+	/**
+	 * @desc passport
+	 * @var object
+	 */
+	protected $passport = null;
+
 	/**
 	 * @desc request
 	 * @var array
@@ -35,14 +41,21 @@ class Client extends Base
 	public function __construct()
 	{
 		parent::__construct();
+		$this->initPassport();
 		$this->initSave();
 		$this->initRequest();
 		$this->initAccount();
 		$this->initSource();
+		$this->initSourceType();
 		$this->initRefer();
 		$this->initConfig();
 	}
 
+	private function initPassport()
+	{
+		$this->passport = Dever::load('passport/lib/base');
+	}
+
 	private function initSave()
 	{
 		$this->session = new Save(DEVER_PROJECT, 'session');
@@ -59,6 +72,18 @@ class Client extends Base
 		$this->session->add('oauth_account', $this->account);
 	}
 
+	private function initSystem()
+	{
+		$this->system = (isset($this->request['system']) && $this->request['system']) ? $this->request['system'] : $this->session->get('oauth_system');
+		$this->session->add('oauth_system', $this->system);
+	}
+
+	private function initSourceType()
+	{
+		$this->source_type = (isset($this->request['source_type']) && $this->request['source_type']) ? $this->request['source_type'] : $this->session->get('oauth_source_type');
+		$this->session->add('oauth_source_type', $this->source_type);
+	}
+
 	private function initSource()
 	{
 		$this->source = (isset($this->request['source']) && $this->request['source']) ? $this->request['source'] : $this->session->get('oauth_source');
@@ -152,9 +177,10 @@ class Client extends Base
 			
 			if (isset($this->config['token']['response'])) {
 				# 进入绑定流程吧
-				$this->bind();
+				return $this->bind();
 			}
 		}
+		Dever::alert('登录失败');
 	}
 	
 	/**
@@ -202,11 +228,16 @@ class Client extends Base
 			$id = $get['id'];
 		}
 		
-		$this->update($data, $id);
+		$user = $this->update($data, $id);
 		# 跳转吧,从哪来去哪吧
 		if ($this->refer) {
 			$refer = urldecode($this->refer);
 			Dever::location($refer);
+		} else {
+			$result = $user;
+	        $result['uid'] = $user['id'];
+	        $result['signature'] = Dever::login($user['id']);
+	        return $result;
 		}
 	}
 
@@ -262,6 +293,12 @@ class Client extends Base
             }
             if (!$uid) {
             	$user['source_type'] = 'service';
+            	if ($this->system) {
+					$user['system_id'] = $this->system;
+	            }
+	            if ($this->source_type) {
+					$user['source_type'] = $this->source_type;
+	            }
                 $uid = Dever::load('passport/user-insert', $user);
             } else {
                 $user['where_id'] = $uid;
@@ -273,8 +310,17 @@ class Client extends Base
             $wechat['expires_in'] = $data['expires_in'];
             $wechat['refresh_token'] = $data['refresh_token'];
             $wechat['account_id'] = $this->account;
+            if ($this->system) {
+				$wechat['system_id'] = $this->system;
+            }
+            
             $wechat['uid'] = $uid;
             $wechat['type'] = 2;
+            if ($this->source_type == 'ios') {
+            	$wechat['type'] = 3;
+            } elseif ($this->source_type == 'android') {
+            	$wechat['type'] = 4;
+            }
             $id = Dever::load('passport/wechat-insert', $wechat);
 
             if (Dever::project('source') && isset($this->source) && $this->source && $this->source > 0) {
@@ -284,6 +330,8 @@ class Client extends Base
             $uid = $info['uid'];
             if (isset($data['unionid']) && $data['unionid']) {
                 $wechat['unionid'] = $data['unionid'];
+                # 判断用户是否存在,是否需要合并
+                $wechat['uid'] = $this->passport->combine($uid, $data['unionid']);
             }
             
             $wechat['access_token'] = $data['access_token'];
@@ -292,6 +340,9 @@ class Client extends Base
             $wechat['refresh_token'] = $data['refresh_token'];
             $wechat['where_id'] = $info['id'];
             $wechat['account_id'] = $this->account;
+            if ($this->system) {
+            	$wechat['system_id'] = $this->system;
+            }
             $id = $info['id'];
             Dever::load('passport/wechat-update', $wechat);
 
@@ -299,13 +350,13 @@ class Client extends Base
             Dever::load('passport/user-update', $user);
         }
 
-        Dever::load('passport/api')->createUsername($uid, $user['username']);
+        $this->passport->createUsername($uid, $user['username']);
 
         $user = Dever::load('passport/user-one', $uid);
 
         $this->save($user);
 
-        return $uid;
+        return $user;
 	}
 	
 	/**