structure.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. package wechat
  2. import (
  3. "encoding/xml"
  4. )
  5. // Client wechat
  6. type Client struct {
  7. UseCacheToken bool
  8. AppID string `json:"appid"`
  9. AppSecret string `json:"appsecret"`
  10. Token string `json:"token"`
  11. EncodingAESKey string `json:"encodingaeskey"`
  12. AccessToken string
  13. Ticket string
  14. //TokenFromCache bool
  15. LastTokenTime int64
  16. LastTicketTime int64
  17. }
  18. // ClientToken wechat client token
  19. type ClientToken struct {
  20. AppID string `json:"appid"`
  21. AccessToken string `json:"access_token"`
  22. LastTokenTime int64 `json:"last_token_time"`
  23. }
  24. // ClientTicket wechat client ticket
  25. type ClientTicket struct {
  26. AppID string `json:"appid"`
  27. Ticket string `json:"ticket"`
  28. LastTicketTime int64 `json:"last_ticket_time"`
  29. }
  30. // MiniClient wechat mini
  31. type MiniClient struct {
  32. AppID string `json:"appid"`
  33. AppSecret string `json:"appsecret"`
  34. AccessToken string
  35. LastTokenTime int64
  36. }
  37. // ResponseMsg response
  38. type ResponseMsg struct {
  39. ErrCode int `json:"errcode,omitempty"`
  40. ErrMsg string `json:"errmsg,omitempty"`
  41. }
  42. // ResponseToken token
  43. type ResponseToken struct {
  44. ResponseMsg
  45. AccessToken string `json:"access_token"`
  46. ExpiresIn int `json:"expires_in"`
  47. }
  48. // ResponseTicket ticket
  49. type ResponseTicket struct {
  50. ResponseMsg
  51. Ticket string `json:"ticket"`
  52. ExpiresIn int `json:"expires_in"`
  53. }
  54. // FormSignature signature
  55. type FormSignature struct {
  56. TimeStamp string `form:"timestamp" json:"timestamp"`
  57. Nonce string `form:"nonce" json:"nonce"`
  58. Signature string `form:"signature" json:"signature"`
  59. Echostr string `form:"echostr" json:"echostr"`
  60. }
  61. // FormAuthorize get code
  62. type FormAuthorize struct {
  63. Code string `form:"code"`
  64. State string `form:"state"`
  65. URL string `form:"url"`
  66. }
  67. // FormOpenID openid
  68. type FormOpenID struct {
  69. OpenID string `form:"openid"`
  70. }
  71. // FormCode code
  72. type FormCode struct {
  73. Code string `form:"code"`
  74. }
  75. // FormSignPackage js sign package
  76. type FormSignPackage struct {
  77. URL string `form:"url"`
  78. }
  79. // FormURLState redirect url and state
  80. type FormURLState struct {
  81. RedirectURL string `form:"url" json:"url" xml:"url"`
  82. State string `form:"state" json:"state" xml:"state"`
  83. }
  84. // Message message
  85. type Message struct {
  86. XMLName xml.Name `xml:"xml"`
  87. ToUserName string `xml:"ToUserName" json:"ToUserName"`
  88. FromUserName string `xml:"FromUserName" json:"FromUserName"`
  89. CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
  90. MsgType string `xml:"MsgType" json:"MsgType"` // text/image/voice/video/shortvideo/location/link
  91. // 文本 Text Text message
  92. Text string `xml:"Content,omitempty" json:"Content,omitempty"`
  93. // 图片 PicURL / MediaID image messgae
  94. PicURL string `xml:"PicUrl,omitempty" json:"PicUrl,omitempty"`
  95. // MediaID 媒体
  96. MediaID string `xml:"MediaId,omitempty" json:"MediaId,omitempty"`
  97. // 语音 MediaID / Format voice message
  98. Format string `xml:"Format,omitempty" json:"Format,omitempty"`
  99. // 视频/小视频 ThumbMediaID / MediaID video/shortvideo message
  100. ThumbMediaID string `xml:"ThumbMediaId,omitempty" json:"ThumbMediaId,omitempty"`
  101. // 地理位置 location message
  102. LocationX string `xml:"Location_X,omitempty" json:"Location_X,omitempty"` // 纬度
  103. LocationY string `xml:"Location_Y,omitempty" json:"Location_Y,omitempty"` // 经度
  104. Scale string `xml:"Scale,omitempty" json:"Scale,omitempty"` // 地图缩放大小
  105. Label string `xml:"Label,omitempty" json:"Label,omitempty"` // 地理位置信息
  106. // 链接消息 link
  107. Title string `xml:"Title,omitempty" json:"Title,omitempty"` // 消息标题
  108. Description string `xml:"Description,omitempty" json:"Description,omitempty"` // 消息描述
  109. URL string `xml:"Url,omitempty" json:"Url,omitempty"` // 消息链接
  110. Event string `xml:"Event,omitempty" json:"Event,omitempty"` // 事件 subscribe(订阅)、unsubscribe(取消订阅)、CLICK(自定义菜单事件)、SCAN
  111. // 扫描带参数二维码事件
  112. EventKey string `xml:"EventKey,omitempty" json:"EventKey,omitempty"` // 事件KEY 值,扫码未关注的 qrscene_ 为前缀(subscribe 事件, 已关注的推送 SCAN 事件),后面为二维码的参数值, 自定义菜单事件与自定义菜单接口中 KEY 值对应
  113. Ticket string `xml:"Ticket,omitempty" json:"Ticket,omitempty"` // 二维码的ticket,可用来换取二维码图片
  114. // 地理位置 location message
  115. Latitude string `xml:"Latitude,omitempty" json:"Latitude,omitempty"` // 纬度
  116. Longitude string `xml:"Longitude,omitempty" json:"Longitude,omitempty"` // 经度
  117. Precision string `xml:"Precision,omitempty" json:"Precision,omitempty"` // 地理位置精度
  118. MsgID int64 `xml:"MsgID,omitempty" json:"MsgID,omitempty"` // 消息id
  119. Status string `xml:"Status,omitempty" json:"Status,omitempty"` // 消息发送状态
  120. }
  121. type menuSubButtonList struct {
  122. Type string `json:"type"`
  123. Name string `json:"name"`
  124. Key string `json:"key"`
  125. URL string `json:"url"`
  126. }
  127. type menuSubButton struct {
  128. List []menuSubButtonList `json:"list"`
  129. }
  130. type menuButton struct {
  131. Type string `json:"type"`
  132. Name string `json:"name"`
  133. Key string `json:"key"`
  134. SubButton menuSubButton `json:"sub_button"`
  135. }
  136. type menuInfo struct {
  137. Button []menuButton `json:"button"`
  138. }
  139. // Menu menu
  140. type Menu struct {
  141. ResponseMsg
  142. IsOpen int64 `json:"is_menu_open"`
  143. Info menuInfo `json:"selfmenu_info"`
  144. }
  145. // FormMenuButton menu button
  146. type FormMenuButton struct {
  147. Type string `json:"type,omitempty"`
  148. Name string `json:"name"`
  149. Key string `json:"key,omitempty"`
  150. URL string `json:"url,omitempty"`
  151. AppID string `json:"appid,omitempty"`
  152. Pagepath string `json:"pagepath,omitempty"`
  153. MediaID string `json:"media_id,omitempty"`
  154. SubButton []*FormMenuButton `json:"sub_button,omitempty"`
  155. }
  156. // FormMenu menu create
  157. type FormMenu struct {
  158. Button []*FormMenuButton `json:"button"`
  159. }
  160. // ArticleItem article item
  161. type ArticleItem struct {
  162. Title string `xml:"Title" json:"Title"`
  163. Description string `xml:"Description" json:"Description"`
  164. PicURL string `xml:"PicUrl" json:"PicUrl"`
  165. URL string `xml:"Url" json:"Url"`
  166. }
  167. type articleItems struct {
  168. Items []ArticleItem `xml:"item" json:"item"`
  169. }
  170. // ReplyMessage reply message
  171. type ReplyMessage struct {
  172. XMLName xml.Name `xml:"xml"`
  173. ToUserName string `xml:"ToUserName" json:"ToUserName"`
  174. FromUserName string `xml:"FromUserName" json:"FromUserName"`
  175. CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
  176. MsgType string `xml:"MsgType" json:"MsgType"` // text/image/voice/video/music/news
  177. // 文本 Content Text message
  178. Content string `xml:"Content,omitempty" json:"Content,omitempty"`
  179. // image
  180. ArticleCount int `xml:"ArticleCount,omitempty" json:"ArticleCount,omitempty"`
  181. Articles *articleItems `xml:"Articles,omitempty" json:"Articles,omitempty"`
  182. }
  183. // EventTemplateReply event reply
  184. type EventTemplateReply struct {
  185. XMLName xml.Name `xml:"xml"`
  186. ToUserName string `xml:"ToUserName"`
  187. FromUserName string `xml:"FromUserName"`
  188. CreateTime string `xml:"CreateTime"`
  189. MsgType string `xml:"MsgType"`
  190. Event string `xml:"Event"`
  191. MsgID string `xml:"MsgID"`
  192. Status string `xml:"Status"`
  193. }
  194. // SignPackage sign package
  195. type SignPackage struct {
  196. AppID string `json:"appId"`
  197. NonceStr string `json:"nonceStr"`
  198. Timestamp int64 `json:"timestamp"`
  199. Signature string `json:"signature"`
  200. Ticket string `json:"ticket"`
  201. URL string `json:"url"`
  202. }
  203. // FormMaterial Material
  204. type FormMaterial struct {
  205. Type string `form:"type"`
  206. Offset int `form:"offset"`
  207. Count int `form:"count"`
  208. }
  209. // UserInfo userinfo
  210. type UserInfo struct {
  211. ResponseMsg
  212. SubScribe int `json:"subscribe"`
  213. OpenID string `json:"openid"`
  214. NickName string `json:"nickname"`
  215. Sex int `json:"sex"`
  216. Language string `json:"language"`
  217. City string `json:"city"`
  218. Province string `json:"province"`
  219. Country string `json:"country"`
  220. HeadImgURL string `json:"headimgurl"`
  221. SubscribeTime int `json:"subscribe_time"`
  222. UnionID string `json:"unionid"`
  223. Remark string `json:"remark"`
  224. GroupID int `json:"groupid"`
  225. TagidList []int `json:"tagid_list"`
  226. SubscribeScene string `json:"subscribe_scene"`
  227. QrScene int `json:"qr_scene"`
  228. QrSceneStr string `json:"qr_scene_str"`
  229. }
  230. // FormNextOpenID next openid
  231. type FormNextOpenID struct {
  232. Next string `form:"next_openid"`
  233. }
  234. // List openid list
  235. type List struct {
  236. OpenID []string `json:"openid"`
  237. }
  238. // UserList user list
  239. type UserList struct {
  240. ResponseMsg
  241. Total int `json:"total"`
  242. Count int `json:"count"`
  243. Data List `json:"data"`
  244. NextOpenID string `json:"next_openid"`
  245. }
  246. // MaterialNewsItem 图片素材
  247. type MaterialNewsItem struct {
  248. Title string `json:"title"`
  249. Author string `json:"author"`
  250. Digest string `json:"digest"`
  251. Content string `json:"content"`
  252. ContentSourceURL string `json:"content_source_url"`
  253. ThumbMediaID string `json:"thumb_media_id"`
  254. ShowCoverPic int `json:"show_cover_pic"`
  255. URL string `json:"url"`
  256. ThumbURL string `json:"thumb_url"`
  257. NeedOpenComment int `json:"need_open_comment"`
  258. OnlyFansCanComment int `json:"only_fans_can_comment"`
  259. }
  260. // MaterialContent 素材内容
  261. type MaterialContent struct {
  262. NewsItem []*MaterialNewsItem `json:"news_item,omitempty"`
  263. CreateTime int `json:"create_time,omitempty"`
  264. UpdateTime int `json:"update_time,omitempty"`
  265. }
  266. // MaterialItem 素材信息
  267. type MaterialItem struct {
  268. MediaID string `json:"media_id"`
  269. Name string `json:"name,omitempty"`
  270. UpdateTime int `json:"update_time"`
  271. URL string `json:"url,omitempty"`
  272. Content *MaterialContent `json:"content,omitempty"`
  273. }
  274. // Material 素材
  275. type Material struct {
  276. ResponseMsg
  277. TotalCount int `json:"total_count"`
  278. ItemCount int `json:"item_count"`
  279. Item []MaterialItem `json:"item"`
  280. }
  281. // MiniProgramPage mini
  282. type MiniProgramPage struct {
  283. AppID string `json:"appid,omitempty"`
  284. PagePath string `json:"pagepath,omitempty"`
  285. }
  286. // ValueColor value color
  287. type ValueColor struct {
  288. Value string `json:"value"`
  289. Color string `json:"color,omitempty"`
  290. }
  291. // TemplateResponse 模版消息返回
  292. type TemplateResponse struct {
  293. ResponseMsg
  294. MessageID int64 `json:"msgid"`
  295. }
  296. // TemplateData data
  297. type TemplateData struct {
  298. First *ValueColor `json:"first"`
  299. Keyword1 *ValueColor `json:"keyword1,omitempty"`
  300. Keyword2 *ValueColor `json:"keyword2,omitempty"`
  301. Keyword3 *ValueColor `json:"keyword3,omitempty"`
  302. Keyword4 *ValueColor `json:"keyword4,omitempty"`
  303. Keyword5 *ValueColor `json:"keyword5,omitempty"`
  304. Keyword6 *ValueColor `json:"keyword6,omitempty"`
  305. Keyword7 *ValueColor `json:"keyword7,omitempty"`
  306. Keyword8 *ValueColor `json:"keyword8,omitempty"`
  307. Keyword9 *ValueColor `json:"keyword9,omitempty"`
  308. Keyword10 *ValueColor `json:"keyword10,omitempty"`
  309. Name *ValueColor `json:"name,omitempty"`
  310. ExpDate *ValueColor `json:"expDate,omitempty"`
  311. Remark *ValueColor `json:"remark,omitempty"`
  312. }
  313. // TemplateMessage template message
  314. type TemplateMessage struct {
  315. ToUser string `json:"touser"`
  316. TemplateID string `json:"template_id"`
  317. URL string `json:"url"`
  318. MiniProgram *MiniProgramPage `json:"miniprogram,omitempty"`
  319. Data TemplateData `json:"data"`
  320. }
  321. // MiniTemplateMessage mini template message
  322. type MiniTemplateMessage struct {
  323. ToUser string `json:"touser"`
  324. TemplateID string `json:"template_id"`
  325. Page string `json:"page"`
  326. FormID string `json:"form_id"`
  327. Data TemplateData `json:"data"`
  328. }
  329. // WeappTemplateMessage mini message
  330. type WeappTemplateMessage struct {
  331. TemplateID string `json:"template_id"`
  332. Page string `json:"page"`
  333. FormID string `json:"form_id"`
  334. Data TemplateData `json:"data"`
  335. Emphasis string `json:"emphasis_keyword"`
  336. }
  337. // MpTemplateMessage wechat public message
  338. type MpTemplateMessage struct {
  339. AppID string `json:"appid"`
  340. TemplateID string `json:"template_id"`
  341. URL string `json:"url"`
  342. Mini MiniProgramPage `json:"miniprogram"`
  343. Data TemplateData `json:"data"`
  344. }
  345. // MiniUniformMessage mini uniform send
  346. type MiniUniformMessage struct {
  347. ToUser string `json:"touser"`
  348. WeApp *WeappTemplateMessage `json:"weapp_template_msg,omitempty"`
  349. MP *MpTemplateMessage `json:"mp_template_msg,omitempty"`
  350. }
  351. // FormPayNotify notify
  352. type FormPayNotify struct {
  353. XMLName xml.Name `xml:"xml" json:"_,omitempty"`
  354. AppID string `form:"appid" xml:"appid"`
  355. Attach string `form:"attach" xml:"attach"`
  356. BankType string `form:"bank_type" xml:"bank_type"`
  357. CashFee int `form:"cash_fee" xml:"cash_fee"`
  358. FeeType string `form:"fee_type" xml:"fee_type"`
  359. MchID string `form:"mch_id" xml:"mch_id"`
  360. IsSubscribe string `form:"is_subscribe" xml:"is_subscribe"`
  361. NonceStr string `form:"nonce_str" xml:"nonce_str"`
  362. OpenID string `form:"openid" xml:"openid"`
  363. OutTradeNo string `form:"out_trade_no" xml:"out_trade_no"`
  364. ResultCode string `form:"result_code" xml:"result_code"`
  365. ReturnMsg string `form:"return_msg" xml:"return_msg"`
  366. ReturnCode string `form:"return_code" xml:"return_code"`
  367. ErrCodeDes string `form:"err_code_des" xml:"err_code_des"`
  368. ErrCode string `form:"err_code" xml:"err_code"`
  369. Sign string `form:"sign" xml:"sign"`
  370. TimeEnd string `form:"time_end" xml:"time_end"`
  371. TotalFee int `form:"total_fee" xml:"total_fee"`
  372. TradeType string `form:"trade_type" xml:"trade_type"`
  373. TransactionID string `form:"transaction_id" xml:"transaction_id"`
  374. ContractID string `form:"contract_id" xml:"contract_id"`
  375. }