mini

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Success = 0

	MsgTypeText     = 0 // 文本消息
	MsgTypeImage    = 1 // 图片消息
	MsgTypeLink     = 2 // 图文链接
	MsgTypeMiniPage = 3 // 小程序卡片

	TypingTyping = 0 // 对用户下发"正在输入"状态,
	TypingCancel = 1 // 取消对用户的"正在输入"状态

	HostDefault = "https://api.weixin.qq.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken added in v1.1.0

type AccessToken struct {
	AccessToken string `json:"access_token,omitempty"` // 获取到的凭证
	ExpiresIn   int    `json:"expires_in,omitempty"`   // 凭证有效时间,单位:秒。目前是7200秒之内的值。
	Errcode     int    `json:"errcode,omitempty"`      // 错误码
	Errmsg      string `json:"errmsg,omitempty"`       // 错误信息
}

type CheckEncryptedResult added in v1.1.0

type CheckEncryptedResult struct {
	Vaild      bool   `json:"vaild"`             // 是否是合法的数据
	CreateTime int    `json:"create_time"`       // 加密数据生成的时间戳
	Errcode    int    `json:"errcode,omitempty"` // 错误码
	Errmsg     string `json:"errmsg,omitempty"`  // 错误信息
}

type Code2Session added in v1.1.0

type Code2Session struct {
	Openid     string `json:"openid,omitempty"`      // 用户唯一标识
	SessionKey string `json:"session_key,omitempty"` // 会话密钥
	Unionid    string `json:"unionid,omitempty"`     // 用户在开放平台的唯一标识符
	Errcode    int    `json:"errcode,omitempty"`     // 错误码
	Errmsg     string `json:"errmsg,omitempty"`      // 错误信息
}

type ErrorCode added in v1.1.0

type ErrorCode struct {
	Errcode int    `json:"errcode,omitempty"` // 错误码
	Errmsg  string `json:"errmsg,omitempty"`  // 错误信息
}

type KeyInfo added in v1.1.3

type KeyInfo struct {
	EncryptKey string `json:"encrypt_key"`
	Version    int    `json:"version"`
	ExpireIn   int    `json:"expire_in"`
	Iv         string `json:"iv"`
	CreateTime int    `json:"create_time"`
}

type MsgType added in v1.1.0

type MsgType int8

type PaidUnionId added in v1.1.0

type PaidUnionId struct {
	Unionid string `json:"unionid,omitempty"` // 用户在开放平台的唯一标识符
	Errcode int    `json:"errcode,omitempty"` // 错误码
	Errmsg  string `json:"errmsg,omitempty"`  // 错误信息
}

type PhoneNumberRsp added in v1.1.3

type PhoneNumberRsp struct {
	PhoneInfo *UserPhone `json:"phone_info,omitempty"` // 用户手机号信息
	Errcode   int        `json:"errcode,omitempty"`    // 错误码
	Errmsg    string     `json:"errmsg,omitempty"`     // 错误信息
}

type PluginOpenPid added in v1.1.3

type PluginOpenPid struct {
	Openpid string `json:"openpid,omitempty"` // 插件用户的唯一标识
	Errcode int    `json:"errcode,omitempty"` // 错误码
	Errmsg  string `json:"errmsg,omitempty"`  // 错误信息
}

type SDK

type SDK struct {
	DebugSwitch wechat.DebugSwitch
	Appid       string
	Secret      string
	Host        string

	RefreshInternal time.Duration
	// contains filtered or unexported fields
}

func New

func New(appid, secret string, autoManageToken bool) (m *SDK, err error)

New 初始化微信小程序 SDK Appid:Appid Secret:appSecret autoManageToken:是否自动获取并自动维护刷新 AccessToken

func (*SDK) CSMessageGetTempMedia

func (s *SDK) CSMessageGetTempMedia(c context.Context, mediaId string) (media []byte, err error)

CSMessageGetTempMedia 获取客服消息内的临时素材 mediaId:媒体文件 ID 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.getTempMedia.html

func (*SDK) CSMessageSend

