(rawXMLMsgBytes []byte)
| 188 | } |
| 189 | |
| 190 | func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixMessage, err error) { |
| 191 | msg = &message.MixMessage{} |
| 192 | if !srv.isJSONContent { |
| 193 | err = xml.Unmarshal(rawXMLMsgBytes, msg) |
| 194 | return |
| 195 | } |
| 196 | // parse json |
| 197 | err = json.Unmarshal(rawXMLMsgBytes, msg) |
| 198 | if err != nil { |
| 199 | return |
| 200 | } |
| 201 | // nonstandard json, 目前小程序订阅消息返回数据格式不标准,订阅消息模板单个 List 返回是对象,多个 List 返回是数组。 |
| 202 | if msg.MsgType == message.MsgTypeEvent { |
| 203 | listData := gjson.Get(string(rawXMLMsgBytes), "List") |
| 204 | if listData.IsObject() { |
| 205 | listItem := message.SubscribeMsgPopupEvent{} |
| 206 | if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil { |
| 207 | return msg, parseErr |
| 208 | } |
| 209 | msg.SetSubscribeMsgPopupEvents([]message.SubscribeMsgPopupEvent{listItem}) |
| 210 | } else if listData.IsArray() { |
| 211 | listItems := make([]message.SubscribeMsgPopupEvent, 0) |
| 212 | if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil { |
| 213 | return msg, parseErr |
| 214 | } |
| 215 | msg.SetSubscribeMsgPopupEvents(listItems) |
| 216 | } |
| 217 | } |
| 218 | return |
| 219 | } |
| 220 | |
| 221 | // SetMessageHandler 设置用户自定义的回调方法 |
| 222 | func (srv *Server) SetMessageHandler(handler func(*message.MixMessage) *message.Reply) { |
no test coverage detected