|
|
@ -14,7 +14,7 @@ class mUser extends mBase { |
|
|
|
$this->tbl = 'tcm_user'; |
|
|
|
} |
|
|
|
|
|
|
|
public function getUid($code) { |
|
|
|
public function getUserInfo($code) { |
|
|
|
$openid = $this->getOpenid($code); |
|
|
|
if (!$openid) { |
|
|
|
$this->setError('获取openid失败'); |
|
|
@ -22,23 +22,23 @@ class mUser extends mBase { |
|
|
|
} |
|
|
|
|
|
|
|
$user = $this->getUserByOpenid($openid); |
|
|
|
if ($user) return $user['uid']; |
|
|
|
if ($user) return $user; |
|
|
|
|
|
|
|
//获取唯一uid串 |
|
|
|
$uid = $this->createUniqueUid($openid); |
|
|
|
$user = $this->getUserByUid($uid); |
|
|
|
$identifier = $this->createUniqueID($openid); |
|
|
|
$user = $this->getUserByIdentifier($identifier); |
|
|
|
if ($user) { |
|
|
|
$this->setError('uid生成失败'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
$id = $this->createUser(array('uid' => $uid, 'openid' => $openid)); |
|
|
|
if (!$id) { |
|
|
|
$uid = $this->createUser(array('identifier' => $identifier, 'openid' => $openid)); |
|
|
|
if (!$uid) { |
|
|
|
$this->setError('用户创建失败'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return $id; |
|
|
|
return $this->getUserByUid($uid); |
|
|
|
} |
|
|
|
|
|
|
|
public function getOpenid($code) { |
|
|
@ -63,13 +63,17 @@ class mUser extends mBase { |
|
|
|
return $this->obj->select($this->tbl, array('sql' => '`openid`=?', 'vals' => array($openid))); |
|
|
|
} |
|
|
|
|
|
|
|
function createUniqueUid($openid) { |
|
|
|
function createUniqueID($openid) { |
|
|
|
$uuid = uniqid($openid, true); |
|
|
|
$hash = hash('sha256', $uuid); |
|
|
|
$decimal = base_convert(substr($hash, 0, 16), 16, 10); |
|
|
|
return substr($decimal, 0, 10); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUserByIdentifier($identifier) { |
|
|
|
return $this->obj->select($this->tbl, array('sql' => '`identifier`=?', 'vals' => array($identifier))); |
|
|
|
} |
|
|
|
|
|
|
|
public function getUserByUid($uid) { |
|
|
|
return $this->obj->select($this->tbl, array('sql' => '`uid`=?', 'vals' => array($uid))); |
|
|
|
} |
|
|
|