func (s *SDK) CSMessageSend(c context.Context, toUser string, msgType MsgType, msgValue bmap.BodyMap) (err error)

CSMessageSend 发送客服消息给用户 注意:errcode = 0 为成功 toUser:小程序用户的 OpenID msgType:消息类型,枚举值:mini.MsgTypeText、mini.MsgTypeImage、mini.MsgTypeLink、mini.MsgTypeMiniPage msgValue:对应 msgType 的value值,BodyMap key-value 格式传入 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.send.html

func (*SDK) CSMessageSetTyping

func (s *SDK) CSMessageSetTyping(c context.Context, toUser string, typingStatus TypingStatus) (err error)

CSMessageSetTyping 下发客服当前输入状态给用户 注意:errcode = 0 为成功 toUser:小程序用户的 OpenID typingStatus:枚举值:mini.TypingTyping、mini.TypingCancel 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.setTyping.html

func (*SDK) CSMessageUploadTempMedia

func (s *SDK) CSMessageUploadTempMedia(c context.Context, img *util.File) (media *UploadTempMedia, err error)

CSMessageUploadTempMedia 把媒体文件上传到微信服务器 注意:errcode = 0 为成功 注意:目前仅支持图片,用于发送客服消息或被动回复用户消息。 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/customer-message/customerServiceMessage.uploadTempMedia.html

func (*SDK) CheckEncryptedData

func (s *SDK) CheckEncryptedData(c context.Context, encryptedData string) (result *CheckEncryptedResult, err error)

CheckEncryptedData 检查加密信息是否由微信生成 注意:errcode = 0 为成功 encryptedData:加密数据,无需sha256操作 注意:(当前只支持手机号加密数据),只能检测最近3天生成的加密数据 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html

func (*SDK) Code2Session

func (s *SDK) Code2Session(c context.Context, wxCode string) (session *Code2Session, err error)

Code2Session 登录凭证校验 注意:errcode = 0 为成功 wxCode:小程序调用 wx.login 获取的code 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html

func (*SDK) DecryptOpenData

func (s *SDK) DecryptOpenData(encryptedData, iv, sessionKey string, ptr interface{}) (err error)

DecryptOpenData 解密开放数据到结构体 encryptedData:包括敏感数据在内的完整用户信息的加密数据,小程序获取到 iv:加密算法的初始向量,小程序获取 sessionKey:会话密钥,通过 sdk.Code2Session() 方法获取到 ptr:需要解析到的结构体指针,例:mini.UserPhone、mini.UserInfo 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

func (*SDK) DoRequestGet added in v1.1.2

func (s *SDK) DoRequestGet(c context.Context, path string, ptr interface{}) (err error)

func (*SDK) GetMiniAccessToken added in v1.1.2

func (s *SDK) GetMiniAccessToken() (at string)

GetMiniAccessToken get mini access token string

func (*SDK) GetPaidUnionid

func (s *SDK) GetPaidUnionid(c context.Context, openid, transactionId string) (unionid *PaidUnionId, err error)

GetPaidUnionid 用户支付完成后,获取该用户的 UnionId,无需用户授权 注意:errcode = 0 为成功 openid:支付用户唯一标识 transactionId:微信支付订单号 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/basic-info/getPaidUnionid.html

func (*SDK) GetPaidUnionidByTradeNo

func (s *SDK) GetPaidUnionidByTradeNo(c context.Context, openid, mchid, tradeNo string) (unionid *PaidUnionId, err error)

GetPaidUnionidByTradeNo 用户支付完成后,获取该用户的 UnionId,无需用户授权 注意:errcode = 0 为成功 openid:支付用户唯一标识 mchid:微信支付商户号 tradeNo:微信支付商户订单号 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html

func (*SDK) GetPhoneNumber added in v1.1.3

func (s *SDK) GetPhoneNumber(c context.Context, code string) (pn *PhoneNumberRsp, err error)

GetPhoneNumber 获取手机号 注意:errcode = 0 为成功 code:手机号获取凭证 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html

func (*SDK) GetPluginOpenPid added in v1.1.3

