上面是老版本的源码,这个新版本的源码有老版本的所有功能:
实现的功能:
1:获取用户的基本信息,
2:获取用户的详细资料
3:实现了微信扫描二维码的功能,并显示扫描结果
4:获取相册图片或者拍照,并显示图片
5:获取用户的地理位置信息
6:智能聊天,能够和微信号实现智能聊天
智能聊天的主要代码:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.IO;
- using System.Configuration;
- using WeChat.Models.Message;
- using WeChat.BLL;
- namespace WeiXinDemo.Controllers
- {
- public class MessageController : Controller
- {
- //
- // GET: /Message/
- [HttpGet]
- public ActionResult Index(string signature, string timestamp, string nonce)
- {
- string echostr = Request["echostr"];
- string sign = WeChat.BLL.WeChatSign.Sign(new string[] { timestamp, nonce, ConfigurationManager.AppSettings["weixin_token"] });
- if (sign.Equals(signature))
- {
- return Content(echostr == null ? "null" : echostr);
- }
- else {
- return Content("shit");
- }
- }
- [HttpPost,ActionName("Index")]
- public ActionResult IndexPost(string signature, string timestamp, string nonce)
- {
- string sign = WeChat.BLL.WeChatSign.Sign(new string[] { timestamp, nonce, ConfigurationManager.AppSettings["weixin_token"] });
- if (!sign.Equals(signature))
- {
- return Content("参数错误!");
- }
- var stream = Request.InputStream;
- Byte[] postBytes = new Byte[stream.Length];
- stream.Read(postBytes, 0, (Int32)stream.Length);
- //接收消息
- WeChat.Models.Message.TextMessageReceive messge = WeChat.BLL.WeChatSerializer.Deserialize<WeChat.Models.Message.TextMessageReceive>(postBytes);
- string moban = @"<xml><ToUserName><![CDATA[{0}]]></ToUserName><FromUserName><![CDATA[{1}]]></FromUserName><CreateTime>{2}</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[{3}]]></Content></xml>";
- string temp1 = string.Format(moban, messge.FromUserName, messge.ToUserName, WeChat.Tools.TimeHelp.GetTimeStamp(DateTime.Now, 10), WeChatMachine.Chat(messge.Content) + "\n" + "auth:码农网www.itsvse.com");
- //string str = System.Text.Encoding.UTF8.GetString(postBytes);
- //Wired(str);
- return Content(temp1);
- }
- private void Wired(string url)
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + @"\get.txt";
- System.IO.File.Delete(path);
- using (FileStream str = new FileStream(path, FileMode.Create))
- {
- StreamWriter mySw = new StreamWriter(str);
- mySw.Write(url);
- mySw.Close();
- str.Close();
- }
- }
- }
- }
复制代码
源码下载:
|