-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
49 lines (41 loc) · 1.5 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ma
import (
"crypto/sha1"
"encoding/hex"
"github.com/cliod/wx-go/common"
"github.com/cliod/wx-go/common/util"
"strings"
)
// 解密分享敏感数据.
func GetShareInfo(sessionKey, encryptedData, ivStr string) (*WxMaShareInfo, error) {
var usrInfo WxMaShareInfo
err := util.Decrypt(&usrInfo, sessionKey, encryptedData, ivStr)
return &usrInfo, err
}
// 解密用户信息敏感数据.
func GetUserInfo(sessionKey, encryptedData, ivStr string) (*UserInfo, error) {
var usrInfo UserInfo
err := util.Decrypt(&usrInfo, sessionKey, encryptedData, ivStr)
return &usrInfo, err
}
// 解密手机号敏感数据.
func GetPhoneNoInfo(sessionKey, encryptedData, ivStr string) (*PhoneNumberInfo, error) {
var info PhoneNumberInfo
err := util.Decrypt(&info, sessionKey, encryptedData, ivStr)
return &info, err
}
func CheckUserInfo(sessionKey, rawData, signature string) bool {
sum := sha1.Sum([]byte(rawData + sessionKey))
return strings.ToLower(hex.EncodeToString(sum[:])) == signature
}
func CheckAndGetUserInfo(sessionKey, rawData, encryptedData, signature, ivStr string) (*UserInfo, error) {
var usrInfo UserInfo
err := util.DecryptInfo(&usrInfo, sessionKey, rawData, encryptedData, signature, ivStr)
return &usrInfo, err
}
func CheckSignature(token, timestamp, nonce, signature string) bool {
return util.CheckSignature(token, timestamp, nonce, signature)
}
func CreateJsapiSignature(url, appId, ticket string) (*common.WxJsapiSignature, error) {
return common.CreateJsapiSignature(url, appId, ticket)
}