/// <summary> /// <![CDATA[取消关注]]> /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual Task OnUnsubscribe(WeiXinContext context) { if (Options.OnUnsubscribeAsync != null) { return(Options.OnUnsubscribeAsync(context)); } return(Task.Delay(0)); }
/// <summary> /// <![CDATA[上报地理位置]]> /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual Task OnLocation(WeiXinContext context) { if (Options.OnLocationAsync != null) { return(Options.OnLocationAsync(context)); } return(Task.Delay(0)); }
/// <summary> /// <![CDATA[被动接收消息]]> /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual Task OnRecieveMessage(WeiXinContext context) { if (Options.OnRecieveMessageAsync != null) { return(Options.OnRecieveMessageAsync(context)); } return(Task.Delay(0)); }
/// <summary> /// <![CDATA[虚方法,接收消息后处理]]> /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual Task OnRecieve(HttpContext context, List <int> tenantIds) { if (Options.OnRecieveAsync != null) { return(Options.OnRecieveAsync(context)); } string strRecieveBody = null;//接收消息 using (System.IO.StreamReader streamReader = new System.IO.StreamReader(context.Request.Body)) { strRecieveBody = streamReader.ReadToEndAsync().GetAwaiter().GetResult(); logger.Info($"接收内容:{strRecieveBody}"); strRecieveBody = TTWork.WeiXinMiddleware.Utils.ClearXmlHeader(strRecieveBody); } //反序列化 var recieve = _XmlSerializer.Deserialize(strRecieveBody) as WeiXinMessage; LogTask(tenantIds, recieve, strRecieveBody); //事件消息 if (recieve.MsgType == Constants.MSG_TYPE.EVENT) { var weiXinContext = new WeiXinContext(recieve, context, tenantIds); var actionName = recieve.Event.ToLower(); actionName = actionName.First().ToString().ToUpper() + actionName.Substring(1); var action = this.GetType().GetMethod($"On{actionName}"); if (action != null) { return((Task)action.Invoke(this, new object[] { weiXinContext })); } } //被动接收消息 else { return(OnRecieveMessage(new WeiXinContext(recieve, context, tenantIds))); } return(Task.Delay(0)); }