40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package enterprise_wechat
|
||
|
||
import (
|
||
"encoding/xml"
|
||
)
|
||
|
||
// 回调参数(推送SuiteTicket)
|
||
type SuiteTicketInfo struct {
|
||
SuiteId string `xml:"SuiteId"` // 第三方应用的SuiteId
|
||
InfoType string `xml:"InfoType"` // suite_ticket
|
||
TimeStamp int64 `xml:"TimeStamp"` // 时间戳
|
||
SuiteTicket string `xml:"SuiteTicket"` // Ticket内容,最长为512字节
|
||
}
|
||
|
||
// 回调参数(解密推送消息Encrypt =》 SuiteTicketInfo 转化为上面的推送信息)
|
||
type SuiteEncrypt struct {
|
||
ToUserName string `xml:"ToUserName"` // 企业微信的CorpID,当为第三方套件回调事件时,CorpID的内容为suiteid
|
||
AgentID string `xml:"AgentID"` // 接收的应用id,可在应用的设置页面获取
|
||
Encrypt string `xml:"Encrypt"` // 消息结构体加密后的字符串
|
||
}
|
||
|
||
// 解密加密推送信息
|
||
func (a *API) GetEnterpriseSend(request []byte) (*SuiteEncrypt, error) {
|
||
encrypt := &SuiteEncrypt{}
|
||
if err := xml.Unmarshal(request, encrypt); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return encrypt, nil
|
||
}
|
||
|
||
func (a *API) GetEnterpriseMsg(param []byte) (*SuiteTicketInfo, error) {
|
||
suite := &SuiteTicketInfo{}
|
||
if err := xml.Unmarshal(param, suite); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return suite, nil
|
||
}
|