-
Notifications
You must be signed in to change notification settings - Fork 281
/
soter.go
41 lines (34 loc) · 1.12 KB
/
soter.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
package weapp
const (
apiVerifySignature = "/cgi-bin/soter/verify_signature"
)
// VerifySignatureResponse 生物认证秘钥签名验证请求返回数据
type VerifySignatureResponse struct {
CommonError
IsOk bool `json:"is_ok"`
}
// VerifySignature 生物认证秘钥签名验证
// accessToken 接口调用凭证
// openID 用户 openid
// data 通过 wx.startSoterAuthentication 成功回调获得的 resultJSON 字段
// signature 通过 wx.startSoterAuthentication 成功回调获得的 resultJSONSignature 字段
func VerifySignature(token, openID, data, signature string) (*VerifySignatureResponse, error) {
api := baseURL + apiVerifySignature
return verifySignature(api, token, openID, data, signature)
}
func verifySignature(api, token, openID, data, signature string) (*VerifySignatureResponse, error) {
url, err := tokenAPI(api, token)
if err != nil {
return nil, err
}
params := requestParams{
"openid": openID,
"json_string": data,
"json_signature": signature,
}
res := new(VerifySignatureResponse)
if err := postJSON(url, params, res); err != nil {
return nil, err
}
return res, nil
}