miniprogram

package
v1.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Code2SessionURL 小程序登录凭证校验地址
	Code2SessionURL = "https://api.weixin.qq.com/sns/jscode2session"

	// GetPhoneNumberURL 通过组件 code 换取手机号地址
	GetPhoneNumberURL = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"

	// AccessTokenURL 获取小程序 access_token 地址
	AccessTokenURL = "https://api.weixin.qq.com/cgi-bin/token"

	// StableTokenURL 获取小程序稳定版 access_token 地址
	StableTokenURL = "https://api.weixin.qq.com/cgi-bin/stable_token"

	// GrantTypeAuthorizationCode 授权类型:authorization_code
	GrantTypeAuthorizationCode = "authorization_code"

	// GrantTypeClientCredential 授权类型:client_credential
	GrantTypeClientCredential = "client_credential"

	// SubscribeMessageSendURL 发送订阅消息地址
	SubscribeMessageSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send"

	// MsgSecCheckURL 内容安全检测(文本)地址
	MsgSecCheckURL = "https://api.weixin.qq.com/wxa/msg_sec_check"

	// MediaCheckAsyncURL 内容安全检测(音视频异步)地址,检测结果通过消息推送异步告知
	MediaCheckAsyncURL = "https://api.weixin.qq.com/wxa/media_check_async"

	// GetWxaCodeURL 获取小程序码(带 path 参数,数量有限制)地址
	GetWxaCodeURL = "https://api.weixin.qq.com/wxa/getwxacode"

	// GetWxaCodeUnlimitURL 获取小程序码(带 scene 参数,数量不限)地址
	GetWxaCodeUnlimitURL = "https://api.weixin.qq.com/wxa/getwxacodeunlimit"

	// CreateWxaQrcodeURL 获取小程序二维码(旧接口,带 path 参数)地址
	CreateWxaQrcodeURL = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode"
)

微信小程序相关 API 地址

View Source
const (
	SubscribeMsgStateFormal    = "formal"    // 正式版
	SubscribeMsgStateTrial     = "trial"     // 体验版
	SubscribeMsgStateDeveloper = "developer" // 开发版
)

订阅消息 miniprogram_state 取值

View Source
const (
	SubscribeMsgLangZhCN = "zh_CN" // 简体中文
	SubscribeMsgLangZhHK = "zh_HK" // 繁体中文(香港)
	SubscribeMsgLangZhTW = "zh_TW" // 繁体中文(台湾)
	SubscribeMsgLangEn   = "en_US" // 英文
)

订阅消息 lang 取值

View Source
const (
	SecCheckSceneProfile = 1 // 资料
	SecCheckSceneComment = 2 // 评论
	SecCheckSceneForum   = 3 // 论坛
	SecCheckSceneSocial  = 4 // 社交日志
)

内容安全检测 scene 取值

View Source
const (
	SecCheckMediaTypeAudio = 1 // 音频
	SecCheckMediaTypeImage = 2 // 图片
)

内容安全检测 media_type 取值 官方文档:https://developers.weixin.qq.com/miniprogram/dev/server/API/sec-center/sec-check/api_mediacheckasync.html 官方原文「1:音频;2:图片」,官方不存在视频类型(提交视频将返回 40004)

View Source
const (
	EnvVersionRelease = "release" // 正式版
	EnvVersionTrial   = "trial"   // 体验版
	EnvVersionDevelop = "develop" // 开发版
)

小程序码 env_version 取值

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 微信小程序客户端

func NewClient deprecated

func NewClient(config *Config, opts ...any) *Client

NewClient 创建新的小程序客户端(使用默认文件存储)

Deprecated: 配置或存储非法时会直接 log.Panic 终止进程,依赖库不应越权决定宿主进程生死。 请改用 NewClientE。

func NewClientE added in v0.1.3

func NewClientE(config *Config, opts ...any) (*Client, error)

NewClientE 创建新的小程序客户端(使用默认文件存储),出错时返回 error 而不是 panic

