|
@@ -22,6 +22,117 @@ class Base
|
|
$this->save = new Save(false, 'cookie');
|
|
$this->save = new Save(false, 'cookie');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function wechat($data, $user = array(), $account, $system, $source_type, $source = false)
|
|
|
|
+ {
|
|
|
|
+ $uid = false;
|
|
|
|
+
|
|
|
|
+ if (!$data['openid']) {
|
|
|
|
+ Dever::alert('错误的openid');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!$user['username']) {
|
|
|
|
+ Dever::alert('用户名错误');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isset($user['sex'])) {
|
|
|
|
+ if ($user['sex'] == 1) {
|
|
|
|
+ $user['sex'] = 1;
|
|
|
|
+ } elseif ($user['sex'] == 2) {
|
|
|
|
+ $user['sex'] = 2;
|
|
|
|
+ } else {
|
|
|
|
+ $user['sex'] = 3;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isset($user['country']) && $user['country'] && isset($user['province']) && $user['province'] && isset($user['city']) && $user['city']) {
|
|
|
|
+ $user['area'] = $user['country'] .','. $user['province'] .','. $user['city'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $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 = $info['uid'];
|
|
|
|
+ }
|
|
|
|
+ $wechat['unionid'] = $data['unionid'];
|
|
|
|
+ }
|
|
|
|
+ if (!$uid) {
|
|
|
|
+ $user['source_type'] = 'service';
|
|
|
|
+ if ($system) {
|
|
|
|
+ $user['system_id'] = $system;
|
|
|
|
+ }
|
|
|
|
+ if ($source_type) {
|
|
|
|
+ $user['source_type'] = $source_type;
|
|
|
|
+ }
|
|
|
|
+ $uid = Dever::load('passport/user-insert', $user);
|
|
|
|
+ } else {
|
|
|
|
+ $user['where_id'] = $uid;
|
|
|
|
+ Dever::load('passport/user-update', $user);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $wechat['access_token'] = $data['access_token'];
|
|
|
|
+ $wechat['openid'] = $data['openid'];
|
|
|
|
+ $wechat['expires_in'] = $data['expires_in'];
|
|
|
|
+ $wechat['refresh_token'] = $data['refresh_token'];
|
|
|
|
+ $wechat['account_id'] = $account;
|
|
|
|
+ if ($system) {
|
|
|
|
+ $wechat['system_id'] = $system;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $wechat['uid'] = $uid;
|
|
|
|
+ $wechat['type'] = 2;
|
|
|
|
+ if ($source_type == 'applet') {
|
|
|
|
+ $wechat['type'] = 1;
|
|
|
|
+ } elseif ($source_type == 'ios') {
|
|
|
|
+ $wechat['type'] = 3;
|
|
|
|
+ } elseif ($source_type == 'android') {
|
|
|
|
+ $wechat['type'] = 4;
|
|
|
|
+ }
|
|
|
|
+ $id = Dever::load('passport/wechat-insert', $wechat);
|
|
|
|
+
|
|
|
|
+ if (Dever::project('source') && isset($source) && $source && $source > 0) {
|
|
|
|
+ Dever::load('source/lib/core')->saveUser($id, $uid, $source, 'oauth', $account);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $uid = $info['uid'];
|
|
|
|
+ if (isset($data['unionid']) && $data['unionid']) {
|
|
|
|
+ $wechat['unionid'] = $data['unionid'];
|
|
|
|
+ # 判断用户是否存在,是否需要合并
|
|
|
|
+ $wechat['uid'] = $this->combine($uid, $data['unionid']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $wechat['access_token'] = $data['access_token'];
|
|
|
|
+ $wechat['openid'] = $data['openid'];
|
|
|
|
+ $wechat['expires_in'] = $data['expires_in'];
|
|
|
|
+ $wechat['refresh_token'] = $data['refresh_token'];
|
|
|
|
+ $wechat['where_id'] = $info['id'];
|
|
|
|
+ $wechat['account_id'] = $account;
|
|
|
|
+ if ($system) {
|
|
|
|
+ $wechat['system_id'] = $system;
|
|
|
|
+ }
|
|
|
|
+ $id = $info['id'];
|
|
|
|
+ Dever::load('passport/wechat-update', $wechat);
|
|
|
|
+
|
|
|
|
+ $user['where_id'] = $uid;
|
|
|
|
+ Dever::load('passport/user-update', $user);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->createUsername($uid, $user['username']);
|
|
|
|
+
|
|
|
|
+ $user = Dever::load('passport/user-one', $uid);
|
|
|
|
+
|
|
|
|
+ $this->save($user);
|
|
|
|
+
|
|
|
|
+ $user['uid'] = $user['id'];
|
|
|
|
+ $user['signature'] = Dever::login($user['id']);
|
|
|
|
+
|
|
|
|
+ return $user;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 更新用户信息 绑定用户手机号
|
|
* 更新用户信息 绑定用户手机号
|
|
*
|
|
*
|