feat: wechat provider

This commit is contained in:
Rogee
2024-11-29 15:38:57 +08:00
parent 391f217bd8
commit aa7ad01ecc
9 changed files with 473 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package wechat
import (
"net/url"
"github.com/imroc/req/v3"
)
type Options func(*Client)
func WithAppID(appID string) Options {
return func(we *Client) {
we.appID = appID
}
}
// WithAppSecret sets the app secret
func WithAppSecret(appSecret string) Options {
return func(we *Client) {
we.appSecret = appSecret
}
}
// WithToken sets the token
func WithToken(token string) Options {
return func(we *Client) {
we.token = token
}
}
// WithAESKey sets the AES key
func WithAESKey(aesKey string) Options {
return func(we *Client) {
we.aesKey = aesKey
}
}
// WithClient sets the http client
func WithClient(client *req.Client) Options {
return func(we *Client) {
we.client = client
}
}
type ScopeAuthorizeURLOptions func(url.Values)
func ScopeAuthorizeURLWithScope(scope AuthScope) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("scope", scope.String())
}
}
func ScopeAuthorizeURLWithRedirectURI(uri string) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("redirect_uri", uri)
}
}
func ScopeAuthorizeURLWithState(state string) ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("state", state)
}
}
func ScopeAuthorizeURLWithForcePopup() ScopeAuthorizeURLOptions {
return func(v url.Values) {
v.Set("forcePopup", "true")
}
}