参数:

  • config: 小程序配置信息
  • opts: 可选参数,支持 debugger.LoggerInterface 与 core.HTTPClient

返回:

  • *Client: 小程序客户端实例
  • error: 文件存储创建失败或配置校验失败时返回错误

func NewClientWithStorage deprecated

func NewClientWithStorage(config *Config, tokenStorage storage.TokenStorage, opts ...any) *Client

NewClientWithStorage 创建新的小程序客户端(使用自定义存储)

Deprecated: 配置非法时会直接 log.Panic 终止进程,请改用 NewClientWithStorageE。

func NewClientWithStorageE added in v0.1.3

func NewClientWithStorageE(config *Config, tokenStorage storage.TokenStorage, opts ...any) (*Client, error)

NewClientWithStorageE 创建新的小程序客户端(使用自定义存储),出错时返回 error 而不是 panic

参数:

  • config: 小程序配置信息
  • tokenStorage: 自定义存储实例
  • opts: 可选参数,支持 debugger.LoggerInterface 与 core.HTTPClient

返回:

  • *Client: 小程序客户端实例
  • error: 配置校验失败时返回错误

func (*Client) Code2Session

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

Code2Session 小程序登录凭证校验

参数:

  • ctx: 上下文
  • code: 前端 wx.login 获取的临时登录凭证

返回:

  • *Code2SessionResponse: 登录凭证校验结果
  • error: 请求失败或微信返回错误时返回错误

文档:

func (*Client) CreateWxaQrcode added in v0.2.0

func (c *Client) CreateWxaQrcode(ctx context.Context, req *CreateWxaQrcodeRequest) (*WXACodeResponse, error)

CreateWxaQrcode 获取小程序二维码(旧接口,带 path,总数上限 10 万)

参数:

  • ctx: 上下文
  • req: 请求参数

返回:

  • *WXACodeResponse: Data 为图片二进制数据
  • error: 请求失败或微信返回错误时返回错误

文档:

func (*Client) DecryptUserInfo

func (c *Client) DecryptUserInfo(sessionKey, encryptedData, iv string, result interface{}) error

DecryptUserInfo 解密微信小程序用户信息或手机号

参数:

  • sessionKey: 登录接口返回的 session_key,Base64 编码
  • encryptedData: 前端返回的 encryptedData,Base64 编码
  • iv: 前端返回的 iv,Base64 编码
  • result: 解密后 JSON 反序列化的目标结构体指针

返回:

  • error: 解密失败或水印校验不通过时返回错误

示例:

var userInfo miniprogram.UserInfo
err := client.DecryptUserInfo(sessionKey, encryptedData, iv, &userInfo)

func (*Client) GetAccessToken

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

GetAccessToken 获取小程序 access_token

参数:

  • ctx: 上下文

返回:

  • string: access_token
  • error: 获取失败时返回错误

func (*Client) GetConfig

func (c *Client) GetConfig() *Config

GetConfig 获取配置信息

返回:

  • *Config: 小程序配置副本指针

func (*Client) GetLogger

func (c *Client) GetLogger() logger.LoggerInterface

GetLogger 获取日志器

返回:

  • logger.LoggerInterface: 日志器实例

func (*Client) GetPhoneNumber

func (c *Client) GetPhoneNumber(ctx context.Context, code string, openid ...string) (*GetPhoneNumberResponse, error)

GetPhoneNumber 通过组件 code 换取用户手机号

参数:

  • ctx: 上下文
  • code: 前端 getPhoneNumber 组件返回的动态令牌
  • openid: 可选参数,用户唯一标识,填入后微信会校验 openid 与 code 的绑定关系

返回:

  • *GetPhoneNumberResponse: 手机号换取结果
  • error: 请求失败或微信返回错误时返回错误

文档:

func (*Client) GetStableAccessToken added in v0.2.0

