package xcx_mobile_api_controller_go import ( "Xcx_New/controllers" "Xcx_New/enums" "Xcx_New/models" "Xcx_New/service" "Xcx_New/utils" "fmt" "github.com/astaxie/beego" "github.com/jinzhu/gorm" "time" ) func XcxApiControllersRegisterRouters() { //传送codeinit beego.Router("/m/api/code", &XcxApiController{}, "Get:GetCodeInit") //获取验证码 beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo") //用户绑定 beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister") //登录 beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetLoginInfor") } type XcxApiController struct { controllers.BaseAuthAPIController } func (this *XcxApiController) GetCodeInit() { redisClient := service.RedisClient() defer redisClient.Close() req := this.Ctx.Request addr := utils.GetIP(req) cur_time := time.Now().Format("2006-01-02") _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result() if err != nil { redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60) } //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址 aespass := utils.AESEncrypt(addr) fmt.Println("hhhhhhh3223323232332", aespass) this.ServeSuccessJSON(map[string]interface{}{ "aespass": aespass, }) } func (this *XcxApiController) GetUserRegister() { //用户绑定 name := this.GetString("name") id_card_no := this.GetString("id_card_no") mobile := this.GetString("mobile") code := this.GetString("code") role := models.XcxAdminUserRole{ PatientName: name, IdCardNo: id_card_no, Mobile: mobile, Code: code, PatientId: 0, UserOrgId: 0, Status: 0, Ctime: 0, Mtime: 0, Appid: "", Appsecret: "", SessionKey: "", } //查找该电话号码是否存在 _, errcode := service.GetXcxMobileInformation(mobile) if errcode == gorm.ErrRecordNotFound { err := service.CreateXcxAdminUser(role) if err == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "role": role, }) } else if errcode == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } fmt.Println("roler", role) } func (this *XcxApiController) GetCodeInfo() { mobile := this.GetString("phone") aespass := this.GetString("aespass") utils.TraceLog("mobile:%v aespass:%v", mobile, aespass) if utils.CellPhoneRegexp().MatchString(mobile) == false { this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat) this.ServeJSON() return } adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile) if adminUser != nil { this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRegisterExist) this.ServeJSON() return } if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil { this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600) this.ServeJSON() } else { this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{ "msg": "短信发送成功,有效期为10分钟", }) this.ServeJSON() } } func (this *XcxApiController) GetLoginInfor() { mobile := this.GetString("mobile") role, err := service.GetLoginInfor(mobile) if err == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "role": role, }) }