<%@ WebHandler Language="C#" Class="wx_Handler_2" Debug="true" %> using System; using System.Web; using System.IO; using Tencent; /* * 此页面,接受公众平台回调的用户位置信息,并作处理 * * * */ public class wx_Handler_2 : IHttpHandler { public void ProcessRequest (HttpContext context) { Weixin wx = new Weixin(context); if (wx.IsVerifyURL) { wx.VerifyURL(); } else { //Tencent.GPSMessage msg = (Tencent.GPSMessage)wx.DecryptMsg(); wx.Debug = false; MessageObject msg= wx.DecryptMsg(); //---debug--------- if (wx.Debug) { string logFile = Path.Combine(context.Request.PhysicalApplicationPath, @"log.txt"); System.IO.File.AppendAllText(logFile, string.Format("{0} {1} \r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), msg.Msg)); } //========================= if (msg is LocationEventMessage) { LocationEventMessage emsg = (LocationEventMessage)msg; if (emsg.Event.Equals(MsgConstClass.MsgEventClass.C_Location, StringComparison.CurrentCultureIgnoreCase)) { //只接收地理位置上报信息,排除选择的地理信息 double longitude = 118.791883; //签到地理中心坐标经度 double latitude = 31.898178; //签到地理中心坐标纬度 System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendFormat("[{1}]{0},您好!", msg.FromUserName,DateTime.Now.ToString("HH:mm")); if (Math.Abs(Convert.ToDouble(emsg.Latitude) - latitude) < 0.00337 && Math.Abs(Convert.ToDouble(emsg.Longitude) - longitude) < 0.00424) { sb.Append("您已成功签到。"); } else { sb.Append("您所在的位置不符合签到条件,请稍后重试。"); } sb.AppendFormat("【{0},{1}】", emsg.Longitude, emsg.Latitude); string sql = "select * from " + msg.FromUserName; wx.Messager.GetAccesstoken(); wx.Messager.SendTextToUser(sb.ToString(), msg.AgentID, msg.FromUserName); } } } } public bool IsReusable { get { return false; } } } /* 进入应用上报地理信息报文: (2015/4/15 @ mingjing) 1429098598 32.027634 118.738693 110.000000 1 */