func (c *Client) GetStableAccessToken(ctx context.Context, forceRefresh bool) (*StableAccessTokenResponse, error)

GetStableAccessToken 获取稳定版 access_token(POST /cgi-bin/stable_token)

稳定版 access_token:结果不下发/不依赖缓存,单 appid 调用频率限制见官方文档。 普通模式(forceRefresh=false)有效期内重复调用返回相同 token; 强制刷新(forceRefresh=true)受官方限频约束(每天次数与最小间隔限制,见官方文档)。

注意:本方法仅直接调用接口并返回结果,不写入现有 token 缓存, 也不会改变 GetAccessToken 的默认 token 获取路径。

参数:

  • ctx: 上下文
  • forceRefresh: 是否强制刷新(对应官方请求字段 force_refresh)

返回:

  • *StableAccessTokenResponse: 包含 AccessToken 与 ExpiresIn
  • error: 请求失败或微信返回错误时返回错误

文档:

func (*Client) GetWxaCode added in v0.2.0

func (c *Client) GetWxaCode(ctx context.Context, req *GetWxaCodeRequest) (*WXACodeResponse, error)

GetWxaCode 获取不限制数量之外的小程序码(带 path,总数上限 10 万)

参数:

  • ctx: 上下文
  • req: 请求参数

返回:

  • *WXACodeResponse: Data 为图片二进制数据
  • error: 请求失败或微信返回错误时返回错误

使用示例:

resp, err := client.GetWxaCode(ctx, &miniprogram.GetWxaCodeRequest{Path: "pages/index/index", Width: 430})
if err == nil { os.WriteFile("qrcode.jpg", resp.Data, 0644) }

文档:

func (*Client) GetWxaCodeUnlimit added in v0.2.0

func (c *Client) GetWxaCodeUnlimit(ctx context.Context, req *GetWxaCodeUnlimitRequest) (*WXACodeResponse, error)

GetWxaCodeUnlimit 获取不限量的小程序码(带 scene 参数,数量暂无限制)

参数:

  • ctx: 上下文
  • req: 请求参数(Scene 必填,最长 32 个可见字符)

返回:

  • *WXACodeResponse: Data 为图片二进制数据
  • error: 请求失败或微信返回错误时返回错误

使用示例:

resp, err := client.GetWxaCodeUnlimit(ctx, &miniprogram.GetWxaCodeUnlimitRequest{
	Scene: "id=123",
	Page:  "pages/detail/index",
})
if err == nil { os.WriteFile("qrcode.jpg", resp.Data, 0644) }

文档:

func (*Client) MediaCheckAsync added in v0.2.0

func (c *Client) MediaCheckAsync(ctx context.Context, mediaURL string, mediaType int, openID string, scene int) (*MediaCheckAsyncResponse, error)

MediaCheckAsync 音视频内容安全检测(异步,检测结果通过消息推送服务器异步告知)

参数:

  • ctx: 上下文
  • mediaURL: 要检测的媒体资源 url
  • mediaType: 媒体类型(官方 v2 取值:1音频 2图片;官方不存在视频类型)
  • openID: 内容发布用户的 openid
  • scene: 场景值(1资料 2评论 3论坛 4社交日志)

返回:

  • *MediaCheckAsyncResponse: 提交结果(携带 TraceID,实际检测结果走消息推送)
  • error: 请求失败或微信返回错误时返回错误

注意: 异步检测结果通过小程序消息推送(wxa_media_check 推送事件)送达,需在消息推送服务中处理。

文档:

func (*Client) MsgSecCheck added in v0.2.0

func (c *Client) MsgSecCheck(ctx context.Context, content, openID string, scene int) (*MsgSecCheckResponse, error)

MsgSecCheck 文本内容安全检测(同步返回结果,便捷方法)

参数:

  • ctx: 上下文
  • content: 要检测的文本内容(最长 2500 字)
  • openID: 内容发布用户的 openid
  • scene: 场景值(1资料 2评论 3论坛 4社交日志)

