minip

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAppID               = "Wechatmp-Appid"
	HeaderTimestamp           = "Wechatmp-TimeStamp"
	HeaderSerial              = "Wechatmp-Serial"
	HeaderSignature           = "Wechatmp-Signature"
	HeaderSerialDeprecated    = "Wechatmp-Serial-Deprecated"
	HeaderSignatureDeprecated = "Wechatmp-Signature-Deprecated"
)
View Source
const AccessToken = "access_token"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 小程序

func NewClient

func NewClient(appid, secret string) *Client

NewClient 生成一个小程序实例

func (*Client) AccessToken

func (c *Client) AccessToken(ctx context.Context) (gjson.Result, error)

AccessToken 获取接口调用凭据

func (*Client) AppID

func (c *Client) AppID() string

AppID 返回appid

func (*Client) Code2Session

func (c *Client) Code2Session(ctx context.Context, code string) (gjson.Result, error)

Code2Session 通过临时登录凭证code完成登录流程

func (*Client) DecodeEncryptData

func (*Client) DecodeEncryptData(sessionKey, iv, encryptData string) ([]byte, error)

DecodeEncryptData 解析加密数据,如:授权的用户信息和手机号

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html)

func (*Client) DecodeEventMsg

func (c *Client) DecodeEventMsg(encrypt string) ([]byte, error)

DecodeEventMsg 事件消息解密

使用包体内的 Encrypt 字段
根据配置的数据格式,解析 XML/JSON
[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

func (*Client) EncodeEventReply

func (c *Client) EncodeEventReply(msg string) (KV, error)

EncodeEventReply 事件回复加密

根据配置的数据格式,输出 XML/JSON
[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

func (*Client) R

func (c *Client) R() *Request

func (*Client) Secret

func (c *Client) Secret() string

Secret 返回secret

func (*Client) SetAesKey

func (c *Client) SetAesKey(sn, key string)

func (*Client) SetHttpClient

func (c *Client) SetHttpClient(cli *http.Client)

func (*Client) SetLogger

func (c *Client) SetLogger(fn func(ctx context.Context, err error, data map[string]string))

func (*Client) SetPrivateKey

func (c *Client) SetPrivateKey(pem []byte) error

func (*Client) SetPrivateKeyFromPfx

func (c *Client) SetPrivateKeyFromPfx(pfxData []byte, password string) error

func (*Client) SetPublicKey

func (c *Client) SetPublicKey(pem []byte) error

func (*Client) SetServerConfig

func (c *Client) SetServerConfig(token, aeskey string)

SetServerConfig 设置服务器配置

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

func (*Client) SetTokenLoader

func (c *Client) SetTokenLoader(fn func(ctx context.Context) (string, error))

func (*Client) StableAccessToken

func (c *Client) StableAccessToken(ctx context.Context, forceRefresh bool) (gjson.Result, error)

StableAccessToken 获取稳定版接口调用凭据

有两种调用模式:
[普通模式] access_token有效期内重复调用该接口不会更新access_token,绝大部分场景下使用该模式;
[强制刷新模式] 会导致上次获取的access_token失效,并返回新的access_token

func (*Client) VerifyEventMsg

func (c *Client) VerifyEventMsg(signature string, items ...string) error

VerifyEventMsg 验证事件消息

[服务器URL验证]
URL参数中的 signature、timestamp、nonce
注意:验证成功后,原样返回 echostr 字段值

[事件消息验证]
[明文模式] URL参数中的 signature、timestamp、nonce
[安全模式] URL参数中的 msg_signature、timestamp、nonce 和包体内的 Encrypt 字段

[参考](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html)

type KV

type KV = kvkit.KV

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) BufferGet

func (r *Request) BufferGet(ctx context.Context, path string) ([]byte, error)

BufferGet 获取 buffer (如:获取媒体资源)

func (*Request) BufferPost

func (r *Request) BufferPost(ctx context.Context, path string) ([]byte, error)

BufferPost 获取 buffer (如:获取二维码)

func (*Request) EncryptBufferPost

func (r *Request) EncryptBufferPost(ctx context.Context, path string) ([]byte, error)

EncryptBufferPost 加密获取 buffer (如:获取二维码)

[安全鉴权模式](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html)
[支持的API](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc)

func (*Request) EncryptPost

func (r *Request) EncryptPost(ctx context.Context, path string) (gjson.Result, error)

EncryptPost 加密请求

[安全鉴权模式](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/getting_started/api_signature.html)
[支持的API](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc)

func (*Request) Get

func (r *Request) Get(ctx context.Context, path string) (gjson.Result, error)

func (*Request) Post

func (r *Request) Post(ctx context.Context, path string) (gjson.Result, error)

func (*Request) SetBody

func (r *Request) SetBody(body X) *Request

SetBody 设置JSON请求Body

func (*Request) SetFile

func (r *Request) SetFile(param, filename string, reader io.Reader) *Request

SetFile 设置上传文件

func (*Request) SetForm

func (r *Request) SetForm(k, v string) *Request

SetForm 设置上传表单数据

func (*Request) SetHeader

func (r *Request) SetHeader(k string, vs ...string) *Request

SetHeader 设置Header

func (*Request) SetQuery

func (r *Request) SetQuery(k string, vs ...string) *Request

SetQuery 设置Query参数

func (*Request) Upload

func (r *Request) Upload(ctx context.Context, path string) (gjson.Result, error)

type SafeMode

type SafeMode struct {
	// contains filtered or unexported fields
}

SafeMode 安全鉴权模式配置

type ServerConfig

type ServerConfig struct {
	// contains filtered or unexported fields
}

ServerConfig 服务器配置

type X

type X = internal.X

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL