structure.go 11 KB

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