xcx_api_controller.go 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. beego.Router("/xcx/api/mobile/patient", &XcxApiController{}, "Get:GetPatientList")
  24. //获取登录后的信息
  25. beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
  26. }
  27. type XcxApiController struct {
  28. mobile_api_controllers.MobileBaseAPIController
  29. }
  30. func (this *XcxApiController) GetCodeInit() {
  31. redisClient := service.RedisClient()
  32. defer redisClient.Close()
  33. req := this.Ctx.Request
  34. addr := utils.GetIP(req)
  35. cur_time := time.Now().Format("2006-01-02")
  36. _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
  37. if err != nil {
  38. redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  39. }
  40. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  41. aespass := utils.AESEncrypt(addr)
  42. fmt.Println("hhhhhhh3223323232332", aespass)
  43. this.ServeSuccessJSON(map[string]interface{}{
  44. "aespass": aespass,
  45. })
  46. }
  47. func (this *XcxApiController) GetUserRegister() {
  48. //用户绑定
  49. name := this.GetString("name")
  50. id_card_no := this.GetString("id_card_no")
  51. mobile := this.GetString("mobile")
  52. code := this.GetString("code")
  53. role := models.XcxAdminUserRole{
  54. PatientName: name,
  55. IdCardNo: id_card_no,
  56. Mobile: mobile,
  57. Code: code,
  58. PatientId: 0,
  59. UserOrgId: 0,
  60. Status: 0,
  61. Ctime: 0,
  62. Mtime: 0,
  63. Appid: "",
  64. Appsecret: "",
  65. SessionKey: "",
  66. }
  67. //查找该电话号码是否存在
  68. _, errcode := service.GetXcxMobileInformation(mobile)
  69. if errcode == gorm.ErrRecordNotFound {
  70. err := service.CreateXcxAdminUser(role)
  71. if err == nil {
  72. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  73. return
  74. }
  75. this.ServeSuccessJSON(map[string]interface{}{
  76. "role": role,
  77. })
  78. } else if errcode == nil {
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  80. return
  81. }
  82. fmt.Println("roler", role)
  83. }
  84. func (this *XcxApiController) GetCodeInfo() {
  85. mobile := this.GetString("phone")
  86. aespass := this.GetString("aespass")
  87. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  88. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  89. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  90. this.ServeJSON()
  91. return
  92. }
  93. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  94. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  95. this.ServeJSON()
  96. } else {
  97. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  98. "msg": "短信发送成功,有效期为10分钟",
  99. })
  100. this.ServeJSON()
  101. }
  102. }
  103. func (this *XcxApiController) GetLoginInfor() {
  104. fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
  105. mobile := this.GetString("mobile")
  106. fmt.Println(mobile)
  107. info, err := service.GetMobilePatientInfo(mobile)
  108. if info.ID == 0 {
  109. if err == nil {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  111. return
  112. }
  113. this.ServeSuccessJSON(map[string]interface{}{
  114. "is_bind": false,
  115. "info": info,
  116. })
  117. } else {
  118. _, errcode := service.GetLoginInfor("18923081560")
  119. if errcode == gorm.ErrRecordNotFound {
  120. role := models.XcxAdminUserRole{
  121. PatientName: info.Name,
  122. IdCardNo: info.IdCardNo,
  123. Mobile: info.TellPhone,
  124. Code: "",
  125. PatientId: info.ID,
  126. UserOrgId: info.UserOrgId,
  127. Status: 1,
  128. Ctime: time.Now().Unix(),
  129. Mtime: 0,
  130. Appid: "",
  131. Appsecret: "",
  132. SessionKey: "",
  133. }
  134. err := service.CreateXcxAdminUser(role)
  135. fmt.Println(err)
  136. } else {
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "is_bind": true,
  139. "info": info,
  140. })
  141. }
  142. this.ServeSuccessJSON(map[string]interface{}{
  143. "is_bind": true,
  144. "info": info,
  145. })
  146. }
  147. }
  148. func (this *XcxApiController) GetPatientList() {
  149. var appid = "wx20b60369111b063a"
  150. var key = "HobHcmPatZ0O5emMYcFo1Q=="
  151. var iv = "wJjr8o47Jv8zBoZF5la+jw=="
  152. var strs = "DKj+ZzSKd77D2X84UqySTfTOxcZ9W5yAArqt74g3Fek+/8N97XI3nKzLO4QadJxwl9f8BDqrpl2dauqNBC4HbkggFcEB9j1zsYDKAm5cM0NPOkjcHeGF8dxpuJGdXWFKZErD957XEPtyODbE3IUMIx/n8haGtCa3W9v5Gqosqxrb6eNY9ogf8V1dy2guuxVAxWojuZ2DLyYovksFLccD5Q=="
  153. data, err := service.DecryptData(appid, key, iv, strs)
  154. patient_id, _ := this.GetInt64("patient_id")
  155. patient, err := service.GetPatientListByPatientId(patient_id)
  156. if err == nil {
  157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  158. return
  159. }
  160. this.ServeSuccessJSON(map[string]interface{}{
  161. "patient": patient,
  162. "data": data,
  163. })
  164. }
  165. func (this *XcxApiController) GetDataInfo() {
  166. appid := this.GetString("appid")
  167. key := this.GetString("key")
  168. iv := this.GetString("iv")
  169. encryptedData := this.GetString("encryptedData")
  170. list, err := service.DecryptData(appid, key, iv, encryptedData)
  171. if err == nil {
  172. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  173. return
  174. }
  175. this.ServeSuccessJSON(map[string]interface{}{
  176. "list": list,
  177. })
  178. }