/// <summary> /// 转换成地理位置信息 /// </summary> /// <param name="rootMsg"></param> /// <param name="jObject"></param> /// <returns></returns> public static RequestLocationMsg ToLocationMsg(this RequestRootMsg rootMsg, JObject jObject) { RequestLocationMsg locationMsg = new RequestLocationMsg() { CreateTime = rootMsg.CreateTime, FromUserName = rootMsg.FromUserName, ToUserName = rootMsg.ToUserName, Location_X = (double)jObject["Location_X"], Location_Y = (double)jObject["Location_Y"], Scale = (int)jObject["Scale"], Label = (string)jObject["Label"][CDATA_KEY], MsgId = (long)jObject["MsgId"] }; return(locationMsg); }
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 OnLocationRequest(RequestLocationMsg request) { throw new NotImplementedException(); }
/// <summary> /// 地理位置请求处理 /// </summary> /// <param name="request">地理位置请求实体</param> /// <returns></returns> public virtual ResponseRootMsg OnLocationRequest(RequestLocationMsg request) { return(OnDefault(request)); }