|
@@ -5,6 +5,7 @@ namespace app\api\controller;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
+use app\common\library\Wechat;
|
|
|
use app\common\service\UserService;
|
|
|
use fast\Random;
|
|
|
use think\Exception;
|
|
@@ -712,55 +713,42 @@ class User extends Api
|
|
|
|
|
|
//微信登录
|
|
|
public function wechatlogin(){
|
|
|
-// $nickname = input('nickname','');
|
|
|
-// $avatar = input('avatar','');
|
|
|
- $gender = input('gender',1);
|
|
|
- $wechat_openid = input('openid','');
|
|
|
|
|
|
- if (!$wechat_openid) {
|
|
|
+ $code = input_post('code','');
|
|
|
+ if(!$code){
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
-// if($gender != 1){
|
|
|
-// $gender = 0;
|
|
|
-// }
|
|
|
+ //微信
|
|
|
+ $wechat = new Wechat();
|
|
|
+
|
|
|
+ $wxuserinfo = $wechat->getwxuserinfo($code);
|
|
|
+ if(!$wxuserinfo){
|
|
|
+ $this->error('openid获取失败');
|
|
|
+ }
|
|
|
+ $openid = $wxuserinfo['openid'];
|
|
|
|
|
|
- $user = \app\common\model\User::getByOpenid($wechat_openid);
|
|
|
+ $user = Db::name('user')->where('openid',$openid)->find();
|
|
|
if ($user) {
|
|
|
- if ($user->status != 1) {
|
|
|
- $this->error(__('Account is locked'));
|
|
|
+ if ($user['status'] == 2) {
|
|
|
+ $this->error(__('Account is log off'));
|
|
|
}
|
|
|
- if ($user->frozentime > time()) {
|
|
|
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
|
|
|
+ if ($user['status'] != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
}
|
|
|
//如果已经有账号则直接登录
|
|
|
- $ret = $this->auth->direct($user->id);
|
|
|
-
|
|
|
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
|
|
|
- /*if($user->gender == 1 && $user->gh_id == 0){
|
|
|
- $this->firstopen_send($user->id);
|
|
|
- }*/
|
|
|
+ $ret = $this->auth->direct($user['id']);
|
|
|
+ $is_register = 0;
|
|
|
} else {
|
|
|
-// $this->success('选择性别', ['code' => 5]);
|
|
|
-
|
|
|
-// if (!$nickname || !$avatar) {
|
|
|
-// $this->error(__('Invalid parameters'));
|
|
|
-// }
|
|
|
-
|
|
|
- $reg_data = [
|
|
|
-// 'nickname'=>$nickname,
|
|
|
-// 'avatar'=>$avatar,
|
|
|
-// 'gender'=>$gender,
|
|
|
- 'register_from' => input('register_from',''),
|
|
|
- 'gender' => $gender,
|
|
|
+ $extend = [
|
|
|
+ 'openid' => $openid,
|
|
|
];
|
|
|
- $ret = $this->auth->openid_register($wechat_openid,$reg_data);
|
|
|
- //亿米
|
|
|
- /*if(input('register_from','') == 'xiaomi'){
|
|
|
- $this->yimi_advert();
|
|
|
- }*/
|
|
|
+ $mobile = '';
|
|
|
+ $ret = $this->auth->register($mobile, Random::alnum(), $mobile, $extend);
|
|
|
+ $is_register = 1;
|
|
|
+ //$ret = $this->auth->openid_register($openid,$extend);
|
|
|
}
|
|
|
if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $data = ['is_register' => $is_register, 'userinfo' => $this->auth->getUserinfo()];
|
|
|
$this->success(__('Logged in successful'), $data);
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
@@ -1124,4 +1112,86 @@ class User extends Api
|
|
|
Db::commit();
|
|
|
$this->success($msg);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 微信注册来的,绑定手机号
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $mobile 手机号
|
|
|
+ * @param string $captcha 验证码
|
|
|
+ */
|
|
|
+ public function bindmobile()
|
|
|
+ {
|
|
|
+ $user = $this->auth->getUser();
|
|
|
+ $mobile = $this->request->post('mobile');
|
|
|
+ $captcha = $this->request->post('captcha');
|
|
|
+
|
|
|
+ if(!empty($this->auth->mobile)){
|
|
|
+ $this->error('已经绑定了手机号');
|
|
|
+ }
|
|
|
+ if (!$mobile || !$captcha) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ if (\app\common\model\User::where('mobile', $mobile)->find()) {
|
|
|
+ $this->error('该手机号已被其他用户绑定');
|
|
|
+ }
|
|
|
+ $result = Sms::check($mobile, $captcha, 'changemobile');
|
|
|
+ if (!$result) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ $verification = $user->verification;
|
|
|
+ $verification->mobile = 1;
|
|
|
+ $user->verification = $verification;
|
|
|
+ $user->mobile = $mobile;
|
|
|
+ $user->save();
|
|
|
+
|
|
|
+ Sms::flush($mobile, 'changemobile');
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手机注册来的,绑定微信
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $wechat_openid
|
|
|
+ */
|
|
|
+ public function bindopenid()
|
|
|
+ {
|
|
|
+ $code = input_post('code','');
|
|
|
+ if(!$code){
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ //微信
|
|
|
+ $wechat = new Wechat();
|
|
|
+ $openid = $wechat->getOpenid($code);
|
|
|
+ if(!$openid){
|
|
|
+ $this->error('openid获取失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = $this->auth->getUser();
|
|
|
+ if(!empty($this->auth->openid)){
|
|
|
+ $this->error('已经绑定了微信号');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (\app\common\model\User::where('openid', $openid)->find()) {
|
|
|
+ $this->error('该微信号已被其他用户绑定');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user->openid = $openid;
|
|
|
+ $user->save();
|
|
|
+
|
|
|
+ $this->success('success',$this->userInfo('return'));
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户详细资料
|
|
|
+ public function userInfo($type = 1){
|
|
|
+ $info = $this->auth->getUserinfo();
|
|
|
+ if($type == 'return'){
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+ $this->success(__('success'),$info);
|
|
|
+ }
|
|
|
}
|