wxmp

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiWxmp

type ApiWxmp interface {
	api.ApiCommon

	/*
	 * 通过code换取openid和unionid
	 *
	 * 参考:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html
	 */
	Login(code string) (string, string, error) // 获取OpenId和UnionId

	/*
	 * 解密用户信息
	 *
	 * 参考:https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserInfo.html
	 */
	DecryptUserInfo(encryptedData, iv string) (*UserInfo, error) // 解密有用户信息

	/*
	 * Deprecated: 已弃用,请使用GetUserPhoneNumber
	 */
	DecryptMobileInfo(encryptedData, iv string) (*MobileInfo, error) // 解密手机号码信息
	/*
	 * 创建永久有效的小程序码,可接受path参数较长,生成个数受限
	 * 参考:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/createQRCode.html
	 */
	CreateLimitedWxaCode(path string, width int, options ...WxaCodeOption) ([]byte, error)
	/*
	 * 生成小程序码,可接受页面参数较短,生成个数不受限
	 * 参考:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
	 */
	CreateUnLimitedWxaCode(scene, page string, width int, options ...WxaCodeOption) ([]byte, error)
	/*
	 * 快速手机号验证
	 * 参考: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
	 */
	GetUserPhoneNumber(code string) (*MobileInfo, error)
}

func New

func New(appId, appSecret string, redisProvider intf.RedisProvider) (ApiWxmp, error)

type GetUserPhoneNumberResult

type GetUserPhoneNumberResult struct {
	api.ApiResult
	PhoneInfo MobileInfo `json:"phone_info"`
}

type LimitedWxmpCode

type LimitedWxmpCode struct {
	*WxmpCodeConfig
	// 扫码进入的小程序页面路径,最大长度 128 字节,不能为空;
	// 对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar",
	// 即可在 wx.getLaunchOptionsSync 接口中的 query 参数获取到 {foo:"bar"}。
	Path string `json:"path"`
}

type MobileInfo

type MobileInfo struct {
	PhoneNumber     string `json:"phoneNumber"`
	PurePhoneNumber string `json:"purePhoneNumber"`
	CountryCode     string `json:"countryCode"`
	Watermark       struct {
		AppId     string      `json:"appid"`
		Timestamp interface{} `json:"timestamp"`
	} `json:"watermark"`
}

type UnlimitedWxmpCode

type UnlimitedWxmpCode struct {
	*WxmpCodeConfig
	// 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
	Scene string `json:"scene"`
	// 页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面
	Page      string `json:"page"`
	CheckPath bool   `json:"check_path"`
}

type UserInfo

type UserInfo struct {
	OpenID    string `json:"openId"`
	UnionID   string `json:"unionId"`
	NickName  string `json:"nickName"`
	Gender    int    `json:"gender"`
	City      string `json:"city"`
	Province  string `json:"province"`
	Country   string `json:"country"`
	AvatarUrl string `json:"avatarUrl"`
	Language  string `json:"language"`
	Watermark struct {
		Timestamp int64  `json:"timestamp"`
		AppId     string `json:"appid"`
	} `json:"watermark"`
}

type WxaCodeOption

type WxaCodeOption func(*WxmpCodeConfig)

func Develop

func Develop() WxaCodeOption

func Trial

func Trial() WxaCodeOption

type WxmpCodeConfig

type WxmpCodeConfig struct {
	// 要打开的小程序版本。正式版为 release,体验版为 trial,开发版为 develop
	EnvVersion string `json:"env_version"`
	// 二维码的宽度,单位 px。最小 280px,最大 1280px
	Width int `json:"width"`
	// auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
	AutoColor bool `json:"auto_color"`
	// auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示
	LineColor struct {
		R int `json:"r"`
		G int `json:"g"`
		B int `json:"b"`
	} `json:"line_color"`
	// 是否需要透明底色,为 true 时,生成透明底色的小程序码
	IsHyaline bool `json:"is_hyaline"`
}

WxmpCodeConfig 微信小程序码配置

Jump to

Keyboard shortcuts

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