返回:

  • *MsgSecCheckResponse: 检测结果(Result.Suggest 为 pass/review/risky)
  • error: 请求失败或微信返回错误时返回错误

使用示例:

resp, err := client.MsgSecCheck(ctx, "待检测文本", openid, miniprogram.SecCheckSceneComment)
if err == nil && resp.Result.Suggest == "risky" { /* 拦截内容 */ }

文档:

func (*Client) MsgSecCheckFull added in v0.2.0

func (c *Client) MsgSecCheckFull(ctx context.Context, req *MsgSecCheckRequest) (*MsgSecCheckResponse, error)

MsgSecCheckFull 文本内容安全检测完整参数方法(同步返回结果)

相比便捷方法 MsgSecCheck,本方法接受完整请求参数,可透传官方扩展检测字段: title(文本标题)、nickname(用户昵称)、signature(个性签名,仅 scene=1 有效)、 head_avatar(用户头像画像检测,官方 v2 初版能力)。

参数:

  • ctx: 上下文
  • req: 完整请求参数(openid 与 scene 必填;version 未填时默认取 2)

返回:

  • *MsgSecCheckResponse: 检测结果(Result.Suggest 为 pass/review/risky)
  • error: 参数缺失或请求失败时返回错误

使用示例:

resp, err := client.MsgSecCheckFull(ctx, &miniprogram.MsgSecCheckRequest{
	Content: "待检测文本",
	OpenID:  openid,
	Scene:   miniprogram.SecCheckSceneProfile,
	Version: 2,
	Nickname:   "用户昵称",
	HeadAvatar: "https://thirdwx.qlogo.cn/...",
})

文档:

func (*Client) SendSubscribeMessage added in v0.2.0

SendSubscribeMessage 发送订阅消息

参数:

  • ctx: 上下文
  • req: 发送请求(ToUser/TemplateID/Data 必填;MiniprogramState/Lang 传空时由微信按默认值处理)

返回:

  • *SendSubscribeMessageResponse: 发送结果
  • error: 请求失败或微信返回错误时返回错误

使用示例:

resp, err := client.SendSubscribeMessage(ctx, &miniprogram.SendSubscribeMessageRequest{
	ToUser:     "openid",
	TemplateID: "template_id",
	Page:       "pages/index/index",
	Data: miniprogram.SubscribeMessageData{
		"thing1": {Value: "审核通过"},
		"time2":  {Value: "2026-10-22 20:00"},
	},
})

文档:

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client core.HTTPClient)

SetHTTPClient 设置自定义 HTTP 客户端

参数:

  • client: 自定义 HTTP 客户端

func (*Client) SetLogger

func (c *Client) SetLogger(log debugger.LoggerInterface)

SetLogger 设置自定义日志器

参数:

  • log: 自定义日志器,nil 则使用默认日志器

type Code2SessionResponse

type Code2SessionResponse struct {
	core.APIResponse
	OpenID     string `json:"openid"`            // 用户唯一标识
	SessionKey string `json:"session_key"`       // 会话密钥
	UnionID    string `json:"unionid,omitempty"` // 用户在开放平台的唯一标识,可能为空
}

Code2SessionResponse 小程序登录凭证校验响应

type Config

type Config struct {
	AppID     string `json:"app_id" ini:"app_id"`         // 小程序 appid
	AppSecret string `json:"app_secret" ini:"app_secret"` // 小程序 appsecret
}

Config 微信小程序配置结构体

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置的有效性

返回:

  • error: 配置无效时返回错误

type CreateWxaQrcodeRequest added in v0.2.0

type CreateWxaQrcodeRequest struct {
	Path  string `json:"path"`            // 页面路径(不能带参数,官方必填,长度小于 128 字符)
	Width int    `json:"width,omitempty"` // 二维码宽度(280-1280,默认 430)
}

CreateWxaQrcodeRequest 获取小程序二维码请求(createwxaqrcode,旧接口)

