Documentation ¶
Index ¶
- Constants
- type AccessToken
- type CheckEncryptedResult
- type Code2Session
- type ErrorCode
- type KeyInfo
- type MsgType
- type PaidUnionId
- type PhoneNumberRsp
- type PluginOpenPid
- type SDK
- func (s *SDK) CSMessageGetTempMedia(c context.Context, mediaId string) (media []byte, err error)
- func (s *SDK) CSMessageSend(c context.Context, toUser string, msgType MsgType, msgValue bmap.BodyMap) (err error)
- func (s *SDK) CSMessageSetTyping(c context.Context, toUser string, typingStatus TypingStatus) (err error)
- func (s *SDK) CSMessageUploadTempMedia(c context.Context, img *util.File) (media *UploadTempMedia, err error)
- func (s *SDK) CheckEncryptedData(c context.Context, encryptedData string) (result *CheckEncryptedResult, err error)
- func (s *SDK) Code2Session(c context.Context, wxCode string) (session *Code2Session, err error)
- func (s *SDK) DecryptOpenData(encryptedData, iv, sessionKey string, ptr interface{}) (err error)
- func (s *SDK) DoRequestGet(c context.Context, path string, ptr interface{}) (err error)
- func (s *SDK) GetMiniAccessToken() (at string)
- func (s *SDK) GetPaidUnionid(c context.Context, openid, transactionId string) (unionid *PaidUnionId, err error)
- func (s *SDK) GetPaidUnionidByTradeNo(c context.Context, openid, mchid, tradeNo string) (unionid *PaidUnionId, err error)
- func (s *SDK) GetPhoneNumber(c context.Context, code string) (pn *PhoneNumberRsp, err error)
- func (s *SDK) GetPluginOpenPid(c context.Context, code string) (openpid *PluginOpenPid, err error)
- func (s *SDK) GetUserEncryptKey(c context.Context, openid, signature, sigMethod string) (uek *UserEncryptKey, err error)
- func (s *SDK) SetMiniAccessToken(accessToken string)
- func (s *SDK) SetMiniAccessTokenCallback(fn func(appid, accessToken string, expireIn int, err error))
- func (s *SDK) UniformMessageSend(c context.Context, toUser string, mpMsg bmap.BodyMap) (err error)
- func (s *SDK) VerifyDecryptOpenData(rowData, signature, sessionKey string) (ok bool)
- type TypingStatus
- type UploadTempMedia
- type UserEncryptKey
- type UserInfo
- type UserPhone
Constants ¶
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 CheckEncryptedResult ¶ added in v1.1.0
type Code2Session ¶ added in v1.1.0
type PaidUnionId ¶ added in v1.1.0
type PhoneNumberRsp ¶ added in v1.1.3
type PluginOpenPid ¶ added in v1.1.3
type SDK ¶
type SDK struct { DebugSwitch wechat.DebugSwitch Appid string Secret string Host string RefreshInternal time.Duration // contains filtered or unexported fields }
func (*SDK) CSMessageGetTempMedia ¶
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 ¶
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 ¶
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 (*SDK) GetMiniAccessToken ¶ added in v1.1.2
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
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
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
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 ¶
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 ¶
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 UserEncryptKey ¶ added in v1.1.3
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"` }
微信小程序解密后 用户信息