structure.go 13 KB

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