|
@@ -15,14 +15,15 @@ use app\common\model\UserDeviceInfo;
|
|
use onlogin\onlogin;
|
|
use onlogin\onlogin;
|
|
|
|
|
|
use addons\epay\library\Service;
|
|
use addons\epay\library\Service;
|
|
-use addons\epay\library\Wechat;
|
|
|
|
|
|
+//use addons\epay\library\Wechat;
|
|
|
|
+use app\common\library\Wechat;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 会员接口,登录,注册,修改资料等
|
|
* 会员接口,登录,注册,修改资料等
|
|
*/
|
|
*/
|
|
class User extends Api
|
|
class User extends Api
|
|
{
|
|
{
|
|
- protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig'];
|
|
|
|
|
|
+ protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig'];
|
|
protected $noNeedRight = '*';
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
public function _initialize()
|
|
@@ -118,19 +119,13 @@ class User extends Api
|
|
//如果已经有账号则直接登录
|
|
//如果已经有账号则直接登录
|
|
$ret = $this->auth->direct($user->id);
|
|
$ret = $this->auth->direct($user->id);
|
|
|
|
|
|
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
|
|
|
|
- if($user->gender == 1 && $user->gh_id == 0){
|
|
|
|
- $this->firstopen_send($user->id);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
$extend = [
|
|
$extend = [
|
|
'register_from' => input('register_from',''),
|
|
'register_from' => input('register_from',''),
|
|
];
|
|
];
|
|
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
|
|
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
|
|
- //亿米
|
|
|
|
- if(input('register_from','') == 'xiaomi'){
|
|
|
|
- $this->yimi_advert();
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
if ($ret) {
|
|
if ($ret) {
|
|
Sms::flush($mobile, 'mobilelogin');
|
|
Sms::flush($mobile, 'mobilelogin');
|
|
@@ -202,10 +197,7 @@ class User extends Api
|
|
//如果已经有账号则直接登录
|
|
//如果已经有账号则直接登录
|
|
$ret = $this->auth->direct($user->id);
|
|
$ret = $this->auth->direct($user->id);
|
|
|
|
|
|
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
|
|
|
|
- if($user->gender == 1 && $user->gh_id == 0){
|
|
|
|
- $this->firstopen_send($user->id);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
if (!$nickname || !$avatar) {
|
|
if (!$nickname || !$avatar) {
|
|
$this->error(__('Invalid parameters'));
|
|
$this->error(__('Invalid parameters'));
|
|
@@ -218,10 +210,7 @@ class User extends Api
|
|
'register_from' => input('register_from',''),
|
|
'register_from' => input('register_from',''),
|
|
];
|
|
];
|
|
$ret = $this->auth->openid_register($wechat_openid,$reg_data);
|
|
$ret = $this->auth->openid_register($wechat_openid,$reg_data);
|
|
- //亿米
|
|
|
|
- if(input('register_from','') == 'xiaomi'){
|
|
|
|
- $this->yimi_advert();
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
if ($ret) {
|
|
if ($ret) {
|
|
$data = $this->userInfo('return');
|
|
$data = $this->userInfo('return');
|
|
@@ -281,25 +270,15 @@ class User extends Api
|
|
$ret = $this->auth->direct($user->id);
|
|
$ret = $this->auth->direct($user->id);
|
|
$is_register = 0;
|
|
$is_register = 0;
|
|
|
|
|
|
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
|
|
|
|
- if($user->gender == 1 && $user->gh_id == 0){
|
|
|
|
- $this->firstopen_send($user->id);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
- $extend = [
|
|
|
|
- 'register_from' => input('register_from',''),
|
|
|
|
- ];
|
|
|
|
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
|
|
|
|
|
|
+
|
|
|
|
+ $ret = $this->auth->register('', '', '', $mobile, []);
|
|
$is_register = 1;
|
|
$is_register = 1;
|
|
- //亿米
|
|
|
|
- if(input('register_from','') == 'xiaomi'){
|
|
|
|
- $this->yimi_advert();
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- //结果
|
|
|
|
- /*$rs['userinfo'] = $this->auth->getUserinfo();
|
|
|
|
- $rs['is_register'] = $is_register;*/
|
|
|
|
|
|
+
|
|
if ($ret) {
|
|
if ($ret) {
|
|
$this->success(__('Logged in successful'), $this->auth->getUserinfo());
|
|
$this->success(__('Logged in successful'), $this->auth->getUserinfo());
|
|
} else {
|
|
} else {
|
|
@@ -554,8 +533,8 @@ class User extends Api
|
|
$this->error(__('Invalid parameters'));
|
|
$this->error(__('Invalid parameters'));
|
|
}
|
|
}
|
|
//退出im
|
|
//退出im
|
|
- $tenIm = new Tenim();
|
|
|
|
- $tenIm->loginoutim($this->auth->id);
|
|
|
|
|
|
+// $tenIm = new Tenim();
|
|
|
|
+// $tenIm->loginoutim($this->auth->id);
|
|
|
|
|
|
//修改用户活跃0
|
|
//修改用户活跃0
|
|
Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
|
|
Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
|
|
@@ -703,40 +682,6 @@ class User extends Api
|
|
$this->success();
|
|
$this->success();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 修改邮箱
|
|
|
|
- *
|
|
|
|
- * @ApiMethod (POST)
|
|
|
|
- * @param string $email 邮箱
|
|
|
|
- * @param string $captcha 验证码
|
|
|
|
- */
|
|
|
|
- /*public function changeemail()
|
|
|
|
- {
|
|
|
|
- $user = $this->auth->getUser();
|
|
|
|
- $email = $this->request->post('email');
|
|
|
|
- $captcha = $this->request->post('captcha');
|
|
|
|
- if (!$email || !$captcha) {
|
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
|
- }
|
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
|
- }
|
|
|
|
- if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
|
|
|
- $this->error(__('Email already exists'));
|
|
|
|
- }
|
|
|
|
- $result = Ems::check($email, $captcha, 'changeemail');
|
|
|
|
- if (!$result) {
|
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
|
- }
|
|
|
|
- $verification = $user->verification;
|
|
|
|
- $verification->email = 1;
|
|
|
|
- $user->verification = $verification;
|
|
|
|
- $user->email = $email;
|
|
|
|
- $user->save();
|
|
|
|
-
|
|
|
|
- Ems::flush($email, 'changeemail');
|
|
|
|
- $this->success();
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 修改手机号
|
|
* 修改手机号
|
|
@@ -827,7 +772,7 @@ class User extends Api
|
|
* @param string $mobile 手机号
|
|
* @param string $mobile 手机号
|
|
* @param string $captcha 验证码
|
|
* @param string $captcha 验证码
|
|
*/
|
|
*/
|
|
- public function bindopenid()
|
|
|
|
|
|
+ /*public function bindopenid()
|
|
{
|
|
{
|
|
$user = $this->auth->getUser();
|
|
$user = $this->auth->getUser();
|
|
$wechat_openid = $this->request->request('wechat_openid');
|
|
$wechat_openid = $this->request->request('wechat_openid');
|
|
@@ -847,40 +792,55 @@ class User extends Api
|
|
$user->save();
|
|
$user->save();
|
|
|
|
|
|
$this->success('success',$this->userInfo('return'));
|
|
$this->success('success',$this->userInfo('return'));
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 第三方登录
|
|
|
|
|
|
+ * 手机注册来的,绑定微信
|
|
*
|
|
*
|
|
* @ApiMethod (POST)
|
|
* @ApiMethod (POST)
|
|
- * @param string $platform 平台名称
|
|
|
|
- * @param string $code Code码
|
|
|
|
|
|
+ * @param string $wechat_openid
|
|
*/
|
|
*/
|
|
- /*public function third()
|
|
|
|
|
|
+ public function bindopenid()
|
|
{
|
|
{
|
|
- $url = url('user/index');
|
|
|
|
-// $platform = $this->request->post("platform");
|
|
|
|
- $platform = 'wechat';
|
|
|
|
- $code = $this->request->post("code");
|
|
|
|
- $config = get_addon_config('third');
|
|
|
|
- if (!$config || !isset($config[$platform])) {
|
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
|
- }
|
|
|
|
- $app = new \addons\third\library\Application($config);
|
|
|
|
- //通过code换access_token和绑定会员
|
|
|
|
- $result = $app->{$platform}->getUserInfo(['code' => $code]);
|
|
|
|
- if ($result) {
|
|
|
|
- $loginret = \addons\third\library\Service::connect($platform, $result);
|
|
|
|
- if ($loginret) {
|
|
|
|
- $data = [
|
|
|
|
- 'userinfo' => $this->auth->getUserinfo(),
|
|
|
|
- 'thirdinfo' => $result
|
|
|
|
- ];
|
|
|
|
- $this->success(__('Logged in successful'), $data);
|
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ try {
|
|
|
|
+ $code = $this->request->param('code','');
|
|
|
|
+ if(!$code){
|
|
|
|
+ throw new Exception(__('Invalid parameters'));
|
|
|
|
+ }
|
|
|
|
+ //微信
|
|
|
|
+ $wechat = new Wechat();
|
|
|
|
+ $openid = $wechat->getOpenid($code);
|
|
|
|
+
|
|
|
|
+ if(!$openid){
|
|
|
|
+ throw new Exception('openid获取失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user = model('User')->find($this->auth->id);
|
|
|
|
+ if(!empty($user['wechat_openid'])/* && $openid != $user['openid']*/){
|
|
|
|
+ throw new Exception('已经绑定了微信号');
|
|
|
|
+ }
|
|
|
|
+ $otherUserWhere['wechat_openid'] = $openid;
|
|
|
|
+ $otherUserWhere['id'] = ['neq',$this->auth->id];
|
|
|
|
+ $otherUser = model('User')->where($otherUserWhere)->find();
|
|
|
|
+ if (!empty($otherUser)) {
|
|
|
|
+ throw new Exception('该微信已被其他用户绑定过');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user->wechat_openid = $openid;
|
|
|
|
+ $userRes = $user->save();
|
|
|
|
+ if (!$userRes) {
|
|
|
|
+ throw new Exception('绑定微信失败');
|
|
}
|
|
}
|
|
|
|
+ Db::commit();
|
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error($e->getMessage());
|
|
}
|
|
}
|
|
- $this->error(__('Operation failed'), $url);
|
|
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 重置密码
|
|
* 重置密码
|
|
@@ -963,7 +923,7 @@ class User extends Api
|
|
}
|
|
}
|
|
|
|
|
|
if ($ret) {
|
|
if ($ret) {
|
|
- $this->success(__('Reset password successful'));
|
|
|
|
|
|
+ $this->success('设置密码成功');
|
|
} else {
|
|
} else {
|
|
$this->error($this->auth->getError());
|
|
$this->error($this->auth->getError());
|
|
}
|
|
}
|