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