123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package xcx_mobile_api_controller_go
-
- import (
- "Xcx_New/controllers/mobile_api_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("/xcx/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/login", &XcxApiController{}, "Get:GetLoginInfor")
-
- }
-
- type XcxApiController struct {
- mobile_api_controllers.MobileBaseAPIController
- }
-
- 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() {
- fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
- mobile := this.GetString("mobile")
- fmt.Println(mobile)
- info, err := service.GetMobilePatientInfo(mobile)
- if info.ID == 0 {
- if err == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": false,
- "info": info,
- })
- } else {
- _, errcode := service.GetLoginInfor("18923081560")
- if errcode == gorm.ErrRecordNotFound {
- role := models.XcxAdminUserRole{
- PatientName: info.Name,
- IdCardNo: info.IdCardNo,
- Mobile: info.TellPhone,
- Code: "",
- PatientId: info.ID,
- UserOrgId: info.UserOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Appid: "",
- Appsecret: "",
- SessionKey: "",
- }
- err := service.CreateXcxAdminUser(role)
- fmt.Println(err)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": true,
- "info": info,
- })
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": true,
- "info": info,
- })
- }
-
- }
|