微信--使用客服消息异步自动回复用户消息
关于重试的消息排重,有msgid的消息推荐使用msgid排重。事件类型消息推荐使用FromUserName + CreateTime 排重。 1、开发者在5秒内未回复任何内容 2、开发者回复了异常数据,比如JSON数据等
我们无法保证我们服务器能在5秒回应的话,推荐使用异步处理,使用客服消息回复用户(不讨论客服消息次数限制等问题)
WeixinServer
1 #region 静态全局变量 2 private static Token _Token = null; 3 private static Ticket _Ticket = null; 4 private readonly static string appid = "wx123456789000"; 5 private readonly static string secret = "abcdefghijklmnopqrstuvwxyz"; 6 private readonly static string domain = "http://wechat.mydomain.com"; 7 #endregion1 #region 静态全局变量 2 private static Token _Token = null; 3 private static Ticket _Ticket = null; 4 private readonly static string appid = "wx123456789000"; 5 private readonly static string secret = "abcdefghijklmnopqrstuvwxyz"; 6 private readonly static string domain = "http://wechat.mydomain.com"; 7 #endregion
Action里面处理
1 [HttpPost]
2 public ActionResult Access()
3 {
4 //异步操作 使用客服消息接口回复用户
5 Stream stream = Request.InputStream;
6 AsyncManager.OutstandingOperations.Increment();
7 var task = Task.Factory.StartNew(() => weixin.DisposeMsg(stream));
8 task.ContinueWith(t =>
9 {
10 //AsyncManager.Parameters["model"] = t.Result;
11 AsyncManager.OutstandingOperations.Decrement();
12 });
13 return Content("");
14 } 1 [HttpPost] 2 public ActionResult Access() 3 { 4 //异步操作 使用客服消息接口回复用户 5 Stream stream = Request.InputStream; 6 AsyncManager.OutstandingOperations.Increment(); 7 var task = Task.Factory.StartNew(() => weixin.DisposeMsg(stream)); 8 task.ContinueWith(t => 9 { 10 //AsyncManager.Parameters["model"] = t.Result; 11 AsyncManager.OutstandingOperations.Decrement(); 12 }); 13 return Content(""); 14 }