注意:path 长度小于 128 字符,总数量 10 万个,生成后数量无法增减。

type GetPhoneNumberRequest

type GetPhoneNumberRequest struct {
	Code   string `json:"code"`             // 前端 getPhoneNumber 组件返回的动态令牌
	OpenID string `json:"openid,omitempty"` // 可选,用户唯一标识,填入后微信会校验 openid 与 code 的绑定关系
}

GetPhoneNumberRequest 通过组件 code 换取手机号请求

type GetPhoneNumberResponse

type GetPhoneNumberResponse struct {
	core.APIResponse
	PhoneInfo PhoneInfo `json:"phone_info"` // 手机号信息
}

GetPhoneNumberResponse 通过组件 code 换取手机号响应

type GetWxaCodeRequest added in v0.2.0

type GetWxaCodeRequest struct {
	Path       string     `json:"path"`                  // 页面路径(官方必填,最长 1024 字符)
	Width      int        `json:"width,omitempty"`       // 小程序码宽度(280-1280,默认 430)
	AutoColor  bool       `json:"auto_color"`            // 自动配置线条颜色
	LineColor  *LineColor `json:"line_color,omitempty"`  // 线条颜色(auto_color 为 false 时生效)
	IsHyaline  bool       `json:"is_hyaline"`            // 是否需要透明底色
	EnvVersion string     `json:"env_version,omitempty"` // 小程序版本:release/trial/develop
}

GetWxaCodeRequest 获取小程序码请求(getwxacode)

注意:path 为官方必填参数(最长 1024 字符,可携带页面参数,空将返回 40159 错误), 与 createwxaqrcode 生成的码总数上限共 10 万(超限报 45029),如需大量生成请使用 getwxacodeunlimit。

type GetWxaCodeUnlimitRequest added in v0.2.0

type GetWxaCodeUnlimitRequest struct {
	Scene      string     `json:"scene"`                 // 业务参数(最长 32 个可见字符,必填)
	Page       string     `json:"page,omitempty"`        // 页面路径(必须为已发布页面),空则默认主页
	CheckPath  *bool      `json:"check_path,omitempty"`  // 校验 page 是否存在(不传时官方默认 true;传 false 时不校验,未发布页面可能无法正常打开)
	EnvVersion string     `json:"env_version,omitempty"` // 小程序版本:release/trial/develop
	Width      int        `json:"width,omitempty"`       // 小程序码宽度(280-1280,默认 430)
	AutoColor  bool       `json:"auto_color"`            // 自动配置线条颜色
	LineColor  *LineColor `json:"line_color,omitempty"`  // 线条颜色(auto_color 为 false 时生效)
	IsHyaline  bool       `json:"is_hyaline"`            // 是否需要透明底色
}

GetWxaCodeUnlimitRequest 获取小程序码请求(getwxacodeunlimit)

注意:scene 参数即小程序码携带的业务参数(最长 32 个可见字符),页面通过 onLoad(query.scene) 获取。

type LineColor added in v0.2.0

type LineColor struct {
	R int `json:"r"` // 红色分量(0-255)
	G int `json:"g"` // 绿色分量(0-255)
	B int `json:"b"` // 蓝色分量(0-255)
}

LineColor 小程序码线条颜色(RGB)

type MediaCheckAsyncRequest added in v0.2.0

type MediaCheckAsyncRequest struct {
	MediaURL  string `json:"media_url"`  // 要检测的图片或音频的 url(官方 v2 仅支持图片和音频,单个文件不超过 10M)
	MediaType int    `json:"media_type"` // 媒体类型(官方 v2 取值):1音频 2图片
	Version   int    `json:"version"`    // 接口版本号,固定填 2(官方参数类型为 number)
	OpenID    string `json:"openid"`     // 用户的 openid(用户需在近两小时访问过小程序)
	Scene     int    `json:"scene"`      // 场景值:1资料 2评论 3论坛 4社交日志
}

