|
@@ -33,6 +33,90 @@ class Applet extends Base
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成用户,返回uid
|
|
|
+ *
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ private function create($data)
|
|
|
+ {
|
|
|
+ $uid = false;
|
|
|
+ $system = Dever::input('system', 1);
|
|
|
+ $info = Dever::load('passport/wechat-one', array('option_openid' => $data['openid']));
|
|
|
+
|
|
|
+ if (!$info) {
|
|
|
+ if (isset($data['unionid']) && $data['unionid']) {
|
|
|
+ $info = Dever::load('passport/wechat-one', array('unionid' => $data['unionid']));
|
|
|
+ if (!$info) {
|
|
|
+ $uid = false;
|
|
|
+ } else {
|
|
|
+ # 判断用户是否存在,是否需要合并
|
|
|
+ $uid = $this->combine($info['uid'], $data['unionid']);
|
|
|
+ }
|
|
|
+ $wechat['unionid'] = $data['unionid'];
|
|
|
+ }
|
|
|
+ if (!$uid) {
|
|
|
+
|
|
|
+ if (isset($data['username'])) {
|
|
|
+ $user['bind'] = 2;
|
|
|
+ $user['temp'] = 2;
|
|
|
+ $user['username'] = $data['username'];
|
|
|
+ $user['sex'] = $data['sex'];
|
|
|
+ $user['avatar'] = $data['avatar'];
|
|
|
+ $user['city'] = $data['city'];
|
|
|
+ $user['province'] = $data['province'];
|
|
|
+ $user['country'] = $data['country'];
|
|
|
+ if ($user['country'] && $user['province'] && $user['city']) {
|
|
|
+ $user['set_area'] = $user['country'] .','. $user['province'] .','. $user['city'];
|
|
|
+ }
|
|
|
+ $user['source_type'] = 'applet';
|
|
|
+ $user['system_id'] = $system;
|
|
|
+ } else {
|
|
|
+ $user['bind'] = 2;
|
|
|
+ $user['temp'] = 1;
|
|
|
+ $user['username'] = '临时用户';
|
|
|
+ $user['source_type'] = 'applet';
|
|
|
+ $user['system_id'] = $system;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $uid = Dever::load('passport/user-insert', $user);
|
|
|
+
|
|
|
+ Dever::load('passport/lib/base')->createUsername($uid, $user['username'], true);
|
|
|
+ }
|
|
|
+
|
|
|
+ $wechat['openid'] = $data['openid'];
|
|
|
+ $wechat['session_key'] = $data['session_key'];
|
|
|
+ $wechat['uid'] = $uid;
|
|
|
+ $wechat['type'] = 1;
|
|
|
+ $wechat['system_id'] = $system;
|
|
|
+ $id = Dever::load('passport/wechat-insert', $wechat);
|
|
|
+ } else {
|
|
|
+ $uid = $info['uid'];
|
|
|
+ if (isset($data['unionid']) && $data['unionid']) {
|
|
|
+ # 判断用户是否存在,是否需要合并
|
|
|
+ $wechat['uid'] = $this->combine($uid, $data['unionid']);
|
|
|
+ }
|
|
|
+ $id = $info['id'];
|
|
|
+ $wechat['session_key'] = $data['session_key'];
|
|
|
+ $wechat['where_id'] = $info['id'];
|
|
|
+
|
|
|
+ Dever::load('passport/wechat-update', $wechat);
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = Dever::load('passport/user-one', $uid);
|
|
|
+
|
|
|
+ $result['vid'] = $id;
|
|
|
+ $result['uid'] = $uid;
|
|
|
+ $result['signature'] = Dever::login($uid);
|
|
|
+
|
|
|
+ if ($user['mobile']) {
|
|
|
+ $result['mobile'] = $user['mobile'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 一次性登录:通过code或者openid、sessionkey来注册用户,此时已经授权,可以直接拿到unioinid
|
|
|
*
|
|
@@ -44,7 +128,7 @@ class Applet extends Base
|
|
|
|
|
|
$data += $this->getWechatData($data['session_key']);
|
|
|
|
|
|
- $data['username'] = Dever::input('nickname');
|
|
|
+ $data['username'] = Dever::emoji(Dever::input('nickname'));
|
|
|
$data['avatar'] = Dever::input('avatarurl');
|
|
|
$data['sex'] = Dever::input('gender');
|
|
|
$data['city'] = Dever::input('city');
|
|
@@ -65,7 +149,7 @@ class Applet extends Base
|
|
|
public function update()
|
|
|
{
|
|
|
$uid = $this->check();
|
|
|
- $name = Dever::input('nickname');
|
|
|
+ $name = Dever::emoji(Dever::input('nickname'));
|
|
|
$pic = Dever::input('avatarurl');
|
|
|
$sex = Dever::input('gender');
|
|
|
$city = Dever::input('city');
|
|
@@ -76,40 +160,29 @@ class Applet extends Base
|
|
|
|
|
|
$update['temp'] = 3;
|
|
|
if ($vid) {
|
|
|
+ $vinfo = Dever::load('passport/wechat-one', $vid);
|
|
|
|
|
|
- /*
|
|
|
- $key = 'applet_sessionKey1_' . $vid;
|
|
|
- $session_key = Dever::cache($key);
|
|
|
- if (!$session_key) {
|
|
|
- $vinfo = Dever::db('passport/wechat')->one($vid);
|
|
|
- $session_key = $vinfo['session_key'];
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- $vinfo = Dever::db('passport/wechat')->one($vid);
|
|
|
- $session_key = $vinfo['session_key'];
|
|
|
-
|
|
|
- $data = $this->getWechatData($session_key);
|
|
|
+ $data = $this->getWechatData($vinfo['session_key']);
|
|
|
$unionid = $data['unionid'];
|
|
|
if ($unionid) {
|
|
|
- $vinfo = Dever::db('passport/wechat')->one(array('option_unionid' => $unionid));
|
|
|
+ $vinfo = Dever::load('passport/wechat-one', array('option_unionid' => $unionid));
|
|
|
if (!$vinfo) {
|
|
|
$wechat['set_unionid'] = $unionid;
|
|
|
$wechat['where_id'] = $vid;
|
|
|
- Dever::db('passport/wechat')->update($wechat);
|
|
|
+ Dever::load('passport/wechat-update', $wechat);
|
|
|
} elseif ($vinfo && $vinfo['id'] != $vid) {
|
|
|
$wechat['set_unionid'] = $unionid;
|
|
|
$uid = $this->combine($uid, $unionid);
|
|
|
$wechat['set_uid'] = $uid;
|
|
|
$wechat['where_id'] = $vid;
|
|
|
- Dever::db('passport/wechat')->update($wechat);
|
|
|
+ Dever::load('passport/wechat-update', $wechat);
|
|
|
}
|
|
|
|
|
|
$update['temp'] = 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $info = Dever::db('passport/user')->one($uid);
|
|
|
+ $info = Dever::load('passport/user-one', $uid);
|
|
|
if ($info) {
|
|
|
|
|
|
if ($info['temp'] == 1) {
|
|
@@ -117,7 +190,7 @@ class Applet extends Base
|
|
|
}
|
|
|
$update['temp'] = 2;
|
|
|
|
|
|
- $update['set_username'] = $this->createUsername($uid, $name);
|
|
|
+ $update['set_username'] = Dever::load('passport/lib/base')->createUsername($uid, $name);
|
|
|
|
|
|
if ($sex == 1) {
|
|
|
$update['set_sex'] = 1;
|
|
@@ -140,7 +213,8 @@ class Applet extends Base
|
|
|
if ($city) {
|
|
|
$update['set_city'] = $city;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //$update['set_mobile'] = $mobile;
|
|
|
if ($province) {
|
|
|
$update['set_province'] = $province;
|
|
|
}
|
|
@@ -154,7 +228,7 @@ class Applet extends Base
|
|
|
}
|
|
|
if (isset($update) && $update) {
|
|
|
$update['where_id'] = $uid;
|
|
|
- Dever::db('passport/user')->update($update);
|
|
|
+ Dever::load('passport/user-update', $update);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -184,19 +258,8 @@ class Applet extends Base
|
|
|
$encryptedData = Dever::input('encryptedData');
|
|
|
|
|
|
if ($iv && $encryptedData) {
|
|
|
- /*
|
|
|
- $key = 'applet_sessionKey1_' . $vid;
|
|
|
- $session_key = Dever::cache($key);
|
|
|
- if (!$session_key) {
|
|
|
- $vinfo = Dever::db('passport/wechat')->one($vid);
|
|
|
- $session_key = $vinfo['session_key'];
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- $vinfo = Dever::db('passport/wechat')->one($vid);
|
|
|
- $session_key = $vinfo['session_key'];
|
|
|
-
|
|
|
- $data = $this->getWechatData($session_key);
|
|
|
+ $vinfo = Dever::load('passport/wechat-one', $vid);
|
|
|
+ $data = $this->getWechatData($vinfo['session_key']);
|
|
|
if ($data && $data['mobile']) {
|
|
|
$mobile = $data['mobile'];
|
|
|
$phoneNumber = $data['phone'];
|
|
@@ -228,110 +291,11 @@ class Applet extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $result['vid'] = $vid;
|
|
|
- $result['uid'] = $uid;
|
|
|
- $result['signature'] = Dever::login($uid);
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成用户,返回uid
|
|
|
- *
|
|
|
- * @return int
|
|
|
- */
|
|
|
- private function create($data)
|
|
|
- {
|
|
|
- $uid = false;
|
|
|
- $system = Dever::input('system', 1);
|
|
|
- $info = Dever::db('passport/wechat')->one(array('option_openid' => $data['openid']));
|
|
|
-
|
|
|
- $wechat = array();
|
|
|
- if (!$info) {
|
|
|
- if (isset($data['unionid']) && $data['unionid']) {
|
|
|
- $info = Dever::db('passport/wechat')->one(array('unionid' => $data['unionid']));
|
|
|
- if (!$info) {
|
|
|
- $uid = false;
|
|
|
- } else {
|
|
|
- # 判断用户是否存在,是否需要合并
|
|
|
- $uid = $this->combine($info['uid'], $data['unionid']);
|
|
|
- }
|
|
|
- $wechat['unionid'] = $data['unionid'];
|
|
|
- }
|
|
|
- if (!$uid) {
|
|
|
-
|
|
|
- $user['source_type'] = 'applet';
|
|
|
- $user['system_id'] = $system;
|
|
|
-
|
|
|
- if (isset($data['username'])) {
|
|
|
- $user['bind'] = 2;
|
|
|
- $user['temp'] = 2;
|
|
|
- $user['username'] = $data['username'];
|
|
|
- $user['sex'] = $data['sex'];
|
|
|
- $user['avatar'] = $data['avatar'];
|
|
|
- $user['city'] = $data['city'];
|
|
|
- $user['province'] = $data['province'];
|
|
|
- $user['country'] = $data['country'];
|
|
|
- if ($user['country'] && $user['province'] && $user['city']) {
|
|
|
- $user['set_area'] = $user['country'] .','. $user['province'] .','. $user['city'];
|
|
|
- }
|
|
|
- } else {
|
|
|
- $user['bind'] = 2;
|
|
|
- $user['temp'] = 1;
|
|
|
- $user['username'] = '临时用户';
|
|
|
- }
|
|
|
-
|
|
|
- $uid = Dever::db('passport/user')->insert($user);
|
|
|
-
|
|
|
- $this->createUsername($uid, $user['username'], true);
|
|
|
- }
|
|
|
-
|
|
|
- $wechat['openid'] = $data['openid'];
|
|
|
- $wechat['session_key'] = $data['session_key'];
|
|
|
- $wechat['uid'] = $uid;
|
|
|
- $wechat['type'] = 1;
|
|
|
- $wechat['system_id'] = $system;
|
|
|
- $id = Dever::db('passport/wechat')->insert($wechat);
|
|
|
-
|
|
|
- //$key = 'applet_sessionKey1_' . $id;
|
|
|
- //$cache = Dever::cache($key, $data['session_key']);
|
|
|
- } else {
|
|
|
- $uid = $info['uid'];
|
|
|
- $id = $info['id'];
|
|
|
- if (isset($data['unionid']) && $data['unionid']) {
|
|
|
- # 判断用户是否存在,是否需要合并
|
|
|
- $wechat['uid'] = $this->combine($uid, $data['unionid']);
|
|
|
-
|
|
|
- if ($wechat['uid'] != $uid) {
|
|
|
- $uid = $wechat['uid'];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- $key = 'applet_sessionKey1_' . $id;
|
|
|
- $cache = Dever::cache($key, $data['session_key']);
|
|
|
-
|
|
|
- if (!$cache) {
|
|
|
- $wechat['session_key'] = $data['session_key'];
|
|
|
- }
|
|
|
- */
|
|
|
- $wechat['session_key'] = $data['session_key'];
|
|
|
-
|
|
|
- if ($wechat) {
|
|
|
- $wechat['where_id'] = $info['id'];
|
|
|
- Dever::db('passport/wechat')->update($wechat);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $user = Dever::db('passport/user')->one($uid);
|
|
|
+
|
|
|
|
|
|
- $result['vid'] = $id;
|
|
|
+ $result['vid'] = $vid;
|
|
|
$result['uid'] = $uid;
|
|
|
$result['signature'] = Dever::login($uid);
|
|
|
-
|
|
|
- if ($user['mobile']) {
|
|
|
- $result['mobile'] = $user['mobile'];
|
|
|
- }
|
|
|
|
|
|
return $result;
|
|
|
}
|