您的位置:首页 > 移动开发 > 微信开发

微信公共平台开发-(.net实现)3--发送文本消息

2014-07-21 08:39 609 查看
最近,项目这边比较忙,没来得及续写,哎,先吐吐槽吧,在这个周六还得来上班,以后每个周六多要上,一天的滋味真有点受不鸟呀。还不习惯ing...

  嗯,别的不说了现在开始接着上次/article/5270499.html 获取ACCESSTOKEN,开始吧,接下来我们就写发送文本消息吧。

   首先建立一个微信消息实体类。此原文出处:blog.csdn.net/hemeng1980/article/details/19503171

    

protected void Page_Load(object sender, EventArgs e)
{
wxmessage wx = GetWxMessage();
string res = "";

if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "subscribe")
{//刚关注时的时间,用于欢迎词
string content = "";
content = "你好,感谢你关注QLJ1314博客";
res = sendTextMessage(wx, content);
}
else
{
if (wx.MsgType == "text" && wx.Content == "你好")
{
res = sendTextMessage(wx, "你好,感谢你关注QLJ1314博客!");
}
else
{
res = sendTextMessage(wx, "这个我也没遇见过,正在向微信客服反应此事,请耐心等待或者可以直接打10086!");
}
}

Response.Write(res);
}
//获取用户基本信息
private wxmessage GetWxMessage()
{
wxmessage wx = new wxmessage();
StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
XmlDocument xml = new XmlDocument();
xml.Load(str);
wx.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
wx.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
wx.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
if (wx.MsgType.Trim() == "text")
{
wx.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
}
if (wx.MsgType.Trim() == "event")
{
wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
}

return wx;
}

/// <summary>
/// 发送文字消息
/// </summary>
/// <param name="wxCont">获取的收发者信息
/// <param name="content">内容
/// <returns>string </returns>
private string sendTextMessage(wxmessage wxCont, string content)
{
string res = string.Format(@" ",
wx.FromUserName, wx.ToUserName, DateTime.Now, content);
return res;
}


View Code
记着一定要和开发文档的格式一致,

一定要把两个关系搞清楚呀。不然是实现不了效果的。哎 行了下班走人,下周再续吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