open_wechat_model.go 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package wechat_service
  2. import (
  3. "encoding/xml"
  4. "time"
  5. "github.com/silenceper/wechat/menu"
  6. )
  7. //MsgEncrypt 微信平台向第三方平台授权事件接收URL推送的xml数据结构
  8. type MsgEncrypt struct {
  9. AppID string `xml:"AppId"`
  10. Encrypt string `xml:"Encrypt"`
  11. }
  12. //ComponentRequestBody 第三方平台授权事件接收URL接收数据后解密后的基本结构,
  13. //有各种不同的结构:Ticket,AuthorizedStruct,UnauthorizedStruct,UpdateauthorizedStruct,由InfoType.InfoType判断
  14. type ComponentRequestBody struct {
  15. AppID string `xml:"AppId"`
  16. CreateTime string `xml:"CreateTime"`
  17. InfoType string `xml:"InfoType"`
  18. // 接收微信平台向第三方平台授权事件接收URL推送,InfoType为component_verify_ticket时,返回
  19. ComponentVerifyTicket string `xml:"ComponentVerifyTicket,omitempty"`
  20. // 微信平台向第三方平台授权事件接收URL推送的数据,InfoType为authorized,unauthorized,updateauthorized时间有返回
  21. AuthorizerAppid string `xml:"AuthorizerAppid,omitempty"`
  22. // 微信平台向第三方平台授权事件接收URL推送的数据,InfoType为authorized,updateauthorized时间有返回
  23. AuthorizationCode string `xml:"AuthorizationCode,omitempty"`
  24. AuthorizationCodeExpiredTime string `xml:"AuthorizationCodeExpiredTime,omitempty"`
  25. PreAuthCode string `xml:"PreAuthCode,omitempty"`
  26. }
  27. type EncryptRequestBody struct {
  28. XMLName xml.Name `xml:"xml"`
  29. ToUserName string
  30. Encrypt string
  31. }
  32. type TextRequestBody struct {
  33. XMLName xml.Name `xml:"xml"`
  34. ToUserName string
  35. FromUserName string
  36. CreateTime time.Duration
  37. MsgType string
  38. Event string
  39. EventKey string
  40. Url string
  41. PicUrl string
  42. MediaId string
  43. ThumbMediaId string
  44. Content string
  45. MsgId int
  46. Location_X string
  47. Location_Y string
  48. Label string
  49. }
  50. type CDATAText struct {
  51. Text string `xml:",innerxml"`
  52. }
  53. type EncryptResponseBody struct {
  54. XMLName xml.Name `xml:"xml"`
  55. Encrypt CDATAText
  56. MsgSignature CDATAText
  57. TimeStamp string
  58. Nonce CDATAText
  59. }
  60. type TextResponseBody struct {
  61. XMLName xml.Name `xml:"xml"`
  62. ToUserName CDATAText
  63. FromUserName CDATAText
  64. CreateTime string
  65. MsgType CDATAText
  66. Content CDATAText
  67. }
  68. type MPResult struct {
  69. ErrCode int64 `json:"errcode"`
  70. ErrMsg string `json:"errmsg"`
  71. }
  72. //ResAddMaterial 永久性素材上传返回的结果
  73. type ResAddMaterial struct {
  74. MPResult
  75. MediaID string `json:"media_id"`
  76. URL string `json:"url"`
  77. }
  78. //ComponentAccessToken 第三方平台主动向微信服务器请求第三方平台自己的component_access_token返回的数据结构
  79. type ComponentAccessToken struct {
  80. ComponentAccessToken string `json:"component_access_token"`
  81. ExpiresIn int `json:"expires_in"`
  82. }
  83. //PreAuthCode 第三方平台主动向微信服务器请求第三方平台预授权码pre_auth_code返回的数据结构
  84. type PreAuthCode struct {
  85. PreAuthCode string `json:"pre_auth_code"`
  86. ExpiresIn int `json:"expires_in"`
  87. }
  88. //AuthorizationInfo 公众号向第三方平台授权成功后,在redirect_uri利用auth_code(公众号确定授权后,微信拼接在redirect_uri上,用来交换AuthorizationInfo)主动请求授权信息
  89. type AuthorizationInfo struct {
  90. AuthorizationInfo struct {
  91. AuthorizerAppid string `json:"authorizer_appid"`
  92. AuthorizerAccessToken string `json:"authorizer_access_token"`
  93. ExpiresIn int64 `json:"expires_in"`
  94. AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
  95. FuncInfo []FuncInfoItems `json:"func_info"`
  96. } `json:"authorization_info"`
  97. }
  98. type FuncInfoItems struct {
  99. FuncscopeCategory struct {
  100. ID int64 `json:"id"`
  101. } `json:"funcscope_category"`
  102. }
  103. //AuthorizerInfo 第三方平利用authorizer_appid(公众号的appid,授权确定后获得,AuthorizationInfo.authorizer_appid)和component_appid(第三方平台appid,在微信开发平台新建一个第三方应用时生成)
  104. type AuthorizerInfo struct {
  105. AuthorizerInfo struct {
  106. NickName string `json:"nick_name"`
  107. HeadImg string `json:"head_img"`
  108. ServiceTypeInfo AuthorizerInfoTypeInfo `json:"service_type_info"`
  109. VerifyTypeInfo AuthorizerInfoTypeInfo `json:"verify_type_info"`
  110. UserName string `json:"user_name"`
  111. QrcodeURL string `json:"qrcode_url"`
  112. PrincipalName string `json:"principal_name"`
  113. BusinessInfo BusinessInfo `json:"business_info"`
  114. FuncInfo []FuncInfoItems `json:"func_info"`
  115. } `json:"authorizer_info"`
  116. }
  117. type AuthorizerInfoTypeInfo struct {
  118. ID int64 `json:"id"`
  119. }
  120. type BusinessInfo struct {
  121. OpenPay int64 `json:"open_pay"`
  122. OpenShake int64 `json:"open_shake"`
  123. OpenScan int64 `json:"open_scan"`
  124. OpenCard int64 `json:"open_card"`
  125. OpenStore int64 `json:"open_store"`
  126. }
  127. //微信菜单形式
  128. type SelfMenuInfo struct {
  129. Button []SelfMenuButton `json:"button"`
  130. }
  131. //reqMenu 设置菜单请求数据
  132. type RRreqMenu struct {
  133. Button []*menu.Button `json:"button,omitempty"`
  134. MatchRule *menu.MatchRule `json:"matchrule,omitempty"`
  135. }
  136. //SelfMenuButton 自定义菜单配置详情
  137. type SelfMenuButton struct {
  138. Name string `json:"name"`
  139. Type string `json:"type,omitempty"`
  140. Key string `json:"key,omitempty"`
  141. AppID string `json:"appid,omitempty"`
  142. PagePath string `json:"pagepath,omitempty"`
  143. Message string `json:"message,omitempty"`
  144. URL string `json:"url,omitempty"`
  145. MediaId string `json:"media_id,omitempty"`
  146. MediaUrl string `json:"media_url,omitempty"`
  147. SubButton []SelfMenuButton `json:"sub_button,omitempty"`
  148. }
  149. type RefreshToken struct {
  150. AuthorizerAccessToken string `json:"authorizer_access_token"`
  151. ExpiresIn int64 `json:"expires_in"`
  152. AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
  153. }