structure.go 13 KB

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