欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信公眾平臺(tái)開發(fā)之地理位置.Net代碼解析

 更新時(shí)間:2016年06月29日 14:13:07   作者:hemeng  
這篇文章主要為大家詳細(xì)解析了微信公眾平臺(tái)開發(fā)之地理位置.Net代碼,感興趣的小伙伴們可以參考一下

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

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代表經(jīng)度,Scale代表縮放比例,Label代表位置的描述
    和接受文本,語(yǔ)音消息一下樣,地理信息的MsgType為“l(fā)ocation”,修改一下之前的GetWxMessage()函數(shù)和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直接回復(fù)“你好”";
         res = sendTextMessage(wx, content);
       }
       else
       {
         content = "二維碼參數(shù):\n" + wx.EventKey.Replace("qrscene_", "");
         res = sendTextMessage(wx, content);
       }
     }

     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.ToLower() == "scan")
     {
       string str = "二維碼參數(shù):\n" + wx.EventKey;
       res = sendTextMessage(wx, str);
     }
     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "CLICK")
     {
       if(wx.EventKey=="HELLO")
         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺(tái)!");
     }
     else
     {
       WriteLog(wx.MsgType);
       if (wx.MsgType == "text" && wx.Content == "你好")
       {
         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺(tái)!");
       }
       else if (wx.MsgType == "voice")
       {
         res = sendTextMessage(wx, wx.Recognition);
       }
       else if (wx.MsgType == "location")
       {
         res = sendTextMessage(wx, "您發(fā)送的位置是:" + wx.Label + ";緯度是:" + wx.Location_X + ";經(jīng)度是:" + wx.Location_Y + ";縮放比例為:" + wx.Scale);
       }
       else
       {
         res = sendTextMessage(wx, "你好,未能識(shí)別消息!");
       }
     }

     Response.Write(res);
   }

        這樣當(dāng)我們發(fā)送一個(gè)地理位置信息的時(shí)候就可以反饋?lái)憫?yīng)的信息了。值得一提的是:這里的地理信息位置無(wú)需授權(quán),因?yàn)樽约喊l(fā)送的地理信息位置不一定是自己的真實(shí)位置,我們可以在輸入界面進(jìn)行任意選擇,不會(huì)涉及隱私。
        當(dāng)然如果我們像制作類似于“我附近”的功能的時(shí)候,就必須有兩個(gè)條件,在微信公共號(hào)中開啟獲取用戶地理信息的功能。第二,用戶自己在關(guān)注微信的時(shí)候允許微信公共號(hào)獲取我的位置。這就需要用到我們?cè)谖恼麻_始的時(shí)候給大家介紹的第二種情況了。按照微信的解釋,當(dāng)一個(gè)會(huì)話開始的時(shí)候(也就是說(shuō)進(jìn)入對(duì)話界面的時(shí)候),首先獲取一下,然后每個(gè)五秒自動(dòng)獲取一次。也就是就是說(shuō)獲得用戶位置信息的時(shí)候觸發(fā)的不是“你一言我一語(yǔ)的對(duì)話”,而是一個(gè)特殊的事件,每格五秒出發(fā)一次。這里被定義為MsgType為“event”,而為了區(qū)別于其他的“event”,他的EventName(其實(shí)官方叫做event)為“LOCATION”(大寫哦)。
        下面我依然需要按照微信的格式修改我們的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; }
    public string Latitude { get; set; }
    public string Longitude { get; set; }
    public string Precision { get; set; }

  }
    改造一下GetWxMessage()函數(shù)和OnLoad函數(shù):
 
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;
     WriteLog("MsgType:"+wx.MsgType);
     if (wx.MsgType.Trim() == "event")
     {
       wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
       WriteLog(wx.EventName);
       if (wx.EventName.ToUpper() == "LOCATION")
       {
         wx.Latitude = xml.SelectSingleNode("xml").SelectSingleNode("Latitude").InnerText;
         wx.Longitude = xml.SelectSingleNode("xml").SelectSingleNode("Longitude").InnerText;
         wx.Precision = xml.SelectSingleNode("xml").SelectSingleNode("Precision").InnerText;
       }
       else
       {
         wx.EventKey = xml.SelectSingleNode("xml").SelectSingleNode("EventKey").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() == "voice")
     {
       wx.Recognition = xml.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;
     }
     
     return wx;
   }

       當(dāng)MsgType為event的時(shí)候我們之前用到的是菜單的事件,現(xiàn)在我們需要加入其EventName為"LOCATION"的代碼段,因?yàn)楝F(xiàn)在還沒(méi)有涉及其他的event我后面就用else好了,后面我會(huì)把代碼寫的規(guī)范些。在這里分別給新增的三個(gè)屬性賦值,然后修改一下Onload函數(shù) 

 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直接回復(fù)“你好”";
         res = sendTextMessage(wx, content);
       }
       else
       {
         content = "二維碼參數(shù):\n" + wx.EventKey.Replace("qrscene_", "");
         res = sendTextMessage(wx, content);
       }
     }

     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.ToLower() == "scan")
     {
       string str = "二維碼參數(shù):\n" + wx.EventKey;
       res = sendTextMessage(wx, str);
     }
     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "CLICK")
     {
       if(wx.EventKey=="HELLO")
         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺(tái)!");
     }
     else if (!string.IsNullOrEmpty(wx.EventName) && wx.EventName.Trim() == "LOCATION")
     {
       res = sendTextMessage(wx, "您的位置是經(jīng)度:" + wx.Latitude + ",維度是:" + wx.Longitude+",地理經(jīng)度為:"+wx.Precision);
     }
     else
     {
       if (wx.MsgType == "text" && wx.Content == "你好")
       {
         res = sendTextMessage(wx, "你好,歡迎使用北京永杰友信科技有限公司公共微信平臺(tái)!");
       }
       else if (wx.MsgType == "voice")
       {
         res = sendTextMessage(wx, wx.Recognition);
       }
       else if (wx.MsgType == "location")
       {
         res = sendTextMessage(wx, "您發(fā)送的位置是:" + wx.Label + ";緯度是:" + wx.Location_X + ";經(jīng)度是:" + wx.Location_Y + ";縮放比例為:" + wx.Scale);
       }
       else
       {
         res = sendTextMessage(wx, "你好,未能識(shí)別消息!");
       }
     }

     Response.Write(res);
   }

        好了,完成,這樣當(dāng)你開啟你的微信“獲得用戶位置信息”的時(shí)候微信平臺(tái)會(huì)提醒你,是僅進(jìn)入會(huì)話第一次獲取,還是每個(gè)5秒獲取一次,如果你選擇了后者,你就會(huì)看到,每5秒會(huì)反饋給你一個(gè)地理位置的信息。
        這里面需要非常注意的是:我按照這樣認(rèn)為沒(méi)有問(wèn)題了,但是怎么也獲得不了信息,那是因?yàn)槲以谶M(jìn)入會(huì)話的時(shí)候,你會(huì)看到你的手機(jī)GPS在搜索,在GPS定位以前,是不會(huì)看到內(nèi)容的??梢赃@樣理解,當(dāng)你GPS搜索定位后,才會(huì)觸發(fā)獲得用戶位置信息的事件,這一點(diǎn)并不是我想象的通過(guò)基站定位也可以獲得大致的位置,這一點(diǎn)需要開發(fā)者注意,我就是弄了半天,等我出門兒,手機(jī)定位了無(wú)意間看到了回復(fù),這才恍然大悟。
        說(shuō)到這里可以各位會(huì)問(wèn)只知道經(jīng)緯度坐標(biāo)有什么用?又不是具體位置。其實(shí)不然,我們可以使用多種方法知道位置詳細(xì)的信息,例如我們可以通過(guò)BaiduMap API的地址反向解析指導(dǎo)這個(gè)坐標(biāo)在那個(gè)城市,那個(gè)街道等內(nèi)容,甚至可以知道附近的情況,這里就不再多說(shuō)了,以后有機(jī)會(huì)和大家一起來(lái)談?wù)凚aiduMap

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。 

