瀏覽代碼

体积小

XMLWAN 3 年之前
父節點
當前提交
de31ba7c9c
共有 2 個文件被更改,包括 110 次插入14 次删除
  1. 42 7
      controllers/xcx_mobile_api_controller.go/xcx_api_controller.go
  2. 68 7
      service/xcx_mobile_api_service.go

+ 42 - 7
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go 查看文件

@@ -22,6 +22,11 @@ func XcxApiControllersRegisterRouters() {
22 22
 	//登录
23 23
 	beego.Router("/xcx/api/mobile/login", &XcxApiController{}, "Get:GetLoginInfor")
24 24
 
25
+	//获取二维码信息
26
+	beego.Router("/xcx/api/mobile/patient", &XcxApiController{}, "Get:GetPatientList")
27
+
28
+	//获取登录后的信息
29
+	beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
25 30
 }
26 31
 
27 32
 type XcxApiController struct {
@@ -102,13 +107,6 @@ func (this *XcxApiController) GetCodeInfo() {
102 107
 		return
103 108
 	}
104 109
 
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 110
 	if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
113 111
 		this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
114 112
 		this.ServeJSON()
@@ -167,3 +165,40 @@ func (this *XcxApiController) GetLoginInfor() {
167 165
 	}
168 166
 
169 167
 }
168
+
169
+func (this *XcxApiController) GetPatientList() {
170
+	var appid = "wx20b60369111b063a"
171
+	var key = "HobHcmPatZ0O5emMYcFo1Q=="
172
+	var iv = "wJjr8o47Jv8zBoZF5la+jw=="
173
+	var strs = "DKj+ZzSKd77D2X84UqySTfTOxcZ9W5yAArqt74g3Fek+/8N97XI3nKzLO4QadJxwl9f8BDqrpl2dauqNBC4HbkggFcEB9j1zsYDKAm5cM0NPOkjcHeGF8dxpuJGdXWFKZErD957XEPtyODbE3IUMIx/n8haGtCa3W9v5Gqosqxrb6eNY9ogf8V1dy2guuxVAxWojuZ2DLyYovksFLccD5Q=="
174
+	data, err := service.DecryptData(appid, key, iv, strs)
175
+	patient_id, _ := this.GetInt64("patient_id")
176
+	patient, err := service.GetPatientListByPatientId(patient_id)
177
+
178
+	if err == nil {
179
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
180
+		return
181
+	}
182
+
183
+	this.ServeSuccessJSON(map[string]interface{}{
184
+		"patient": patient,
185
+		"data":    data,
186
+	})
187
+}
188
+
189
+func (this *XcxApiController) GetDataInfo() {
190
+
191
+	appid := this.GetString("appid")
192
+	key := this.GetString("key")
193
+	iv := this.GetString("iv")
194
+	encryptedData := this.GetString("encryptedData")
195
+	list, err := service.DecryptData(appid, key, iv, encryptedData)
196
+	if err == nil {
197
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
198
+		return
199
+	}
200
+
201
+	this.ServeSuccessJSON(map[string]interface{}{
202
+		"list": list,
203
+	})
204
+}

+ 68 - 7
service/xcx_mobile_api_service.go 查看文件

@@ -2,7 +2,13 @@ package service
2 2
 
3 3
 import (
4 4
 	"Xcx_New/models"
5
+	"crypto/aes"
6
+	"crypto/cipher"
7
+	"encoding/base64"
8
+	"encoding/json"
9
+	"errors"
5 10
 	"github.com/jinzhu/gorm"
11
+	"strings"
6 12
 )
7 13
 
8 14
 func GetXcxMobileInformation(mobile string) (*models.XcxAdminUserRole, error) {
@@ -35,12 +41,67 @@ func GetMobilePatientInfo(mobile string) (models.XcxPatients, error) {
35 41
 
36 42
 	patients := models.XcxPatients{}
37 43
 	err := XTReadDB().Model(&patients).Where("(phone = ? or home_telephone = ? ) and status = 1", mobile, mobile).Find(&patients).Error
38
-	//if err == gorm.ErrRecordNotFound {
39
-	//	return nil, err
40
-	//}
41
-	//
42
-	//if err != nil {
43
-	//	return nil, err
44
-	//}
45 44
 	return patients, err
46 45
 }
46
+
47
+func GetPatientListByPatientId(id int64) (models.XcxPatients, error) {
48
+
49
+	patients := models.XcxPatients{}
50
+	err := XTReadDB().Model(&patients).Where("id = ? and status = 1", id).Find(&patients).Error
51
+	return patients, err
52
+}
53
+
54
+func DecryptData(app_id, session_key, iv, encrypted_data string) (map[string]interface{}, error) {
55
+	if len := strings.Count(session_key, "") - 1; len != 24 {
56
+		return nil, errors.New("Invalid value session_key!")
57
+	}
58
+	aesKey, err := base64.StdEncoding.DecodeString(session_key)
59
+	if err != nil {
60
+		return nil, err
61
+	}
62
+
63
+	if len := strings.Count(iv, "") - 1; len != 24 {
64
+		return nil, errors.New("Invalid value iv!")
65
+	}
66
+	ivKey, err := base64.StdEncoding.DecodeString(iv)
67
+	if err != nil {
68
+		return nil, err
69
+	}
70
+
71
+	decodeData, err := base64.StdEncoding.DecodeString(encrypted_data)
72
+	if err != nil {
73
+		return nil, err
74
+	}
75
+
76
+	dataBytes, err := AesDecrypt(decodeData, aesKey, ivKey)
77
+	if err != nil {
78
+		return nil, err
79
+	}
80
+
81
+	var result map[string]interface{}
82
+	err = json.Unmarshal(dataBytes, &result)
83
+
84
+	watermark := result["watermark"].(map[string]interface{})
85
+	if watermark["appid"] != app_id {
86
+		return nil, errors.New("Invalid appid data!")
87
+	}
88
+
89
+	return result, err
90
+}
91
+
92
+func AesDecrypt(crypted, key, iv []byte) ([]byte, error) {
93
+	block, err := aes.NewCipher(key)
94
+	if err != nil {
95
+		return nil, err
96
+	}
97
+
98
+	blockMode := cipher.NewCBCDecrypter(block, iv)
99
+	origData := make([]byte, len(crypted))
100
+	blockMode.CryptBlocks(origData, crypted)
101
+
102
+	// 去除填充
103
+	length := len(origData)
104
+	unp := int(origData[length-1])
105
+	return origData[:(length - unp)], nil
106
+
107
+}