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