/// <summary> /// 微信获取文本信息 /// </summary> /// <param name="postObj">xml文档</param> private void getWXRequestXML(string postStr, ref WXRequest wxRequest) { //回复消息部分 System.Xml.XmlDocument postObj = new System.Xml.XmlDocument(); postObj.LoadXml(postStr); wxRequest = new WXRequest(postObj); }
/// <summary> /// 发送微信 /// </summary> /// <param name="postStr">XML信息</param> private void ResponseMsg(string postStr) { //创建属性文件 WXRequest wxRequest = new WXRequest(); getWXRequestXML(postStr, ref wxRequest);//获取微信消息 string sendStr = ""; sendStr = sendText(wxRequest);//发送微信信息 Response.Write(sendStr); Response.End(); }
//测试信息 private void Test() { WXRequest wxRequest = new WXRequest("event"); wxRequest.FromUserName = "******"; wxRequest.ToUserName = "******"; wxRequest.eventModel.Event = "subscribe"; //wxRequest.textModel.Content = "?"; Response.Write(wxRequest.FromUserName); sendText(wxRequest); }
/// <summary> /// 微信发送文本信息 /// </summary> /// <param name="wxRequestXMLModel">消息发送方微信号</param> /// <param name="ToUserName">消息接收方微信号,一般为公众平台账号微信号</param> /// <param name="Content">消息内容</param> private string sendText(WXRequest wxRequest) { string Result = ""; string FromUserName = wxRequest.FromUserName; string ToUserName = wxRequest.ToUserName; string Content = ""; //创建用户对象 //非员工信息 //if () //{ //if ("ZC")//注册校验,自己可以写自己的用户注册功能 //{ //} if (wxRequest.MsgType.ToLower() == "event") { //EnumEvent ee=(EnumEvent)Enum.Parse(typeof(EnumEvent), wxRequest.eventModel.Event); if (wxRequest.eventModel.Event == EnumMapHelper.GetStringFromEnum(EnumEvent.subscribe)) { Result = "感谢新的关注!"; } else { Result = wxRequest.eventModel.EventKey; } } else if (wxRequest.MsgType.ToLower() == "text") { //EnumEvent ee=(EnumEvent)Enum.Parse(typeof(EnumEvent), wxRequest.eventModel.Event); Content = wxRequest.textModel.Content; } //else //{ // Result = "您好,感谢查看XX微信平台!您当前状态是“未注册”。注册方法是:发送:ZC#张三"; //} //} //else//公司员工 //{ // //属于员工的自己内部业务 //} //创建属性文件 WXResponse wxResponse = new WXResponse("text"); Result = (Result == "" ? "内容[" + Content + "]" : Result); //FromUserName = "******";//模拟发送人,不支持 wxResponse.ToUserName = FromUserName; wxResponse.FromUserName = ToUserName; wxResponse.textModel.Content = Result; WXTool.WriteLog("三、微信平台发送信息sendStr=" + Result); return wxResponse.ResponseXML(); }