附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 line
1.1 KiB

  1. package weapp
  2. const (
  3. apiVerifySignature = "/cgi-bin/soter/verify_signature"
  4. )
  5. // VerifySignatureResponse 生物认证秘钥签名验证请求返回数据
  6. type VerifySignatureResponse struct {
  7. CommonError
  8. IsOk bool `json:"is_ok"`
  9. }
  10. // VerifySignature 生物认证秘钥签名验证
  11. // accessToken 接口调用凭证
  12. // openID 用户 openid
  13. // data 通过 wx.startSoterAuthentication 成功回调获得的 resultJSON 字段
  14. // signature 通过 wx.startSoterAuthentication 成功回调获得的 resultJSONSignature 字段
  15. func VerifySignature(token, openID, data, signature string) (*VerifySignatureResponse, error) {
  16. api := baseURL + apiVerifySignature
  17. return verifySignature(api, token, openID, data, signature)
  18. }
  19. func verifySignature(api, token, openID, data, signature string) (*VerifySignatureResponse, error) {
  20. url, err := tokenAPI(api, token)
  21. if err != nil {
  22. return nil, err
  23. }
  24. params := requestParams{
  25. "openid": openID,
  26. "json_string": data,
  27. "json_signature": signature,
  28. }
  29. res := new(VerifySignatureResponse)
  30. if err := postJSON(url, params, res); err != nil {
  31. return nil, err
  32. }
  33. return res, nil
  34. }