fix: wechat verify
This commit is contained in:
@@ -67,3 +67,10 @@ func ScopeAuthorizeURLWithForcePopup() ScopeAuthorizeURLOptions {
|
||||
v.Set("forcePopup", "true")
|
||||
}
|
||||
}
|
||||
|
||||
func WithVerifySiteKeyPair(key, value string) Options {
|
||||
return func(we *Client) {
|
||||
we.verifyKey = key
|
||||
we.verifyValue = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ type Config struct {
|
||||
Token string
|
||||
AesKey string
|
||||
DevMode bool
|
||||
Verify struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
}
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
@@ -42,6 +46,7 @@ func Provide(opts ...opt.Option) error {
|
||||
WithAESKey(config.AesKey),
|
||||
WithToken(config.Token),
|
||||
WithClient(httpClient),
|
||||
WithVerifySiteKeyPair(config.Verify.Key, config.Verify.Value),
|
||||
), nil
|
||||
}, o.DiOptions()...)
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ type Client struct {
|
||||
appSecret string
|
||||
token string
|
||||
aesKey string
|
||||
|
||||
verifyKey string
|
||||
verifyValue string
|
||||
}
|
||||
|
||||
func New(options ...Options) *Client {
|
||||
@@ -53,6 +56,13 @@ func New(options ...Options) *Client {
|
||||
return we
|
||||
}
|
||||
|
||||
func (we *Client) VerifySite(key string) (string, error) {
|
||||
if key == we.verifyKey {
|
||||
return we.verifyValue, nil
|
||||
}
|
||||
return "", errors.New("verify failed")
|
||||
}
|
||||
|
||||
func (we *Client) Verify(signature, timestamp, nonce string) error {
|
||||
params := []string{signature, timestamp, nonce, we.token}
|
||||
sort.Strings(params)
|
||||
|
||||
Reference in New Issue
Block a user