Documentation ¶
Index ¶
- Constants
- func Concat(args ...string) string
- func JsonTo(v interface{}, indent bool) string
- func MaskAccessTokenByCodeOpenUrl(cp cache.Provider, url, componentAppId, code string) (result string, err error)
- func MaskAccessTokenUrl(cp cache.Provider, logger *log.Slf4g, appId string) (string, bool)
- func MaskAuthorizationAccessTokenUrl(cp cache.Provider, logger *log.Slf4g, appId string) (string, bool)
- func XmlTo(v interface{}, indent bool) string
- type AccessTokenModel
- type Adapter
- type Api
- type AuthorizationInfo
- type CallbackMessage
- type CallbackModel
- type Crypter
- type EncryptedMessage
- type ErrorModel
- type MsgType
- type TicketType
- type WeChatThirdCrypter
- type WechatApi
- type WxType
Constants ¶
const ( ApiUrl = "https://api.weixin.qq.com" CacheNeverTimeout = -1 // 第三方平台或公众号接口调用令牌默认过期时间 TextMessageKey = "wechat:tm:%s" TicketKey = "wechat:%s:ticket" TokenKey = "wechat:%s:token" AuthorizationKey = "wechat:%s:authorization" AccessTokenKey = "wechat:%s:access_token" JsApiTicketKey = "wechat:%s:js_api_ticket" RefreshTime = "wechat:%s:refresh_time" )
const CallUserAgent = "Mozilla/5.0 (Linux x86_64) TitanWechat/1.0.0"
Variables ¶
This section is empty.
Functions ¶
func MaskAccessTokenUrl ¶
Types ¶
type AccessTokenModel ¶
type AccessTokenModel struct { ErrorModel AccessToken string `json:"access_token"` Expire int `json:"expires_in"` }
AccessTokenModel 服务端accesstoken接口返回参数说明 属性 类型 说明 access_token string 获取到的凭证 expires_in number 凭证有效时间,单位:秒。目前是7200秒之内的值。 errcode number 错误码 errmsg string 错误信息
返回errcode的合法值 值 说明 -1 系统繁忙,此时请开发者稍候再试 0 请求成功 40001 AppSecret 错误或者 AppSecret 不属于这个小程序,请开发者确认 AppSecret 的正确性 40002 请确保 grant_type 字段值为 client_credential 40013 不合法的 AppID,请开发者检查 AppID 的正确性,避免异常字符,注意大小写
type Adapter ¶
type Adapter interface { GetKey() []string CallBack(CallbackModel) string GetValue(context []byte, value interface{}) error }
func NewAdapter ¶
func NewAdapter(key []string, call func(CallbackModel, Adapter) string) Adapter
type AuthorizationInfo ¶
type AuthorizationInfo struct { AuthorizerAppId string `json:"authorizer_appid"` // 授权方 appid AuthorizerAccessToken string `json:"authorizer_access_token"` // 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值) ExpiresIn int `json:"expires_in"` // 有效期,单位:秒 AuthorizerRefreshToken string `json:"authorizer_refresh_token"` // 刷新令牌(在授权的公众号具备API权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。 FuncInfo []struct { FuncScopeCategory struct { Id uint32 `json:"id"` } `json:"funcscope_category"` ConfirmInfo struct { NeedConfirm uint32 `json:"need_confirm"` AlreadyConfirm uint32 `json:"already_confirm"` CanConfirm uint32 `json:"can_confirm"` } `json:"confirm_info"` } `json:"func_info"` }
AuthorizationInfo 参数 类型 说明 authorization_appid string 授权方 appid func_info object 授权给开发者的权限集列表
{ "authorizer_appid": "wx58a6179c79e038e7", "authorizer_refresh_token": "refreshtoken@@@XM0FapXdhUmRpVmm9o9_J1h8QeAwnAjUB5cpvGSR6tQ", "func_info": [ {"funcscope_category": {"id": 23}}, {"funcscope_category": {"id": 24},"confirm_info": {"need_confirm": 0,"already_confirm": 0,"can_confirm": 0}}, {"funcscope_category": {"id": 26}}, {"funcscope_category": {"id": 27 },"confirm_info": {"need_confirm": 0,"already_confirm": 0,"can_confirm": 0}} ] }
type CallbackMessage ¶
type CallbackMessage struct { InfoType string `xml:"InfoType"` // 消息类型 MsgType string `xml:"MsgType"` // 消息类型 Event string `xml:"Event"` // 事件类型 }
CallbackMessage 开放平台(只有InfoType)与公众号(MsgType/Event)回调信息结构
func (CallbackMessage) Key ¶
func (cm CallbackMessage) Key() string
type CallbackModel ¶
type CallbackModel struct { OpenId string `json:"openId"` AppId string `json:"appId"` Timestamp string `json:"timestamp"` //签名时间 Nonce string `json:"nonce"` //随机数 Data []byte `json:"data"` //post Data中的XML体 Extra map[string]string `json:"extra"` //附加的数据 }
func (*CallbackModel) String ¶
func (cm *CallbackModel) String() string
type Crypter ¶
type Crypter interface { Encrypt(text, id string) (string, error) Decrypt(text, id string) ([]byte, error) }
公众平台消息加解密接口
func NewAesCrypter ¶
type EncryptedMessage ¶
type ErrorModel ¶
func (ErrorModel) Success ¶
func (em ErrorModel) Success() bool
type TicketType ¶
type TicketType int
TicketType ticket类型枚举
const ( JSAPI TicketType // jsapi SDK // sdk WxCard // 微信卡券 )
func (TicketType) Code ¶
func (tt TicketType) Code() string
type WeChatThirdCrypter ¶
type WeChatThirdCrypter struct {
// contains filtered or unexported fields
}
func NewWeChatThirdCrypter ¶
func NewWeChatThirdCrypter(appId, token, encodingAesKey string) *WeChatThirdCrypter
func (*WeChatThirdCrypter) DecryptMessage ¶
func (w *WeChatThirdCrypter) DecryptMessage(encrypt, msgSignature, timestamp, nonce string) ([]byte, error)
func (*WeChatThirdCrypter) EncryptMessage ¶
func (w *WeChatThirdCrypter) EncryptMessage(msg, timestamp, nonce string) (string, error)
type WechatApi ¶
type WechatApi struct { *Api Cache cache.Provider Log *log.Slf4g // contains filtered or unexported fields }
func NewWechatApi ¶
func (*WechatApi) AccessToken ¶
AccessToken 获取小程序全局唯一后台接口调用凭据(access_token)。调用绝大多数后台接口时都需使用 access_token 请求地址 GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET 请求参数 属性 类型 必填 说明 grant_type string 是 填写 client_credential appid string 是 小程序唯一凭证,即 AppID,可在「微信公众平台 - 设置 - 开发设置」页中获得。(需要已经成为开发者,且帐号没有异常状态) secret string 是 小程序唯一凭证密钥,即 AppSecret,获取方式同 appid 返回类型 AccessTokenModel 根据接口返回的有效期进行redis缓存 注意: 缓存后不能在其他地方重新生成access_token, 否则缓存的token会失效