rdluck 4 年之前
父节点
当前提交
48e6201490
共有 2 个文件被更改,包括 90 次插入4 次删除
  1. 85 4
      controllers/user.go
  2. 5 0
      models/wx_user.go

+ 85 - 4
controllers/user.go

@@ -73,7 +73,7 @@ func (this *UserCommonController) GetSmsCode() {
 		return
 	}
 	areaNum := this.GetString("AreaNum")
-	msgCode := utils.GetRandString(4)
+	msgCode := utils.GetRandDigit(4)
 	var result bool
 	if areaNum == "86" || areaNum == "" || areaNum == "0" {
 		result = services.SendSmsCode(mobile, msgCode)
@@ -171,7 +171,7 @@ func (this *UserCommonController) GetEmailCode() {
 		br.Msg = "邮箱格式错误,请重新输入"
 		return
 	}
-	msgCode := utils.GetRandString(4)
+	msgCode := utils.GetRandDigit(4)
 	content := "尊敬的用户:</br>您好,感谢您使用弘则研究,您正在进行邮箱验证,本次请求的验证码为:" + msgCode + "(为了保障您账号的安全性,请在15分钟内完成验证。)</br>弘则研究团队 </br>2019年05月11日"
 	title := "弘则研究登陆验证"
 	//发送邮件
@@ -239,9 +239,90 @@ func (this *UserCommonController) CheckEmailCode() {
 	br.Msg = "验证码正确"
 }
 
+
+// @Title 登录
+// @Description 登录接口
+// @Param	request	body models.LoginReq true "type json string"
+// @Success 200 {object} models.LoginResp
+// @router /login [post]
+func (this *UserCommonController) Login() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.LoginReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "登录成功"
+}
+
+
 /*
-$app->post('api/user/login',"UserController@login");//登录
-*/
+
+   //登录
+   function login()
+   {
+
+       $openId =$this->request->open_id;
+       if(empty($openId)){
+           return response()->json(['code'=>'1','msg'=>'参数错误']);
+       }
+       $user = UserModel::getUserByOpenid($openId);
+       if(empty($user))
+       {
+           return response()->json(['code'=>'40001','msg'=>'请重新登陆']);
+       }
+       $loginTypeStr='';
+       $userId=$user->user_id;
+
+       $userData=array(
+           'company_id'=>1,
+       );
+       if ($loginType==1){
+           $mobile = ExpressUtil::checkStringArrayValue('mobile',$request_data);
+           if(!preg_match("/^1\d{10}$/",$mobile)){
+               return response()->json(['code'=>'3','msg'=>'请输入正确的手机号(1开头的11位数字)']);
+           }
+           app('log')->info("start bindMobile");
+           $userId=UserModel::bindMobile($openId,$userId,$mobile);
+           $loginTypeStr='MOBILE';
+       }else if ($loginType==2){
+           $email = ExpressUtil::checkStringArrayValue('email',$request_data);
+           $preg_email='/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims';
+           if(!preg_match($preg_email,$email)){
+               return response()->json(['code'=>'4','msg'=>'请输入正确的邮箱']);
+           }
+           $userId=UserModel::bindMobile($openId,$userId,$email);
+           $loginTypeStr='EMAIL';
+       }else{
+           return response()->json(['code'=>'5','msg'=>'无效的登录方式']);
+       }
+
+       //判断是否有权限访问
+       $userPermission = ExpressUtil::checkUserPermission($userId);
+
+       SessionModel::addSession($openId,$userId);
+       $session = SessionModel::getSessionByUserId($userId);
+       $rddpAccessToken=$session->access_token;
+       $response = new Response(['code'=>'0','msg'=>'登录成功','data'=>array(
+           'user_id'=>$userId,
+           'rddp_access_token'=>$rddpAccessToken,
+           'user_permission'=>$userPermission,
+       )]);
+       UserModel::editUserFirstLogin($openId);
+       $result=json_encode($response);
+       app('log')->info("login result:".$result);
+       return $response;
+   }
+
+ */
 
 // @Title 申请试用
 // @Description 申请试用接口

+ 5 - 0
models/wx_user.go

@@ -164,3 +164,8 @@ func Apply(userId, applyMethod int, mobile, email, companyName, realName, openId
 	}
 	return
 }
+
+type LoginReq struct {
+	LoginType int    `description:"登录方式:1:手机,2:邮箱"`
+	Mobile    string `description:"手机号"`
+}