123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- package wechat
- import (
- "encoding/xml"
- )
- // Client wechat
- type Client struct {
- AppID string `json:"appid"`
- AppSecret string `json:"appsecret"`
- Token string `json:"token"`
- EncodingAESKey string `json:"encodingaeskey"`
- //ReadLock *sync.Mutex
- UseCacheToken bool
- AccessToken string
- LastTokenTime int64
- TokenFromCache bool
- Ticket string
- LastTicketTime int64
- }
- // ClientToken wechat client token
- type ClientToken struct {
- AppID string `json:"appid"`
- AccessToken string `json:"access_token"`
- LastTokenTime int64 `json:"last_token_time"`
- }
- // MiniClient wechat mini
- type MiniClient struct {
- AppID string `json:"appid"`
- AppSecret string `json:"appsecret"`
- AccessToken string
- LastTokenTime int64
- }
- // ResponseMsg response
- type ResponseMsg struct {
- ErrCode int `json:"errcode"`
- ErrMsg string `json:"errmsg"`
- }
- // MiniSession mini session
- type MiniSession struct {
- OpenID string `json:"openid"`
- SessionKey string `json:"session_key"`
- UnionID string `json:"unionid"`
- }
- // FormSignature signature
- type FormSignature struct {
- TimeStamp string `form:"timestamp" json:"timestamp"`
- Nonce string `form:"nonce" json:"nonce"`
- Signature string `form:"signature" json:"signature"`
- Echostr string `form:"echostr" json:"echostr"`
- }
- // FormAuthorize get code
- type FormAuthorize struct {
- Code string `form:"code"`
- State string `form:"state"`
- URL string `form:"url"`
- }
- // FormOpenID openid
- type FormOpenID struct {
- OpenID string `form:"openid"`
- }
- // FormCode code
- type FormCode struct {
- Code string `form:"code"`
- }
- // FormSignPackage js sign package
- type FormSignPackage struct {
- URL string `form:"url"`
- }
- // FormURLState redirect url and state
- type FormURLState struct {
- RedirectURL string `form:"url" json:"url" xml:"url"`
- State string `form:"state" json:"state" xml:"state"`
- }
- // Message message
- type Message struct {
- XMLName xml.Name `xml:"xml"`
- ToUserName string `xml:"ToUserName" json:"ToUserName"`
- FromUserName string `xml:"FromUserName" json:"FromUserName"`
- CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
- MsgType string `xml:"MsgType" json:"MsgType"` // text/image/voice/video/shortvideo/location/link
- // 文本 Text Text message
- Text string `xml:"Content,omitempty" json:"Content,omitempty"`
- // 图片 PicURL / MediaID image messgae
- PicURL string `xml:"PicUrl,omitempty" json:"PicUrl,omitempty"`
- // MediaID 媒体
- MediaID string `xml:"MediaId,omitempty" json:"MediaId,omitempty"`
- // 语音 MediaID / Format voice message
- Format string `xml:"Format,omitempty" json:"Format,omitempty"`
- // 视频/小视频 ThumbMediaID / MediaID video/shortvideo message
- ThumbMediaID string `xml:"ThumbMediaId,omitempty" json:"ThumbMediaId,omitempty"`
- // 地理位置 location message
- LocationX string `xml:"Location_X,omitempty" json:"Location_X,omitempty"` // 纬度
- LocationY string `xml:"Location_Y,omitempty" json:"Location_Y,omitempty"` // 经度
- Scale string `xml:"Scale,omitempty" json:"Scale,omitempty"` // 地图缩放大小
- Label string `xml:"Label,omitempty" json:"Label,omitempty"` // 地理位置信息
- // 链接消息 link
- Title string `xml:"Title,omitempty" json:"Title,omitempty"` // 消息标题
- Description string `xml:"Description,omitempty" json:"Description,omitempty"` // 消息描述
- URL string `xml:"Url,omitempty" json:"Url,omitempty"` // 消息链接
- Event string `xml:"Event,omitempty" json:"Event,omitempty"` // 事件 subscribe(订阅)、unsubscribe(取消订阅)、CLICK(自定义菜单事件)、SCAN
- // 扫描带参数二维码事件
- EventKey string `xml:"EventKey,omitempty" json:"EventKey,omitempty"` // 事件KEY 值,扫码未关注的 qrscene_ 为前缀(subscribe 事件, 已关注的推送 SCAN 事件),后面为二维码的参数值, 自定义菜单事件与自定义菜单接口中 KEY 值对应
- Ticket string `xml:"Ticket,omitempty" json:"Ticket,omitempty"` // 二维码的ticket,可用来换取二维码图片
- // 地理位置 location message
- Latitude string `xml:"Latitude,omitempty" json:"Latitude,omitempty"` // 纬度
- Longitude string `xml:"Longitude,omitempty" json:"Longitude,omitempty"` // 经度
- Precision string `xml:"Precision,omitempty" json:"Precision,omitempty"` // 地理位置精度
- MsgID int64 `xml:"MsgID,omitempty" json:"MsgID,omitempty"` // 消息id
- Status string `xml:"Status,omitempty" json:"Status,omitempty"` // 消息发送状态
- }
- type menuSubButtonList struct {
- Type string `json:"type"`
- Name string `json:"name"`
- Key string `json:"key"`
- URL string `json:"url"`
- }
- type menuSubButton struct {
- List []menuSubButtonList `json:"list"`
- }
- type menuButton struct {
- Type string `json:"type"`
- Name string `json:"name"`
- Key string `json:"key"`
- SubButton menuSubButton `json:"sub_button"`
- }
- type menuInfo struct {
- Button []menuButton `json:"button"`
- }
- // Menu menu
- type Menu struct {
- IsOpen int64 `json:"is_menu_open"`
- Info menuInfo `json:"selfmenu_info"`
- }
- // FormMenuButton menu button
- type FormMenuButton struct {
- Type string `json:"type,omitempty"`
- Name string `json:"name"`
- Key string `json:"key,omitempty"`
- URL string `json:"url,omitempty"`
- AppID string `json:"appid,omitempty"`
- Pagepath string `json:"pagepath,omitempty"`
- MediaID string `json:"media_id,omitempty"`
- SubButton []*FormMenuButton `json:"sub_button,omitempty"`
- }
- // FormMenu menu create
- type FormMenu struct {
- Button []*FormMenuButton `json:"button"`
- }
- // ArticleItem article item
- type ArticleItem struct {
- Title string `xml:"Title" json:"Title"`
- Description string `xml:"Description" json:"Description"`
- PicURL string `xml:"PicUrl" json:"PicUrl"`
- URL string `xml:"Url" json:"Url"`
- }
- type articleItems struct {
- Items []ArticleItem `xml:"item" json:"item"`
- }
- // ReplyMessage reply message
- type ReplyMessage struct {
- XMLName xml.Name `xml:"xml"`
- ToUserName string `xml:"ToUserName" json:"ToUserName"`
- FromUserName string `xml:"FromUserName" json:"FromUserName"`
- CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
- MsgType string `xml:"MsgType" json:"MsgType"` // text/image/voice/video/music/news
- // 文本 Content Text message
- Content string `xml:"Content,omitempty" json:"Content,omitempty"`
- // image
- ArticleCount int `xml:"ArticleCount,omitempty" json:"ArticleCount,omitempty"`
- Articles *articleItems `xml:"Articles,omitempty" json:"Articles,omitempty"`
- }
- // EventTemplateReply event reply
- type EventTemplateReply struct {
- XMLName xml.Name `xml:"xml"`
- ToUserName string `xml:"ToUserName"`
- FromUserName string `xml:"FromUserName"`
- CreateTime string `xml:"CreateTime"`
- MsgType string `xml:"MsgType"`
- Event string `xml:"Event"`
- MsgID string `xml:"MsgID"`
- Status string `xml:"Status"`
- }
- // SignPackage sign package
- type SignPackage struct {
- AppID string `json:"appId"`
- NonceStr string `json:"nonceStr"`
- Timestamp int64 `json:"timestamp"`
- Signature string `json:"signature"`
- Ticket string `json:"ticket"`
- URL string `json:"url"`
- }
- // FormMaterial Material
- type FormMaterial struct {
- Type string `form:"type"`
- Offset int `form:"offset"`
- Count int `form:"count"`
- }
- // UserInfo userinfo
- type UserInfo struct {
- SubScribe int `json:"subscribe"`
- OpenID string `json:"openid"`
- NickName string `json:"nickname"`
- Sex int `json:"sex"`
- Language string `json:"language"`
- City string `json:"city"`
- Province string `json:"province"`
- Country string `json:"country"`
- HeadImgURL string `json:"headimgurl"`
- SubscribeTime int `json:"subscribe_time"`
- UnionID string `json:"unionid"`
- Remark string `json:"remark"`
- GroupID int `json:"groupid"`
- TagidList []int `json:"tagid_list"`
- SubscribeScene string `json:"subscribe_scene"`
- QrScene int `json:"qr_scene"`
- QrSceneStr string `json:"qr_scene_str"`
- }
- // FormNextOpenID next openid
- type FormNextOpenID struct {
- Next string `form:"next_openid"`
- }
- // List openid list
- type List struct {
- OpenID []string `json:"openid"`
- }
- // UserList user list
- type UserList struct {
- Total int `json:"total"`
- Count int `json:"count"`
- Data List `json:"data"`
- NextOpenID string `json:"next_openid"`
- }
- // MaterialNewsItem 图片素材
- type MaterialNewsItem struct {
- Title string `json:"title"`
- Author string `json:"author"`
- Digest string `json:"digest"`
- Content string `json:"content"`
- ContentSourceURL string `json:"content_source_url"`
- ThumbMediaID string `json:"thumb_media_id"`
- ShowCoverPic int `json:"show_cover_pic"`
- URL string `json:"url"`
- ThumbURL string `json:"thumb_url"`
- NeedOpenComment int `json:"need_open_comment"`
- OnlyFansCanComment int `json:"only_fans_can_comment"`
- }
- // MaterialContent 素材内容
- type MaterialContent struct {
- NewsItem []*MaterialNewsItem `json:"news_item,omitempty"`
- CreateTime int `json:"create_time,omitempty"`
- UpdateTime int `json:"update_time,omitempty"`
- }
- // MaterialItem 素材信息
- type MaterialItem struct {
- MediaID string `json:"media_id"`
- Name string `json:"name,omitempty"`
- UpdateTime int `json:"update_time"`
- URL string `json:"url,omitempty"`
- Content *MaterialContent `json:"content,omitempty"`
- }
- // Material 素材
- type Material struct {
- TotalCount int `json:"total_count"`
- ItemCount int `json:"item_count"`
- Item []MaterialItem `json:"item"`
- }
- // MiniProgramPage mini
- type MiniProgramPage struct {
- AppID string `json:"appid,omitempty"`
- PagePath string `json:"pagepath,omitempty"`
- }
- // ValueColor value color
- type ValueColor struct {
- Value string `json:"value"`
- Color string `json:"color,omitempty"`
- }
- // TemplateResponse 模版消息返回
- type TemplateResponse struct {
- ResponseMsg
- MessageID int64 `json:"msgid"`
- }
- // TemplateData data
- type TemplateData struct {
- First *ValueColor `json:"first"`
- Keyword1 *ValueColor `json:"keyword1,omitempty"`
- Keyword2 *ValueColor `json:"keyword2,omitempty"`
- Keyword3 *ValueColor `json:"keyword3,omitempty"`
- Keyword4 *ValueColor `json:"keyword4,omitempty"`
- Keyword5 *ValueColor `json:"keyword5,omitempty"`
- Keyword6 *ValueColor `json:"keyword6,omitempty"`
- Keyword7 *ValueColor `json:"keyword7,omitempty"`
- Keyword8 *ValueColor `json:"keyword8,omitempty"`
- Keyword9 *ValueColor `json:"keyword9,omitempty"`
- Keyword10 *ValueColor `json:"keyword10,omitempty"`
- Name *ValueColor `json:"name,omitempty"`
- ExpDate *ValueColor `json:"expDate,omitempty"`
- Remark *ValueColor `json:"remark,omitempty"`
- }
- // TemplateMessage template message
- type TemplateMessage struct {
- ToUser string `json:"touser"`
- TemplateID string `json:"template_id"`
- URL string `json:"url"`
- MiniProgram *MiniProgramPage `json:"miniprogram,omitempty"`
- Data TemplateData `json:"data"`
- }
- // MiniTemplateMessage mini template message
- type MiniTemplateMessage struct {
- ToUser string `json:"touser"`
- TemplateID string `json:"template_id"`
- Page string `json:"page"`
- FormID string `json:"form_id"`
- Data TemplateData `json:"data"`
- }
- // WeappTemplateMessage mini message
- type WeappTemplateMessage struct {
- TemplateID string `json:"template_id"`
- Page string `json:"page"`
- FormID string `json:"form_id"`
- Data TemplateData `json:"data"`
- Emphasis string `json:"emphasis_keyword"`
- }
- // MpTemplateMessage wechat public message
- type MpTemplateMessage struct {
- AppID string `json:"appid"`
- TemplateID string `json:"template_id"`
- URL string `json:"url"`
- Mini MiniProgramPage `json:"miniprogram"`
- Data TemplateData `json:"data"`
- }
- // MiniUniformMessage mini uniform send
- type MiniUniformMessage struct {
- ToUser string `json:"touser"`
- WeApp *WeappTemplateMessage `json:"weapp_template_msg,omitempty"`
- MP *MpTemplateMessage `json:"mp_template_msg,omitempty"`
- }
- // FormPayNotify notify
- type FormPayNotify struct {
- XMLName xml.Name `xml:"xml" json:"_,omitempty"`
- AppID string `form:"appid" xml:"appid"`
- Attach string `form:"attach" xml:"attach"`
- BankType string `form:"bank_type" xml:"bank_type"`
- CashFee int `form:"cash_fee" xml:"cash_fee"`
- FeeType string `form:"fee_type" xml:"fee_type"`
- MchID string `form:"mch_id" xml:"mch_id"`
- IsSubscribe string `form:"is_subscribe" xml:"is_subscribe"`
- NonceStr string `form:"nonce_str" xml:"nonce_str"`
- OpenID string `form:"openid" xml:"openid"`
- OutTradeNo string `form:"out_trade_no" xml:"out_trade_no"`
- ResultCode string `form:"result_code" xml:"result_code"`
- ReturnMsg string `form:"return_msg" xml:"return_msg"`
- ReturnCode string `form:"return_code" xml:"return_code"`
- ErrCodeDes string `form:"err_code_des" xml:"err_code_des"`
- ErrCode string `form:"err_code" xml:"err_code"`
- Sign string `form:"sign" xml:"sign"`
- TimeEnd string `form:"time_end" xml:"time_end"`
- TotalFee int `form:"total_fee" xml:"total_fee"`
- TradeType string `form:"trade_type" xml:"trade_type"`
- TransactionID string `form:"transaction_id" xml:"transaction_id"`
- ContractID string `form:"contract_id" xml:"contract_id"`
- }
|