MediaCheckAsyncRequest 音视频内容安全检测请求(version 2,异步)

type MediaCheckAsyncResponse added in v0.2.0

type MediaCheckAsyncResponse struct {
	core.APIResponse
	TraceID string `json:"trace_id"` // 追踪 ID,检测结果推送时会携带该值
}

MediaCheckAsyncResponse 音视频内容安全检测响应(结果通过消息推送异步告知)

type MsgSecCheckRequest added in v0.2.0

type MsgSecCheckRequest struct {
	Content    string `json:"content"`               // 要检测的文本内容(最长 2500 字)
	Version    int    `json:"version"`               // 接口版本号,固定填 2(官方参数类型为 number)
	OpenID     string `json:"openid"`                // 用户的 openid(用户需在近两小时访问过小程序)
	Scene      int    `json:"scene"`                 // 场景值:1资料 2评论 3论坛 4社交日志
	Title      string `json:"title,omitempty"`       // 文本标题(可选,需填写内容标题)
	Nickname   string `json:"nickname,omitempty"`    // 用户昵称(可选)
	Signature  string `json:"signature,omitempty"`   // 个性签名(可选,仅在资料类场景 scene=1 有效)
	HeadAvatar string `json:"head_avatar,omitempty"` // 用户头像图片临时链接(可选,用于头像画像检测;官方 v2 初版参数表含此字段,现行参数表已不再列出,保守保留——微信侧会忽略未知字段)
}

MsgSecCheckRequest 文本内容安全检测请求(version 2)

注意:v2 接口必须传入内容发布用户的 openid 与 scene,否则会报错。 参考文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/sec-center/sec-check/msgSecCheck.html

type MsgSecCheckResponse added in v0.2.0

type MsgSecCheckResponse struct {
	core.APIResponse
	Result  *MsgSecCheckResult `json:"result"`   // 检测结果(errcode 为 0 时存在)
	TraceID string             `json:"trace_id"` // 追踪 ID,用于异步结果关联与工单排查
	Detail  []struct {
		Strategy string `json:"strategy"`
		ErrCode  int    `json:"errcode"`
		Suggest  string `json:"suggest"`
		Label    int    `json:"label"` // 命中标签枚举值:100正常 10001广告 20001时政 20002色情 20003辱骂 20006违法犯罪 20008欺诈 20012低俗 20013版权 21000其他
		Prob     int    `json:"prob"`
		Keyword  string `json:"keyword,omitempty"` // 命中的自定义关键词
	} `json:"detail"`
}

MsgSecCheckResponse 文本内容安全检测响应

type MsgSecCheckResult added in v0.2.0

type MsgSecCheckResult struct {
	Suggest string `json:"suggest"` // 建议:pass(通过)/review(需人工复审)/risky(不通过)
	Label   int    `json:"label"`   // 命中标签枚举值:100正常 10001广告 20001时政 20002色情 20003辱骂 20006违法犯罪 20008欺诈 20012低俗 20013版权 21000其他
}

MsgSecCheckResult 检测结果

type PhoneInfo

type PhoneInfo struct {
	PhoneNumber     string     `json:"phoneNumber"`         // 用户绑定的手机号(国外手机号会有国家码)
	PurePhoneNumber string     `json:"purePhoneNumber"`     // 没有国家码的手机号
	CountryCode     string     `json:"countryCode"`         // 国家码
	Watermark       *Watermark `json:"watermark,omitempty"` // 数据水印
}

PhoneInfo 手机号信息

type SendSubscribeMessageRequest added in v0.2.0

type SendSubscribeMessageRequest struct {
	ToUser           string               `json:"touser"`                      // 接收用户的 OpenID
	TemplateID       string               `json:"template_id"`                 // 订阅消息模板 ID
	Page             string               `json:"page,omitempty"`              // 点击模板卡片跳转页面(空则无跳转)
	MiniprogramState string               `json:"miniprogram_state,omitempty"` // 跳转小程序类型:formal/trial/developer(不传时由微信按默认值处理)
	Lang             string               `json:"lang,omitempty"`              // 语言类型:zh_CN/zh_HK/zh_TW/en_US(不传时官方默认 zh_CN)
	Data             SubscribeMessageData `json:"data"`                        // 模板内容
}

