forked from royalrick/weapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soter.go
49 lines (39 loc) · 1.27 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
42
43
44
45
46
47
48
49
package weapp
import "github.com/ericnts/weapp/v3/request"
const (
apiVerifySignature = "/cgi-bin/soter/verify_signature"
)
// VerifySignatureResponse 生物认证秘钥签名验证请求返回数据
type VerifySignatureResponse struct {
request.CommonError
IsOk bool `json:"is_ok"`
}
// VerifySignature 生物认证秘钥签名验证
// accessToken 接口调用凭证
// openID 用户 openid
// data 通过 wx.startSoterAuthentication 成功回调获得的 resultJSON 字段
// signature 通过 wx.startSoterAuthentication 成功回调获得的 resultJSONSignature 字段
func (cli *Client) VerifySignature(openID, data, signature string) (*VerifySignatureResponse, error) {
api := baseURL + apiVerifySignature
token, err := cli.AccessToken()
if err != nil {
return nil, err
}
return cli.verifySignature(api, token, openID, data, signature)
}
func (cli *Client) 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 := cli.request.Post(url, params, res); err != nil {
return nil, err
}
return res, nil
}