structure.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 formMenuButton 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. MediaID string `json:"media_id,omitempty"`
  156. SubButton []*formMenuButton `json:"sub_button,omitempty"`
  157. }
  158. // FormMenu menu create
  159. type FormMenu struct {
  160. Button []*formMenuButton `json:"button"`
  161. }
  162. // ArticleItem article item
  163. type ArticleItem struct {
  164. Title string `xml:"Title" json:"Title"`
  165. Description string `xml:"Description" json:"Description"`
  166. PicURL string `xml:"PicUrl" json:"PicUrl"`
  167. URL string `xml:"Url" json:"Url"`
  168. }
  169. type articleItems struct {
  170. Items []ArticleItem `xml:"item" json:"item"`
  171. }
  172. // ReplyMessage reply message
  173. type ReplyMessage struct {
  174. XMLName xml.Name `xml:"xml"`
  175. ToUserName string `xml:"ToUserName" json:"ToUserName"`
  176. FromUserName string `xml:"FromUserName" json:"FromUserName"`
  177. CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
  178. MsgType string `xml:"MsgType" json:"MsgType"` // text/image/voice/video/music/news
  179. // 文本 Content Text message
  180. Content string `xml:"Content,omitempty" json:"Content,omitempty"`
  181. // image
  182. ArticleCount int `xml:"ArticleCount,omitempty" json:"ArticleCount,omitempty"`
  183. Articles *articleItems `xml:"Articles,omitempty" json:"Articles,omitempty"`
  184. }
  185. /*
  186. <xml>
  187. <ToUserName><![CDATA[toUser]]></ToUserName>
  188. <FromUserName><![CDATA[fromUser]]></FromUserName>
  189. <CreateTime>12345678</CreateTime>
  190. <MsgType><![CDATA[news]]></MsgType>
  191. <ArticleCount>1</ArticleCount>
  192. <Articles>
  193. <item>
  194. <Title><![CDATA[title1]]></Title>
  195. <Description><![CDATA[description1]]></Description>
  196. <PicUrl><![CDATA[picurl]]></PicUrl>
  197. <Url><![CDATA[url]]></Url>
  198. </item>
  199. </Articles>
  200. </xml>
  201. // */
  202. // EventTemplateReply event reply
  203. type EventTemplateReply struct {
  204. XMLName xml.Name `xml:"xml"`
  205. ToUserName string `xml:"ToUserName"`
  206. FromUserName string `xml:"FromUserName"`
  207. CreateTime string `xml:"CreateTime"`
  208. MsgType string `xml:"MsgType"`
  209. Event string `xml:"Event"`
  210. MsgID string `xml:"MsgID"`
  211. Status string `xml:"Status"`
  212. }
  213. // SignPackage sign package
  214. type SignPackage struct {
  215. AppID string `json:"appId"`
  216. NonceStr string `json:"nonceStr"`
  217. Timestamp int64 `json:"timestamp"`
  218. Signature string `json:"signature"`
  219. Ticket string `json:"ticket"`
  220. URL string `json:"url"`
  221. }
  222. // FormMaterial Material
  223. type FormMaterial struct {
  224. Type string `form:"type"`
  225. Offset int `form:"offset"`
  226. Count int `form:"count"`
  227. }
  228. // UserInfo userinfo
  229. type UserInfo struct {
  230. SubScribe int `json:"subscribe"`
  231. OpenID string `json:"openid"`
  232. NickName string `json:"nickname"`
  233. Sex int `json:"sex"`
  234. Language string `json:"language"`
  235. City string `json:"city"`
  236. Province string `json:"province"`
  237. Country string `json:"country"`
  238. HeadImgURL string `json:"headimgurl"`
  239. SubscribeTime int `json:"subscribe_time"`
  240. UnionID string `json:"unionid"`
  241. Remark string `json:"remark"`
  242. GroupID int `json:"groupid"`
  243. TagidList []int `json:"tagid_list"`
  244. SubscribeScene string `json:"subscribe_scene"`
  245. QrScene int `json:"qr_scene"`
  246. QrSceneStr string `json:"qr_scene_str"`
  247. }
  248. // FormNextOpenID next openid
  249. type FormNextOpenID struct {
  250. Next string `form:"next_openid"`
  251. }
  252. // List openid list
  253. type List struct {
  254. OpenID []string `json:"openid"`
  255. }
  256. // UserList user list
  257. type UserList struct {
  258. Total int `json:"total"`
  259. Count int `json:"count"`
  260. Data List `json:"data"`
  261. NextOpenID string `json:"next_openid"`
  262. }
  263. // MaterialNewsItem 图片素材
  264. type MaterialNewsItem struct {
  265. Title string `json:"title"`
  266. Author string `json:"author"`
  267. Digest string `json:"digest"`
  268. Content string `json:"content"`
  269. ContentSourceURL string `json:"content_source_url"`
  270. ThumbMediaID string `json:"thumb_media_id"`
  271. ShowCoverPic int `json:"show_cover_pic"`
  272. URL string `json:"url"`
  273. ThumbURL string `json:"thumb_url"`
  274. NeedOpenComment int `json:"need_open_comment"`
  275. OnlyFansCanComment int `json:"only_fans_can_comment"`
  276. }
  277. // MaterialContent 素材内容
  278. type MaterialContent struct {
  279. NewsItem []*MaterialNewsItem `json:"news_item,omitempty"`
  280. CreateTime int `json:"create_time,omitempty"`
  281. UpdateTime int `json:"update_time,omitempty"`
  282. }
  283. // MaterialItem 素材信息
  284. type MaterialItem struct {
  285. MediaID string `json:"media_id"`
  286. Name string `json:"name,omitempty"`
  287. UpdateTime int `json:"update_time"`
  288. URL string `json:"url,omitempty"`
  289. Content *MaterialContent `json:"content,omitempty"`
  290. }
  291. // Material 素材
  292. type Material struct {
  293. TotalCount int `json:"total_count"`
  294. ItemCount int `json:"item_count"`
  295. Item []MaterialItem `json:"item"`
  296. }
  297. // MiniProgramPage mini
  298. type MiniProgramPage struct {
  299. AppID string `json:"appid,omitempty"`
  300. PagePath string `json:"pagepath,omitempty"`
  301. }
  302. // ValueColor value color
  303. type ValueColor struct {
  304. Value string `json:"value"`
  305. Color string `json:"color,omitempty"`
  306. }
  307. // TemplateData data
  308. type TemplateData struct {
  309. First *ValueColor `json:"first"`
  310. Keyword1 *ValueColor `json:"keyword1,omitempty"`
  311. Keyword2 *ValueColor `json:"keyword2,omitempty"`
  312. Keyword3 *ValueColor `json:"keyword3,omitempty"`
  313. Keyword4 *ValueColor `json:"keyword4,omitempty"`
  314. Keyword5 *ValueColor `json:"keyword5,omitempty"`
  315. Keyword6 *ValueColor `json:"keyword6,omitempty"`
  316. Keyword7 *ValueColor `json:"keyword7,omitempty"`
  317. Keyword8 *ValueColor `json:"keyword8,omitempty"`
  318. Keyword9 *ValueColor `json:"keyword9,omitempty"`
  319. Keyword10 *ValueColor `json:"keyword10,omitempty"`
  320. Name *ValueColor `json:"name,omitempty"`
  321. ExpDate *ValueColor `json:"expDate,omitempty"`
  322. Remark *ValueColor `json:"remark,omitempty"`
  323. }
  324. // TemplateMessage template message
  325. type TemplateMessage struct {
  326. ToUser string `json:"touser"`
  327. TemplateID string `json:"template_id"`
  328. URL string `json:"url"`
  329. MiniProgram *MiniProgramPage `json:"miniprogram,omitempty"`
  330. Data TemplateData `json:"data"`
  331. }
  332. // MiniTemplateMessage mini template message
  333. type MiniTemplateMessage struct {
  334. ToUser string `json:"touser"`
  335. TemplateID string `json:"template_id"`
  336. Page string `json:"page"`
  337. FormID string `json:"form_id"`
  338. Data TemplateData `json:"data"`
  339. }
  340. // WeappTemplateMessage mini message
  341. type WeappTemplateMessage struct {
  342. TemplateID string `json:"template_id"`
  343. Page string `json:"page"`
  344. FormID string `json:"form_id"`
  345. Data TemplateData `json:"data"`
  346. Emphasis string `json:"emphasis_keyword"`
  347. }
  348. // MpTemplateMessage wechat public message
  349. type MpTemplateMessage struct {
  350. AppID string `json:"appid"`
  351. TemplateID string `json:"template_id"`
  352. URL string `json:"url"`
  353. Mini MiniProgramPage `json:"miniprogram"`
  354. Data TemplateData `json:"data"`
  355. }
  356. // MiniUniformMessage mini uniform send
  357. type MiniUniformMessage struct {
  358. ToUser string `json:"touser"`
  359. WeApp *WeappTemplateMessage `json:"weapp_template_msg,omitempty"`
  360. MP *MpTemplateMessage `json:"mp_template_msg,omitempty"`
  361. }