相關(guān)文章

  • 三步將Asp.Net頁(yè)面輸出到EXCEL里

    三步將Asp.Net頁(yè)面輸出到EXCEL里

    利用ASP.NET輸出指定內(nèi)容的WORD、EXCEL、TXT、HTM等類型的文檔很容易的,下面為大家簡(jiǎn)單介紹下,感興趣的朋友可以參考參考
    2014-05-05
  • asp.net core集成JWT的步驟記錄

    asp.net core集成JWT的步驟記錄

    這篇文章主要給大家介紹了關(guān)于asp.net core集成JWT的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用asp.net core具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • .net5?使用Hangfire的過(guò)程記錄

    .net5?使用Hangfire的過(guò)程記錄

    最近項(xiàng)目遇到這樣的需求,需要實(shí)現(xiàn)根據(jù)領(lǐng)取時(shí)間改變優(yōu)惠券狀態(tài)的功能,本文給大家分享.net5?使用Hangfire的過(guò)程記錄,感興趣的朋友跟隨小編一起看看吧
    2022-02-02
  • swfupload ajax無(wú)刷新上傳圖片實(shí)例代碼

    swfupload ajax無(wú)刷新上傳圖片實(shí)例代碼

    在這里上傳圖片就需要用到ajax無(wú)刷新上傳圖片,這里面包含的東西不是一點(diǎn)半點(diǎn)。這里用到的是一個(gè)插件swfupload實(shí)現(xiàn)無(wú)刷新上傳圖片,感興趣的朋友可以參考下哈
    2013-06-06
  • ASP.NET MVC中Controller控制器向View視圖傳值的幾種方式

    ASP.NET MVC中Controller控制器向View視圖傳值的幾種方式

    這篇文章介紹了ASP.NET MVC中Controller控制器向View視圖傳值的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • TreeNodeCheckChanged事件觸發(fā)方法代碼實(shí)例

    TreeNodeCheckChanged事件觸發(fā)方法代碼實(shí)例

    這篇文章主要介紹了TreeNodeCheckChanged事件觸發(fā)方法代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-12-12
  • .NET Core中HttpClient的正確打開方式

    .NET Core中HttpClient的正確打開方式

    這篇文章主要給大家介紹了關(guān)于.NET Core中HttpClient的正確打開方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • .Net?Core?進(jìn)程守護(hù)之Supervisor使用詳解

    .Net?Core?進(jìn)程守護(hù)之Supervisor使用詳解

    這篇文章主要介紹了.Net?Core?進(jìn)程守護(hù)之Supervisor使用,Supervisor它可以很方便的監(jiān)聽、啟動(dòng)、停止、重啟一個(gè)或多個(gè)進(jìn)程,對(duì).Net?Core?進(jìn)程守護(hù)之Supervisor使用相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-04-04
  • asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用七牛轉(zhuǎn)換法)

    asp.net音頻轉(zhuǎn)換之.amr轉(zhuǎn).mp3(利用七牛轉(zhuǎn)換法)

    相信很多人都遇到amr格式的音頻文件不能直接在網(wǎng)頁(yè)播放的問(wèn)題,有人使用QuickTime插件的輔助,下面這篇文章主要給大家介紹了asp.net音頻轉(zhuǎn)換之利用七牛轉(zhuǎn)換法將.amr格式轉(zhuǎn).mp3格式,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2016-12-12
  • Linux安裝.Net core 環(huán)境并運(yùn)行項(xiàng)目的方法

    Linux安裝.Net core 環(huán)境并運(yùn)行項(xiàng)目的方法

    這篇文章主要介紹了Linux安裝.Net core 環(huán)境并運(yùn)行項(xiàng)目,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08

最新評(píng)論