mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-17 03:02:26 +08:00
将原始消息内容暴露
This commit is contained in:
@@ -29,10 +29,10 @@ type Server struct {
|
|||||||
|
|
||||||
messageHandler func(message.MixMessage) *message.Reply
|
messageHandler func(message.MixMessage) *message.Reply
|
||||||
|
|
||||||
requestRawXMLMsg []byte
|
RequestRawXMLMsg []byte
|
||||||
requestMsg message.MixMessage
|
RequestMsg message.MixMessage
|
||||||
responseRawXMLMsg []byte
|
ResponseRawXMLMsg []byte
|
||||||
responseMsg interface{}
|
ResponseMsg interface{}
|
||||||
|
|
||||||
isSafeMode bool
|
isSafeMode bool
|
||||||
random []byte
|
random []byte
|
||||||
@@ -71,7 +71,7 @@ func (srv *Server) Serve() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//debug print request msg
|
//debug print request msg
|
||||||
log.Debugf("request msg =%s", string(srv.requestRawXMLMsg))
|
log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg))
|
||||||
|
|
||||||
return srv.buildResponse(response)
|
return srv.buildResponse(response)
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
|
|||||||
if !success {
|
if !success {
|
||||||
err = errors.New("消息类型转换失败")
|
err = errors.New("消息类型转换失败")
|
||||||
}
|
}
|
||||||
srv.requestMsg = mixMessage
|
srv.RequestMsg = mixMessage
|
||||||
reply = srv.messageHandler(mixMessage)
|
reply = srv.messageHandler(mixMessage)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func (srv *Server) getMessage() (interface{}, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srv.requestRawXMLMsg = rawXMLMsgBytes
|
srv.RequestRawXMLMsg = rawXMLMsgBytes
|
||||||
|
|
||||||
return srv.parseRequestMessage(rawXMLMsgBytes)
|
return srv.parseRequestMessage(rawXMLMsgBytes)
|
||||||
}
|
}
|
||||||
@@ -204,10 +204,10 @@ func (srv *Server) buildResponse(reply *message.Reply) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
params := make([]reflect.Value, 1)
|
params := make([]reflect.Value, 1)
|
||||||
params[0] = reflect.ValueOf(srv.requestMsg.FromUserName)
|
params[0] = reflect.ValueOf(srv.RequestMsg.FromUserName)
|
||||||
value.MethodByName("SetToUserName").Call(params)
|
value.MethodByName("SetToUserName").Call(params)
|
||||||
|
|
||||||
params[0] = reflect.ValueOf(srv.requestMsg.ToUserName)
|
params[0] = reflect.ValueOf(srv.RequestMsg.ToUserName)
|
||||||
value.MethodByName("SetFromUserName").Call(params)
|
value.MethodByName("SetFromUserName").Call(params)
|
||||||
|
|
||||||
params[0] = reflect.ValueOf(msgType)
|
params[0] = reflect.ValueOf(msgType)
|
||||||
@@ -216,19 +216,19 @@ func (srv *Server) buildResponse(reply *message.Reply) (err error) {
|
|||||||
params[0] = reflect.ValueOf(util.GetCurrTs())
|
params[0] = reflect.ValueOf(util.GetCurrTs())
|
||||||
value.MethodByName("SetCreateTime").Call(params)
|
value.MethodByName("SetCreateTime").Call(params)
|
||||||
|
|
||||||
srv.responseMsg = msgData
|
srv.ResponseMsg = msgData
|
||||||
srv.responseRawXMLMsg, err = xml.Marshal(msgData)
|
srv.ResponseRawXMLMsg, err = xml.Marshal(msgData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send 将自定义的消息发送
|
//Send 将自定义的消息发送
|
||||||
func (srv *Server) Send() (err error) {
|
func (srv *Server) Send() (err error) {
|
||||||
replyMsg := srv.responseMsg
|
replyMsg := srv.ResponseMsg
|
||||||
log.Debugf("response msg =%+v", replyMsg)
|
log.Debugf("response msg =%+v", replyMsg)
|
||||||
if srv.isSafeMode {
|
if srv.isSafeMode {
|
||||||
//安全模式下对消息进行加密
|
//安全模式下对消息进行加密
|
||||||
var encryptedMsg []byte
|
var encryptedMsg []byte
|
||||||
encryptedMsg, err = util.EncryptMsg(srv.random, srv.responseRawXMLMsg, srv.AppID, srv.EncodingAESKey)
|
encryptedMsg, err = util.EncryptMsg(srv.random, srv.ResponseRawXMLMsg, srv.AppID, srv.EncodingAESKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user