/// <summary> /// 获取请求消息和实体之间的映射结果 /// </summary> /// <param name="requestMsgType"></param> /// <returns></returns> public override IRequestMessageBase GetRequestEntityMappingResult(RequestMsgType requestMsgType, XDocument doc = null) { RequestMessageBase requestMessage; switch (requestMsgType) { case RequestMsgType.Text: requestMessage = new RequestMessageText(); break; case RequestMsgType.Image: requestMessage = new RequestMessageImage(); break; case RequestMsgType.MiniProgramPage: //小程序页面 requestMessage = new RequestMessageMiniProgramPage(); break; case RequestMsgType.NeuChar: requestMessage = new RequestMessageNeuChar(); break; case RequestMsgType.Event: //判断Event类型 switch (doc.Root.Element("Event").Value.ToUpper()) { case "USER_ENTER_TEMPSESSION": //进入客服会话 requestMessage = new RequestMessageEvent_UserEnterTempSession(); break; case "WEAPP_AUDIT_SUCCESS": //小程序审核成功 requestMessage = new RequestMessageEvent_WeAppAuditSuccess(); break; case "WEAPP_AUDIT_FAIL": //小程序审核失败 requestMessage = new RequestMessageEvent_WeAppAuditFail(); break; case "WEAPP_AUDIT_DELAY": //小程序审核延后 requestMessage = new RequestMessageEvent_WeAppAuditDelay(); break; case "WXA_NICKNAME_AUDIT": //名称审核结果 requestMessage = new RequestMessageEvent_NicknameAudit(); break; default: //其他意外类型(也可以选择抛出异常) requestMessage = new RequestMessageEventBase(); break; } break; default: throw new UnknownRequestMsgTypeException(string.Format("MsgType:{0} 在RequestMessageFactory中没有对应的处理程序!", requestMsgType), new ArgumentOutOfRangeException()); //为了能够对类型变动最大程度容错(如微信目前还可以对公众账号suscribe等未知类型,但API没有开放),建议在使用的时候catch这个异常 } return(requestMessage); }
public override async Task <IResponseMessageBase> OnMiniProgramPageRequestAsync(RequestMessageMiniProgramPage requestMessage) { var msg = @$ "您从某个小程序页面来到客服,并且发送了小程序卡片。 Title:{requestMessage.Title} AppId:{requestMessage.AppId.Substring(1,5)}...
public override async Task <IResponseMessageBase> OnMiniProgramPageRequestAsync(RequestMessageMiniProgramPage requestMessage) { var msg = $"您从某个小程序页面来到客服,并且发送了小程序卡片。\r\nTitle:{requestMessage.Title}\r\nAppId:{requestMessage.AppId.Substring(1,5)}...\r\nPagePath:{requestMessage.PagePath}\r\n附带照片:"; await Senparc.Weixin.WxOpen.AdvancedAPIs.CustomApi.SendTextAsync(appId, OpenId, msg); await Senparc.Weixin.WxOpen.AdvancedAPIs.CustomApi.SendImageAsync(appId, OpenId, requestMessage.ThumbMediaId); return(await DefaultResponseMessageAsync(requestMessage)); }
public async virtual Task <IResponseMessageBase> OnMiniProgramPageRequestAsync(RequestMessageMiniProgramPage requestMessage) { return(await DefaultResponseMessageAsync(requestMessage).ConfigureAwait(false)); }