|
@@ -8,6 +8,8 @@ use Passport\Lib\Base;
|
|
|
|
|
|
class Applet extends Base
|
|
|
{
|
|
|
+ private $cache = 'applet_sessionKey_';
|
|
|
+
|
|
|
public function init()
|
|
|
{
|
|
|
$uid = $this->check();
|
|
@@ -23,11 +25,12 @@ class Applet extends Base
|
|
|
*/
|
|
|
public function bind()
|
|
|
{
|
|
|
- $create = Dever::input('create', 1);
|
|
|
+ $create = Dever::input('create', 2);
|
|
|
$data = $this->getLoginInfo();
|
|
|
|
|
|
if ($create == 1) {
|
|
|
- $data = $this->create($data);
|
|
|
+ # 未授权,生成临时用户,针对有的项目,不需要授权,但是还要生成用户
|
|
|
+ $data = $this->create($data, false);
|
|
|
}
|
|
|
|
|
|
return $data;
|
|
@@ -65,93 +68,29 @@ class Applet extends Base
|
|
|
public function update()
|
|
|
{
|
|
|
$uid = $this->check();
|
|
|
- $name = Dever::input('nickname');
|
|
|
- $pic = Dever::input('avatarurl');
|
|
|
- $sex = Dever::input('gender');
|
|
|
- $city = Dever::input('city');
|
|
|
- $mobile = Dever::input('mobile');
|
|
|
- $province = Dever::input('province');
|
|
|
- $country = Dever::input('country');
|
|
|
$vid = Dever::input('vid');
|
|
|
-
|
|
|
- $update['temp'] = 3;
|
|
|
- if ($vid) {
|
|
|
-
|
|
|
- $key = 'applet_sessionKey_' . $vid;
|
|
|
- $session_key = Dever::cache($key);
|
|
|
- if (!$session_key) {
|
|
|
- $vinfo = Dever::db('passport/wechat')->one($vid);
|
|
|
- $session_key = $vinfo['session_key'];
|
|
|
- }
|
|
|
-
|
|
|
- $data = $this->getWechatData($session_key);
|
|
|
- $unionid = $data['unionid'];
|
|
|
- if ($unionid) {
|
|
|
- $vinfo = Dever::db('passport/wechat')->one(array('option_unionid' => $unionid));
|
|
|
- if (!$vinfo) {
|
|
|
- $wechat['set_unionid'] = $unionid;
|
|
|
- $wechat['where_id'] = $vid;
|
|
|
- Dever::db('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);
|
|
|
- }
|
|
|
-
|
|
|
- $update['temp'] = 2;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$info = Dever::db('passport/user')->one($uid);
|
|
|
if ($info) {
|
|
|
-
|
|
|
if ($info['temp'] == 1) {
|
|
|
+ # 针对未授权,生成临时用户的用户进行设置积分
|
|
|
Dever::score($uid, 'bind_wechat', '用户微信授权');
|
|
|
}
|
|
|
- $update['temp'] = 2;
|
|
|
-
|
|
|
- $update['set_username'] = $this->createUsername($uid, $name);
|
|
|
-
|
|
|
- if ($sex == 1) {
|
|
|
- $update['set_sex'] = 1;
|
|
|
- } elseif ($sex == 2) {
|
|
|
- $update['set_sex'] = 2;
|
|
|
+ $data['temp'] = 2;
|
|
|
+ $data['username'] = Dever::input('nickname');
|
|
|
+ $data['avatar'] = Dever::input('avatarurl');
|
|
|
+ $data['sex'] = Dever::input('gender');
|
|
|
+ $data['city'] = Dever::input('city');
|
|
|
+ $data['province'] = Dever::input('province');
|
|
|
+ $data['country'] = Dever::input('country');
|
|
|
+
|
|
|
+ if ($data['sex'] == 1) {
|
|
|
+ $data['sex'] = 1;
|
|
|
+ } elseif ($data['sex'] == 2) {
|
|
|
+ $data['sex'] = 2;
|
|
|
} else {
|
|
|
- $update['set_sex'] = 3;
|
|
|
- }
|
|
|
- /*
|
|
|
- if ($sex || $sex == 0) {
|
|
|
- $update['set_sex'] = $this->saveSex($sex);
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- if ($pic) {
|
|
|
- //$update['set_avatar'] = $this->saveAvatar($pic);
|
|
|
- $update['set_avatar'] = $pic;
|
|
|
- }
|
|
|
-
|
|
|
- if ($city) {
|
|
|
- $update['set_city'] = $city;
|
|
|
+ $data['sex'] = 3;
|
|
|
}
|
|
|
-
|
|
|
- if ($province) {
|
|
|
- $update['set_province'] = $province;
|
|
|
- }
|
|
|
-
|
|
|
- if ($country) {
|
|
|
- $update['set_country'] = $country;
|
|
|
- }
|
|
|
-
|
|
|
- if ($country && $province && $city) {
|
|
|
- $update['set_area'] = $country . ',' . $province . ',' . $city;
|
|
|
- }
|
|
|
- if (isset($update) && $update) {
|
|
|
- $update['where_id'] = $uid;
|
|
|
- Dever::db('passport/user')->update($update);
|
|
|
- }
|
|
|
-
|
|
|
+ $this->updateUser($uid, $data);
|
|
|
} else {
|
|
|
Dever::alert('无效的用户id,请重新登录');
|
|
|
}
|
|
@@ -179,7 +118,7 @@ class Applet extends Base
|
|
|
$encryptedData = Dever::input('encryptedData');
|
|
|
|
|
|
if ($iv && $encryptedData) {
|
|
|
- $key = 'applet_sessionKey_' . $vid;
|
|
|
+ $key = $this->cache . $vid;
|
|
|
$session_key = Dever::cache($key);
|
|
|
if (!$session_key) {
|
|
|
$vinfo = Dever::db('passport/wechat')->one($vid);
|
|
@@ -199,14 +138,13 @@ class Applet extends Base
|
|
|
$info = Dever::load('passport/user-one', $uid);
|
|
|
$result['mobile'] = $mobile;
|
|
|
if ($info) {
|
|
|
-
|
|
|
if (!$info['mobile']) {
|
|
|
Dever::score($uid, 'bind_mobile', '绑定手机号');
|
|
|
}
|
|
|
- $update['set_mobile'] = $mobile;
|
|
|
- $update['set_bind'] = 1;
|
|
|
+ $update['mobile'] = $mobile;
|
|
|
+ $update['bind'] = 1;
|
|
|
$update['where_id'] = $uid;
|
|
|
- Dever::load('passport/user-update', $update);
|
|
|
+ Dever::db('passport/user')->update($update);
|
|
|
|
|
|
$state = Dever::config('base', 'project')->regSendSms;
|
|
|
if ($state) {
|
|
@@ -230,11 +168,11 @@ class Applet extends Base
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
- public function create($data)
|
|
|
+ public function create($data, $state = true)
|
|
|
{
|
|
|
$uid = false;
|
|
|
- $system = Dever::input('system', 1);
|
|
|
- $info = Dever::db('passport/wechat')->one(array('option_openid' => $data['openid']));
|
|
|
+ $data['system'] = Dever::input('system', 1);
|
|
|
+ $info = Dever::db('passport/wechat')->one(array('openid' => $data['openid']));
|
|
|
|
|
|
$wechat = array();
|
|
|
if (!$info) {
|
|
@@ -250,41 +188,20 @@ class Applet extends Base
|
|
|
$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 = $this->reg('applet', $data);
|
|
|
+ if ($state) {
|
|
|
+ Dever::score($info['id'], 'bind_wechat', '用户微信授权');
|
|
|
}
|
|
|
-
|
|
|
- $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;
|
|
|
+ $wechat['system_id'] = $data['system'];
|
|
|
$id = Dever::db('passport/wechat')->insert($wechat);
|
|
|
|
|
|
- $key = 'applet_sessionKey_' . $id;
|
|
|
+ $key = $this->cache . $id;
|
|
|
$cache = Dever::cache($key, $data['session_key']);
|
|
|
} else {
|
|
|
$uid = $info['uid'];
|
|
@@ -300,7 +217,7 @@ class Applet extends Base
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
- $key = 'applet_sessionKey_' . $id;
|
|
|
+ $key = $this->cache . $id;
|
|
|
$cache = Dever::cache($key, $data['session_key']);
|
|
|
|
|
|
if (!$cache) {
|
|
@@ -308,7 +225,7 @@ class Applet extends Base
|
|
|
}
|
|
|
|
|
|
if ($wechat) {
|
|
|
- $wechat['where_id'] = $info['id'];
|
|
|
+ $wechat['where_id'] = $id;
|
|
|
Dever::db('passport/wechat')->update($wechat);
|
|
|
}
|
|
|
}
|
|
@@ -319,7 +236,7 @@ class Applet extends Base
|
|
|
$result['uid'] = $uid;
|
|
|
$result['signature'] = Dever::login($uid);
|
|
|
|
|
|
- if ($user['mobile']) {
|
|
|
+ if (isset($user['mobile']) && $user['mobile']) {
|
|
|
$result['mobile'] = $user['mobile'];
|
|
|
}
|
|
|
|