|
@@ -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
|
+}
|