xcx_api_controller.go 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package xcx_mobile_api_controller_go
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "Xcx_New/utils"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "time"
  12. )
  13. func XcxApiControllersRegisterRouters() {
  14. ////传送codeinit
  15. beego.Router("/xcx/m/api/code", &XcxApiController{}, "Get:GetCodeInit")
  16. //获取验证码
  17. beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo")
  18. //用户绑定
  19. beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister")
  20. //登录
  21. beego.Router("/xcx/api/mobile/login", &XcxApiController{}, "Get:GetLoginInfor")
  22. }
  23. type XcxApiController struct {
  24. mobile_api_controllers.MobileBaseAPIController
  25. }
  26. func (this *XcxApiController) GetCodeInit() {
  27. redisClient := service.RedisClient()
  28. defer redisClient.Close()
  29. req := this.Ctx.Request
  30. addr := utils.GetIP(req)
  31. cur_time := time.Now().Format("2006-01-02")
  32. _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
  33. if err != nil {
  34. redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  35. }
  36. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  37. aespass := utils.AESEncrypt(addr)
  38. fmt.Println("hhhhhhh3223323232332", aespass)
  39. this.ServeSuccessJSON(map[string]interface{}{
  40. "aespass": aespass,
  41. })
  42. }
  43. func (this *XcxApiController) GetUserRegister() {
  44. //用户绑定
  45. name := this.GetString("name")
  46. id_card_no := this.GetString("id_card_no")
  47. mobile := this.GetString("mobile")
  48. code := this.GetString("code")
  49. role := models.XcxAdminUserRole{
  50. PatientName: name,
  51. IdCardNo: id_card_no,
  52. Mobile: mobile,
  53. Code: code,
  54. PatientId: 0,
  55. UserOrgId: 0,
  56. Status: 0,
  57. Ctime: 0,
  58. Mtime: 0,
  59. Appid: "",
  60. Appsecret: "",
  61. SessionKey: "",
  62. }
  63. //查找该电话号码是否存在
  64. _, errcode := service.GetXcxMobileInformation(mobile)
  65. if errcode == gorm.ErrRecordNotFound {
  66. err := service.CreateXcxAdminUser(role)
  67. if err == nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  69. return
  70. }
  71. this.ServeSuccessJSON(map[string]interface{}{
  72. "role": role,
  73. })
  74. } else if errcode == nil {
  75. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  76. return
  77. }
  78. fmt.Println("roler", role)
  79. }
  80. func (this *XcxApiController) GetCodeInfo() {
  81. mobile := this.GetString("phone")
  82. aespass := this.GetString("aespass")
  83. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  84. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  85. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  86. this.ServeJSON()
  87. return
  88. }
  89. adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile)
  90. if adminUser != nil {
  91. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRegisterExist)
  92. this.ServeJSON()
  93. return
  94. }
  95. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  96. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  97. this.ServeJSON()
  98. } else {
  99. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  100. "msg": "短信发送成功,有效期为10分钟",
  101. })
  102. this.ServeJSON()
  103. }
  104. }
  105. func (this *XcxApiController) GetLoginInfor() {
  106. fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
  107. mobile := this.GetString("mobile")
  108. fmt.Println(mobile)
  109. info, err := service.GetMobilePatientInfo(mobile)
  110. if info.ID == 0 {
  111. if err == nil {
  112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  113. return
  114. }
  115. this.ServeSuccessJSON(map[string]interface{}{
  116. "is_bind": false,
  117. "info": info,
  118. })
  119. } else {
  120. _, errcode := service.GetLoginInfor("18923081560")
  121. if errcode == gorm.ErrRecordNotFound {
  122. role := models.XcxAdminUserRole{
  123. PatientName: info.Name,
  124. IdCardNo: info.IdCardNo,
  125. Mobile: info.TellPhone,
  126. Code: "",
  127. PatientId: info.ID,
  128. UserOrgId: info.UserOrgId,
  129. Status: 1,
  130. Ctime: time.Now().Unix(),
  131. Mtime: 0,
  132. Appid: "",
  133. Appsecret: "",
  134. SessionKey: "",
  135. }
  136. err := service.CreateXcxAdminUser(role)
  137. fmt.Println(err)
  138. } else {
  139. this.ServeSuccessJSON(map[string]interface{}{
  140. "is_bind": true,
  141. "info": info,
  142. })
  143. }
  144. this.ServeSuccessJSON(map[string]interface{}{
  145. "is_bind": true,
  146. "info": info,
  147. })
  148. }
  149. }