SendSubscribeMessageRequest 发送订阅消息请求

type SendSubscribeMessageResponse added in v0.2.0

type SendSubscribeMessageResponse struct {
	core.APIResponse
}

SendSubscribeMessageResponse 发送订阅消息响应

type StableAccessTokenRequest added in v0.2.0

type StableAccessTokenRequest struct {
	GrantType    string `json:"grant_type"`              // 获取 access_token 固定填 client_credential
	AppID        string `json:"appid"`                   // 小程序 appid
	Secret       string `json:"secret"`                  // 小程序 appsecret
	ForceRefresh bool   `json:"force_refresh,omitempty"` // 是否强制刷新,true-是;false-否
}

StableAccessTokenRequest 获取稳定版 access_token 请求参数

type StableAccessTokenResponse added in v0.2.0

type StableAccessTokenResponse struct {
	core.APIResponse
	AccessToken string `json:"access_token"` // 获取到的凭证
	ExpiresIn   int    `json:"expires_in"`   // 凭证有效时间,单位:秒(正常为 7200)
}

StableAccessTokenResponse 获取稳定版 access_token 响应

type SubscribeMessageData added in v0.2.0

type SubscribeMessageData map[string]SubscribeMessageDataValue

SubscribeMessageData 订阅消息数据,key 为模板字段编号(如 thing1、time2)

type SubscribeMessageDataValue added in v0.2.0

type SubscribeMessageDataValue struct {
	Value string `json:"value"` // 模板字段值
}

SubscribeMessageDataValue 订阅消息数据项的值

type UserInfo

type UserInfo struct {
	OpenID    string    `json:"openId"`            // 用户 openId
	NickName  string    `json:"nickName"`          // 用户昵称
	Gender    int       `json:"gender"`            // 用户性别,0 未知,1 男,2 女
	City      string    `json:"city"`              // 用户所在城市
	Province  string    `json:"province"`          // 用户所在省份
	Country   string    `json:"country"`           // 用户所在国家
	AvatarURL string    `json:"avatarUrl"`         // 用户头像 URL
	UnionID   string    `json:"unionId,omitempty"` // 用户在开放平台的唯一标识
	Watermark Watermark `json:"watermark"`         // 数据水印
}

UserInfo 解密后的微信小程序用户信息

type WXACodeResponse added in v0.2.0

type WXACodeResponse struct {
	core.APIResponse
	Data        []byte `json:"-"` // 图片二进制数据
	ContentType string `json:"-"` // 响应 Content-Type(如 image/jpeg)
	NumUsed     string `json:"-"` // 响应头 Num-Used(已生成码数量,与 10 万总量上限对照;官方在 getwxacode/createQRCode 文档记载该头,getwxacodeunlimit 无总量限制,官方未记载其返回,为空属正常)
}

WXACodeResponse 小程序码/二维码接口响应

成功时 Data 为图片二进制数据,ContentType 为图片类型;失败时微信返回 JSON 错误。

type Watermark

type Watermark struct {
	AppID     string `json:"appid"`     // 小程序 appid
	Timestamp int64  `json:"timestamp"` // 数据水印时间戳
	Nonce     string `json:"nonce"`     // 随机字符串(getuserphonenumber 响应的水印携带)
}

Watermark 微信开放数据水印

字段说明:

  • AppID: 数据归属的小程序 appid
  • Timestamp: 数据生成时间戳

注意:

  • 官方建议服务端解密后校验 watermark.appid 是否与自身 appid 一致
  • 可结合 timestamp 做时效性校验

文档:

Jump to

Keyboard shortcuts

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