/// <summary> /// 转换成语音消息 /// </summary> /// <param name="rootMsg"></param> /// <param name="jObject"></param> /// <returns></returns> public static RequestVoiceMsg ToVoiceMsg(this RequestRootMsg rootMsg, JObject jObject) { RequestVoiceMsg voiceMsg = new RequestVoiceMsg() { CreateTime = rootMsg.CreateTime, FromUserName = rootMsg.FromUserName, ToUserName = rootMsg.ToUserName, MediaId = (string)jObject["MediaId"][CDATA_KEY], Format = (string)jObject["Format"][CDATA_KEY], Recognition = (string)jObject["Recognition"][CDATA_KEY], MsgId = (long)jObject["MsgId"] }; return(voiceMsg); }
public static IRequestMsgBase GetRequestEntity(XDocument xml) { RequestMsgBase requestMsg = null; RequestMsgType msgType; try { msgType = MsgTypeHelper.GetRequestMsgType(xml); switch (msgType) { case RequestMsgType.Text: requestMsg = new RequestTestMsg(); break; case RequestMsgType.Location: requestMsg = new RequestLocationMsg(); break; case RequestMsgType.Image: requestMsg = new RequestImageMsg(); break; case RequestMsgType.Voice: requestMsg = new RequestVoiceMsg(); break; case RequestMsgType.Video: requestMsg = new RequestVideoMsg(); break; case RequestMsgType.Link: requestMsg = new RequestLinkMsg(); break; case RequestMsgType.Event: var eventType = EventHelper.GetEventType(xml); switch (eventType) { case Event.LOCATION: requestMsg = new RequestLocationEventMsg(); break; case Event.subscribe: requestMsg = new RequestSubscribeEventMsg(); break; case Event.unsubscribe: requestMsg = new RequestUnsubscribeEventMsg(); break; case Event.CLICK: requestMsg = new RequestClickEventMsg(); break; case Event.scan: requestMsg = new RequestScanEventMsg(); break; default: requestMsg = new RequestEventMsgBase(); break; } break; default: throw new UnknowRequestMsgTypeException(string.Format("MsgType {0} 在RequestMsgFactory中没有对应的处理程序.", msgType), new ArgumentOutOfRangeException()); } //根据XML信息映射实体 requestMsg.FillEntityWithXml(xml); } catch (ArgumentException ex) { throw new WeixinException(string.Format("RequestMsg映射失败,可能是MsgType不存在, XML: {0}", xml.ToString()), ex); } return requestMsg; }
/// <summary> /// 语音请求处理 /// </summary> /// <param name="request">语音请求实体</param> /// <returns></returns> protected virtual ResponseRootMsg OnVoiceRequest(RequestVoiceMsg request) { throw new NotImplementedException(); }
/// <summary> /// 语音请求处理 /// </summary> /// <param name="request">语音请求实体</param> /// <returns></returns> public virtual ResponseRootMsg OnVoiceRequest(RequestVoiceMsg request) { return(OnDefault(request)); }