国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

微信公眾平臺開發之地理位置.Net代碼解析

2024-07-10 12:47:02
字體:
來源:轉載
供稿:網友

微信公共平臺中涉及到地理位置的有兩種情況:
        第一、我發送一個自選的地理位置給微信,然后微信可以自動反饋響應的信息。
        第二、讓微信獲取我們GPS定位地址位置,反饋響應的信息。 
       首先我們先來看第一種,在微信中除了可以發文本,圖片,語音等還有一個信息就是地理位置,按照微信接受地理信息的XML信息,我們需要改造一下之前的wxmessage類加上幾個屬性: 

class wxmessage   {     public string FromUserName { get; set; }     public string ToUserName { get; set; }     public string MsgType { get; set; }     public string EventName { get; set; }     public string Content { get; set; }    public string Recognition { get; set; }    public string MediaId { get; set; }    public string EventKey { get; set; }     public string Location_X { get; set; }    public string Location_Y { get; set; }    public string Scale { get; set; }    public string Label { get; set; }  }    其中Location_X代表緯度,Location_Y代表經度,Scale代表縮放比例,Label代表位置的描述    和接受文本,語音消息一下樣,地理信息的MsgType為“location”,修改一下之前的GetWxMessage()函數和OnLoad里面的消息處理: 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() == "location")     {       wx.Location_X = xml.SelectSingleNode("xml").SelectSingleNode("Location_X").InnerText;       wx.Location_Y = xml.SelectSingleNode("xml").SelectSingleNode("Location_Y").InnerText;       wx.Scale = xml.SelectSingleNode("xml").SelectSingleNode("Scale").InnerText;       wx.Label = xml.SelectSingleNode("xml").SelectSingleNode("Label").InnerText;     }     if (wx.MsgType.Trim() == "event")     {       wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;       wx.EventKey = xml.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText;     }     if (wx.MsgType.Trim() == "voice")     {       wx.Recognition = xml.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;     }          return wx;   }  protected void Page_Load(object sender, EventArgs e)   {     wxmessage wx = GetWxMessage();     string res = "";     if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "subscribe")     {       string content = "";       if (!wx.EventKey.Contains("qrscene_"))       {         content = "/:rose歡迎北京永杰友信科技有限公司/:rose/n直接回復“你好”";         res = sendTextMessage(wx, content);       }       else       {         content = "二維碼參數:/n" + wx.EventKey.Replace("qrscene_", "");         res = sendTextMessage(wx, content);       }     }     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.ToLower() == "scan")     {       string str = "二維碼參數:/n" + wx.EventKey;       res = sendTextMessage(wx, str);     }     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "CLICK")     {       if(wx.EventKey=="HELLO")         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺!");     }     else     {       WriteLog(wx.MsgType);       if (wx.MsgType == "text" && wx.Content == "你好")       {         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺!");       }       else if (wx.MsgType == "voice")       {         res = sendTextMessage(wx, wx.Recognition);       }       else if (wx.MsgType == "location")       {         res = sendTextMessage(wx, "您發送的位置是:" + wx.Label + ";緯度是:" + wx.Location_X + ";經度是:" + wx.Location_Y + ";縮放比例為:" + wx.Scale);       }       else       {         res = sendTextMessage(wx, "你好,未能識別消息!");       }     }     Response.Write(res);   }            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 光山县| 盐池县| 叶城县| 大厂| 辽宁省| 晋宁县| 马鞍山市| 秀山| 永昌县| 阿拉善右旗| 修武县| 德惠市| 郴州市| 吉水县| 白城市| 平罗县| 南部县| 乐都县| 潢川县| 罗城| 永嘉县| 九江市| 盐城市| 巴彦县| 浠水县| 贵州省| 玉门市| 珠海市| 黄石市| 桂东县| 惠州市| 桐城市| 尤溪县| 德清县| 韩城市| 东阳市| 青冈县| 卢氏县| 长乐市| 东宁县| 黎川县|