func (s *SDK) GetPluginOpenPid(c context.Context, code string) (openpid *PluginOpenPid, err error)

GetPluginOpenPid 获取插件用户openpid 注意:errcode = 0 为成功 code:通过 wx.pluginLogin 获得的插件用户标志凭证 code,有效时间为5分钟,一个 code 只能获取一次 openpid 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/basic-info/getPluginOpenPId.html

func (*SDK) GetUserEncryptKey added in v1.1.3

func (s *SDK) GetUserEncryptKey(c context.Context, openid, signature, sigMethod string) (uek *UserEncryptKey, err error)

GetUserEncryptKey 获取用户encryptKey 注意:errcode = 0 为成功 encryptedData:加密数据,无需sha256操作 注意:(当前只支持手机号加密数据),只能检测最近3天生成的加密数据 文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/internet/getUserEncryptKey.html

func (*SDK) SetMiniAccessToken added in v1.1.2

func (s *SDK) SetMiniAccessToken(accessToken string)

SetMiniAccessToken set mini access token string

func (*SDK) SetMiniAccessTokenCallback added in v1.1.2

func (s *SDK) SetMiniAccessTokenCallback(fn func(appid, accessToken string, expireIn int, err error))

SetMiniAccessTokenCallback set mini access token callback listener

func (*SDK) UniformMessageSend

func (s *SDK) UniformMessageSend(c context.Context, toUser string, mpMsg bmap.BodyMap) (err error)

UniformMessageSend 发送统一服务消息 注意:小程序模板消息已下线,不用传 weapp_template_msg 此节点 toUser:用户openid,可以是小程序的openid,也可以是mp_template_msg.appid对应的公众号的openid mpMsg:对应 mp_template_msg 的value值,BodyMap key-value 格式传入 文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/uniform-message/uniformMessage.send.html

func (*SDK) VerifyDecryptOpenData

func (s *SDK) VerifyDecryptOpenData(rowData, signature, sessionKey string) (ok bool)

VerifyDecryptOpenData 数据签名校验 rowData、signature:通过调用接口(如 wx.getUserInfo)获取数据时,接口会同时返回 rawData、signature sessionKey:会话密钥,通过 sdk.Code2Session() 方法获取到 文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

type TypingStatus added in v1.1.0

type TypingStatus int8

type UploadTempMedia added in v1.1.0

type UploadTempMedia struct {
	MediaId   string     `json:"media_id"`          // 媒体文件上传后,获取标识,3天内有效。
	Type      string     `json:"type"`              // 文件类型
	CreatedAt xtime.Time `json:"created_at"`        // 媒体文件上传时间戳
	Errcode   int        `json:"errcode,omitempty"` // 错误码
	Errmsg    string     `json:"errmsg,omitempty"`  // 错误信息
}

type UserEncryptKey added in v1.1.3

type UserEncryptKey struct {
	Errcode     int        `json:"errcode"`
	Errmsg      string     `json:"errmsg"`
	KeyInfoList []*KeyInfo `json:"key_info_list"`
}

type UserInfo added in v1.1.0

type UserInfo struct {
	OpenId    string         `json:"openId,omitempty"`
	NickName  string         `json:"nickName,omitempty"`
	Gender    int            `json:"gender,omitempty"`
	City      string         `json:"city,omitempty"`
	Province  string         `json:"province,omitempty"`
	Country   string         `json:"country,omitempty"`
	AvatarUrl string         `json:"avatarUrl,omitempty"`
	UnionId   string         `json:"unionId,omitempty"`
	Watermark *watermarkInfo `json:"watermark,omitempty"`
}

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

type UserPhone added in v1.1.0

type UserPhone struct {
	PhoneNumber     string         `json:"phoneNumber,omitempty"`
	PurePhoneNumber string         `json:"purePhoneNumber,omitempty"`
	CountryCode     string         `json:"countryCode,omitempty"`
	Watermark       *watermarkInfo `json:"watermark,omitempty"`
}

微信小程序解密后 用户手机号

Jump to

Keyboard shortcuts

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