structure.go 13 KB

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