|
@@ -170,7 +170,7 @@ class User extends Api
|
|
|
}
|
|
|
$openid = $wxuserinfo['openid'];
|
|
|
|
|
|
- $user = Db::name('user')->where('openid',$openid)->find();
|
|
|
+ $user = Db::name('user')->where('wechat_openid',$openid)->find();
|
|
|
if ($user) {
|
|
|
if ($user['status'] == -1) {
|
|
|
$this->error('账户已注销');
|
|
@@ -284,7 +284,7 @@ class User extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //苹果登录+注册
|
|
|
+ //苹果登录+预注册
|
|
|
public function applelogin(){
|
|
|
$iosUserId = input_post('ios_user_id','');
|
|
|
if(!$iosUserId){
|
|
@@ -300,13 +300,20 @@ class User extends Api
|
|
|
$this->error(__('Account is locked'));
|
|
|
}
|
|
|
//如果已经有账号则直接登录
|
|
|
+ $is_register = 0;
|
|
|
$ret = $this->auth->direct($user['id']);
|
|
|
+ $userInfo = $this->auth->getUserinfo();
|
|
|
} else {
|
|
|
+ $is_register = 1;
|
|
|
+ $ret = true;
|
|
|
+ $userInfo = [];
|
|
|
|
|
|
- $ret = $this->auth->ios_register($iosUserId);
|
|
|
+ $data = ['ios_user_id'=>$iosUserId,'is_register' => $is_register, 'userinfo' => $userInfo];
|
|
|
+ $this->success('获取信息成功', $data, 2);
|
|
|
}
|
|
|
if ($ret) {
|
|
|
- $this->success(__('Logged in successful'), $this->auth->getUserinfo());
|
|
|
+ $data = ['ios_user_id'=>$iosUserId,'is_register' => $is_register, 'userinfo' => $userInfo];
|
|
|
+ $this->success(__('Logged in successful'), $data);
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
|
}
|
|
@@ -474,17 +481,20 @@ class User extends Api
|
|
|
$latitude = input_post('latitude',0);
|
|
|
$cityname = input_post('cityname','');
|
|
|
$plat_unique_id = input_post('plat_unique_id','');
|
|
|
- if(empty($longitude) || empty($latitude) || empty($cityname)){
|
|
|
+ /*if(empty($longitude) || empty($latitude) || empty($cityname)){
|
|
|
$this->error();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- $data = [
|
|
|
- 'longitude' => $longitude,
|
|
|
- 'latitude' => $latitude,
|
|
|
- 'cityname' => $cityname,
|
|
|
- 'plat_unique_id' => $plat_unique_id,
|
|
|
- ];
|
|
|
- Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ $longitude && $data['longitude'] = $longitude;
|
|
|
+ $latitude && $data['latitude'] = $latitude;
|
|
|
+ $cityname && $data['cityname'] = $cityname;
|
|
|
+ $plat_unique_id && $data['plat_unique_id'] = $plat_unique_id;
|
|
|
+
|
|
|
+ if(!empty($data)){
|
|
|
+ Db::name('user')->where('id',$this->auth->id)->update($data);
|
|
|
+ }
|
|
|
$this->success();
|
|
|
}
|
|
|
|
|
@@ -544,6 +554,63 @@ class User extends Api
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
$this->success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 苹果注册来的,绑定手机号
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $mobile 手机号
|
|
|
+ * @param string $captcha 验证码
|
|
|
+ */
|
|
|
+ public function applebindmobile()
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $iosUserId = $this->request->param('ios_user_id','');
|
|
|
+ $mobile = $this->request->param('mobile');
|
|
|
+ $captcha = $this->request->param('captcha');
|
|
|
+
|
|
|
+ if (!$mobile || !$captcha || !$iosUserId) {
|
|
|
+ throw new Exception(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ /*if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ throw new Exception(__('Mobile is incorrect'));
|
|
|
+ }*/
|
|
|
+ $result = Sms::check($mobile, $captcha, 'changemobile');
|
|
|
+ if (!$result) {
|
|
|
+ throw new Exception(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $where['mobile'] = $mobile;
|
|
|
+ $userData = model('User')->where($where)->find();//老用户
|
|
|
+ if (!empty($userData)) {
|
|
|
+ if (empty($userData['ios_user_id'])) {
|
|
|
+ model('User')->update(['ios_user_id' => $iosUserId],$where);//老用户更新openid
|
|
|
+ } else {
|
|
|
+ if ($userData['ios_user_id'] != $iosUserId) {
|
|
|
+ throw new Exception('该手机号已被其他用户绑定');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $ret = $this->auth->direct($userData['id']);
|
|
|
+ } else {
|
|
|
+ $extend = [
|
|
|
+ 'ios_user_id' => $iosUserId,
|
|
|
+ ];
|
|
|
+ $ret = $this->auth->register('', '','', $mobile, $extend);
|
|
|
+ }
|
|
|
+ if (!$ret) {
|
|
|
+ throw new Exception($this->auth->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ Sms::flush($mobile, 'changemobile');
|
|
|
+ Db::commit();
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 微信注册来的,绑定手机号
|
|
|
*
|