Documentation
¶
Index ¶
- Variables
- func NewError(errCode int, errMsg string) error
- type Client
- func (c *Client) CheckEncryptedData()
- func (c *Client) CheckSessionKey(ctx context.Context, openID, signature string) error
- func (c *Client) CheckSessionKeyWithSignType(ctx context.Context, openID, signature string, st SignType) error
- func (c *Client) ClearQuota(ctx context.Context) error
- func (c *Client) ClearQuotaByAppSecret(ctx context.Context) error
- func (c *Client) Code2Session(ctx context.Context, code string) (*Code2SessionResponse, error)
- func (c *Client) CreateQRCode(ctx context.Context, path string, width int) (*CreateQRCodeResponse, error)
- func (c *Client) GenerateNFCScheme()
- func (c *Client) GenerateScheme()
- func (c *Client) GenerateShortLink()
- func (c *Client) GenerateURLLink()
- func (c *Client) GetAPIQuota(ctx context.Context, cgiPath string) (*GetAPIQuotaResponse, error)
- func (c *Client) GetPaidUnionID()
- func (c *Client) GetPhoneNumber(ctx context.Context, code string) (*GetPhoneNumberResponse, error)
- func (c *Client) GetPluginOpenPId()
- func (c *Client) GetQRCode(ctx context.Context, req *GetQRCodeRequest) (*GetQRCodeResponse, error)
- func (c *Client) GetRidInfo(ctx context.Context, rid string) (*GetRidInfoResponse, error)
- func (c *Client) GetUnlimitedQRCode(ctx context.Context, req *GetUnlimitedQRCodeRequest) (*GetUnlimitedQRCodeResponse, error)
- func (c *Client) GetUserEncryptKey()
- func (c *Client) GetUserInfo(ctx context.Context, req *GetUserInfoRequest) (*GetUserInfoResponse, error)
- func (c *Client) NewRequest() *rest.Request
- func (c *Client) QueryScheme()
- func (c *Client) QueryURLLink()
- type ClientOption
- type Code2SessionResponse
- type CreateQRCodeResponse
- type Error
- type GetAPIQuota
- type GetAPIQuotaResponse
- type GetPhoneNumberResponse
- type GetQRCodeRequest
- type GetQRCodeResponse
- type GetRidInfo
- type GetRidInfoResponse
- type GetUnlimitedQRCodeRequest
- type GetUnlimitedQRCodeResponse
- type GetUserInfoRequest
- type GetUserInfoResponse
- type GrantType
- type JSONValidator
- type PhoneInfo
- type PhoneInfoWatermark
- type QRCodeLineColor
- type RoundTripper
- type SignType
- type Token
- type TokenSource
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSignType = errors.New("wgo: invalid sign type")
ErrInvalidSignType is returned when sign type is invalid
var ErrOpenIDEmpty = errors.New("openID empty")
ErrOpenIDEmpty is returned when the OpenID is empty
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a WGo client.
func NewClientWithSecret ¶
func NewClientWithSecret(appid string, secret string, opts ...ClientOption) *Client
NewClientWithSecret ...
func (*Client) CheckSessionKey ¶
CheckSessionKey 校验服务器所保存的登录态 session_key 是否合法。 为了保持 session_key 私密性,接口不明文传输 session_key,而是通过校验登录态签名完成。 see: https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.checkSessionKey.html
func (*Client) CheckSessionKeyWithSignType ¶
func (c *Client) CheckSessionKeyWithSignType(ctx context.Context, openID, signature string, st SignType) error
CheckSessionKeyWithSignType 校验服务器所保存的登录态 session_key 是否合法。 为了保持 session_key 私密性,接口不明文传输 session_key,而是通过校验登录态签名完成。 see: https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.checkSessionKey.html
func (*Client) ClearQuotaByAppSecret ¶
ClearQuotaByAppSecret ...
func (*Client) Code2Session ¶
Code2Session 登录凭证校验。 通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。 see: https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.code2Session.html
func (*Client) CreateQRCode ¶
func (c *Client) CreateQRCode(ctx context.Context, path string, width int) (*CreateQRCodeResponse, error)
CreateQRCode Obtains Mini Program QR code in scenarios where a small number of codes are required.
Note that Mini Program codes generated via this API never expire, but the quantity is limited. For details, see Obtaining the QR Code https://developers.weixin.qq.com/miniprogram/en/dev/framework/open-ability/qr-code.html. see: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html
func (*Client) GetAPIQuota ¶
GetAPIQuota ...
func (*Client) GetPhoneNumber ¶
GetPhoneNumber 获取手机号 该接口用于将code换取用户手机号。 说明,每个 code 只能使用一次,code 的有效期为 5min。
func (*Client) GetQRCode ¶
func (c *Client) GetQRCode(ctx context.Context, req *GetQRCodeRequest) (*GetQRCodeResponse, error)
GetQRCode Obtains Mini Program QR code in scenarios where a small number of codes are required.
Mini Program codes generated via this API are permanently effective, but the quantity is limited. For details, see Obtaining the QR Code: https://developers.weixin.qq.com/miniprogram/en/dev/framework/open-ability/qr-code.html see: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/open-api/qr-code/wxacode.get.html
func (*Client) GetRidInfo ¶
GetRidInfo ...
func (*Client) GetUnlimitedQRCode ¶
func (c *Client) GetUnlimitedQRCode(ctx context.Context, req *GetUnlimitedQRCodeRequest) (*GetUnlimitedQRCodeResponse, error)
GetUnlimitedQRCode Obtains the Mini Program code in scenarios where a large number of codes are required.
Mini Program codes generated via this API are permanently effective. There is no upper limit on the number of codes. For more information on how to use it, see Obtaining the QR Code: https://developers.weixin.qq.com/miniprogram/en/dev/framework/open-ability/qr-code.html see: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html chinese see: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html
func (*Client) GetUserInfo ¶
func (c *Client) GetUserInfo(ctx context.Context, req *GetUserInfoRequest) (*GetUserInfoResponse, error)
GetUserInfo Users Basic Information UnionID see: https://developers.weixin.qq.com/doc/offiaccount/User_Management/Get_users_basic_information_UnionID.html#UinonId
func (*Client) NewRequest ¶
NewRequest creates a new request
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption is a client option for the WGo Client config.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient sets the http client for the WGo client
func WithSecret ¶
func WithSecret(secret string) ClientOption
func WithToken ¶
func WithToken(token string) ClientOption
WithToken sets the token for the WGo client
func WithTokenSource ¶
func WithTokenSource(tokenSource TokenSource) ClientOption
WithTokenSource sets the token source for the WGo client
type Code2SessionResponse ¶
type Code2SessionResponse struct { OpenID string `json:"openid"` SessionKey string `json:"session_key"` UnionID string `json:"unionid"` }
Code2SessionResponse is the response to an Code2Session
type CreateQRCodeResponse ¶
type CreateQRCodeResponse struct { Buffer []byte `json:"buffer"` ContentType string `json:"contentType"` }
CreateQRCodeResponse is the response of CreateQRCode
type GetAPIQuota ¶
type GetAPIQuota struct { DailyLimit int `json:"daily_limit"` Used int `json:"used"` Remain int `json:"remain"` }
GetAPIQuota ...
type GetAPIQuotaResponse ¶
type GetAPIQuotaResponse struct {
Quota GetAPIQuota `json:"quota"`
}
GetAPIQuotaResponse ...
type GetPhoneNumberResponse ¶
type GetPhoneNumberResponse struct {
PhoneInfo PhoneInfo `json:"phone_info"`
}
GetPhoneNumberResponse 获取手机号响应
type GetQRCodeRequest ¶
type GetQRCodeRequest struct { Path string `json:"path"` Width int `json:"width"` AutoColor bool `json:"auto_color"` LineColor QRCodeLineColor `json:"line_color"` IsHyaline bool `json:"is_hyaline"` }
GetQRCodeRequest is a request to get the GetQRCode
type GetQRCodeResponse ¶
type GetQRCodeResponse struct { Buffer []byte `json:"buffer"` ContentType string `json:"contentType"` }
GetQRCodeResponse is the response of GetQRCode
type GetRidInfo ¶
type GetRidInfo struct { InvokeTime int `json:"invoke_time"` CostInMs int `json:"cost_in_ms"` RequestURL string `json:"request_url"` RequestBody string `json:"request_body"` ResponseBody string `json:"response_body"` ClientIP string `json:"client_ip"` }
GetRidInfo ...
type GetRidInfoResponse ¶
type GetRidInfoResponse struct {
Request GetRidInfo `json:"request"`
}
GetRidInfoResponse ...
type GetUnlimitedQRCodeRequest ¶
type GetUnlimitedQRCodeRequest struct { // Scene is required // A maximum of 32 visible characters including numbers, uppercase and lowercase English letters, // and some special characters !#$&'()*+,/:;=?@-._~ are supported. Other characters need to be encoded // as valid characters. (Because % is not supported, Chinese characters cannot be processed via urlencode, // so you must use other encoding schemes instead.) Scene string `json:"scene"` // Page This must be an existing page of a published Mini Program (otherwise, an error is reported), // for example, pages/index/index. Do not prefix a root path with /. This field cannot contain parameters // (parameters can be contained in the scene field). // If this field is left empty, the user is redirected to the homepage by default. Page string `json:"page"` // Width The width of the QR code (in px). The minimum value is 280 px and the maximum value is 1280 px. Width int `json:"width"` // AutoColor The automatically configured line color. If the color is still black, // it indicates that the setting of the dominant tone is not recommended. Its value is "false" by default. AutoColor bool `json:"auto_color"` // LineColor It takes effect when auto_color is "false". The color is specified via RGB, // for example, {"r":"xxx","g":"xxx","b":"xxx"}, and indicated by a decimal value. LineColor QRCodeLineColor `json:"line_color"` // IsHyaline Specifies whether a transparent background is required. // "true" indicates a transparent background is generated for the Mini Program. IsHyaline bool `json:"is_hyaline"` }
GetUnlimitedQRCodeRequest is a request to get the GetUnlimitedQRCode see: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html#Request-Parameters chinese see: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0
type GetUnlimitedQRCodeResponse ¶
type GetUnlimitedQRCodeResponse struct { Buffer []byte `json:"buffer"` ContentType string `json:"contentType"` }
GetUnlimitedQRCodeResponse is the response of GetUnlimitedQRCode
see: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html#Return-Values chinese see: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html#%E8%BF%94%E5%9B%9E%E5%80%BC
type GetUserInfoRequest ¶
GetUserInfoRequest is the request for the GetUserInfo method
type GetUserInfoResponse ¶
type GetUserInfoResponse struct { Subscribe int `json:"subscribe"` OpenID string `json:"openid"` Language string `json:"language"` SubscribeTime int `json:"subscribe_time"` UnionID string `json:"unionid"` Remark string `json:"remark"` GroupID int `json:"groupid"` TagIDList []int `json:"tagid_list"` SubscribeScene string `json:"subscribe_scene"` QrScene int `json:"qr_scene"` QrSceneStr string `json:"qr_scene_str"` }
GetUserInfoResponse is the response to a GetUserInfo request
type JSONValidator ¶
type JSONValidator struct {
// contains filtered or unexported fields
}
JSONValidator 是一个结构体,它用于在解析 JSON 数据之前验证 JSON 是否符合要求。
主要的作用是检查 JSON 数据中是否包含名为 errcode 和 errmsg 的字段, 如果存在 errcode 字段,则返回一个包含 errcode 和 errmsg 的错误。 否则,JSONValidator 将解析 JSON 数据。
func NewJSONValidator ¶
func NewJSONValidator(val interface{}) *JSONValidator
NewJSONValidator 是一个函数,它创建并返回一个 JSONValidator 的实例。 它接受一个参数 val,它是要解析 JSON 数据的目标结构体或值。
func (*JSONValidator) UnmarshalJSON ¶
func (r *JSONValidator) UnmarshalJSON(body []byte) error
UnmarshalJSON 是 JSONValidator 的方法,它用于在解析 JSON 数据之前验证 JSON 是否符合要求。
它首先从 JSON 数据中获取 errcode 和 errmsg 字段,并检查 errcode 是否大于 0。 如果 errcode 大于 0,则 UnmarshalJSON 方法会返回一个包含 errcode 和 errmsg 的错误。 如果 errcode 不大于 0,则 UnmarshalJSON 方法将使用 encoding/json 包的 Unmarshal 函数解析 JSON 数据到目标结构体或值中。
type PhoneInfo ¶
type PhoneInfo struct { // PhoneNumber 用户绑定的手机号(国外手机号会有区号) PhoneNumber string `json:"phoneNumber"` // PurePhoneNumber 没有区号的手机号 PurePhoneNumber string `json:"purePhoneNumber"` // CountryCode 区号 CountryCode string `json:"countryCode"` // Watermark 数据水印 Watermark PhoneInfoWatermark `json:"watermark"` }
PhoneInfo 用户手机号信息
type PhoneInfoWatermark ¶
type PhoneInfoWatermark struct { // 用户获取手机号操作的时间戳 Timestamp int `json:"timestamp"` // 小程序appid AppID string `json:"appid"` }
PhoneInfoWatermark 数据水印
type QRCodeLineColor ¶
QRCodeLineColor It takes effect when auto_color is "false".
The color is specified via RGB, for example, {"r":"xxx","g":"xxx","b":"xxx"}, and indicated by a decimal value.
type RoundTripper ¶
type RoundTripper struct { TokenSource TokenSource // contains filtered or unexported fields }
RoundTripper is a RoundTripper that implements the http.RoundTripper interface
type Token ¶
type Token struct { // AccessToken is the token that authorizes and authenticates // the requests. AccessToken string `json:"access_token"` // Expiry is the optional expiration time of the access token. // // If zero, TokenSource implementations will reuse the same // token forever and RefreshToken or equivalent // mechanisms for that TokenSource will not be used. Expiry time.Time `json:"expiry,omitempty"` }
Token represents the credentials used to authorize the requests to access protected resources on the OAuth 2.0 provider's backend.
Most users of this package should not access fields of Token directly. They're exported mostly for use by related packages implementing derivative OAuth2 flows.
type TokenSource ¶
type TokenSource interface { // Token returns a token or an error. // Token must be safe for concurrent use by multiple goroutines. // The returned Token must not be modified. Token() (*Token, error) }
A TokenSource is anything that can return a token.