国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
1. WeChat’s geographical location information
2、地址位置的應用處理
3、地址位置應用擴展
Home WeChat Applet WeChat Development C# develops WeChat portals and applications using geographical location to expand related applications

C# develops WeChat portals and applications using geographical location to expand related applications

Mar 01, 2017 am 10:33 AM

This article continues the previous article "C# Development of WeChat Portal and Applications (12)-Using Speech Processing" and continues to introduce WeChat related applications. We know that geographical location information can be used for many related applications. In addition to knowing the user's location, we can also associate some geographical location applications, such as weather, popular movies, nearby attractions, nearby theaters, traffic events, etc. Etc. Anyway, for all information related to geographical location, we can make some extended applications as needed. This article mainly introduces how to use geographical location information to build operations that use these applications.

C# develops WeChat portals and applications using geographical location to expand related applications

1. WeChat’s geographical location information

Before using it, let’s take a look at WeChat’s interface, which defines for us those information about geographical location. Information. In fact, the geographical location information is divided into two aspects on WeChat. One is to receive the user's geographical location request, and the other is the geographical location information that the user allows to report the geographical location operation and is sent regularly.

This article mainly introduces related applications based on the first type, how to process the user's geographical location after reporting it.

The geographical location reporting operation is to select the + sign to add the geographical location where you enter it, and then select the current or specified geographical location map. The specific operation is as follows.

C# develops WeChat portals and applications using geographical location to expand related applications ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? C# develops WeChat portals and applications using geographical location to expand related applications

Geolocation Message

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1351776360</CreateTime>
<MsgType><![CDATA[location]]></MsgType>
<Location_X>23.134521</Location_X>
<Location_Y>113.358803</Location_Y>
<Scale>20</Scale>
<Label><![CDATA[位置信息]]></Label>
<MsgId>1234567890123456</MsgId>
</xml>


##FromUserNameSender account (an OpenID)CreateTimeMessage creation time (integer)MsgTypelocation##Location_XLocation_Y##ScaleMap zoom sizeLabelGeographical location informationMsgIdMessage id, 64-bit integer

有了上面的地理位置信息,我們在程序里面,需要在消息傳遞過來的時候,定義一個實體類信息,承載相關的地理位置信息,方便我們進一步的處理操作。

/// <summary>
    /// 接收的地理位置消息
    /// </summary>
    [System.Xml.Serialization.XmlRoot(ElementName = "xml")]
    public class RequestLocation : BaseMessage
    {    
        public RequestLocation()
        {
            this.MsgType = RequestMsgType.Location.ToString().ToLower();
        }
  
        /// <summary>
        /// 消息ID
        /// </summary>
        public Int64 MsgId { get; set; }
        /// <summary>
        /// 地理位置維度
        /// </summary>
        public decimal Location_X { get; set; }
        /// <summary>
        /// 地理位置經(jīng)度
        /// </summary>
        public decimal Location_Y { get; set; }
        /// <summary>
        /// 地圖縮放大小
        /// </summary>
        public int Scale { get; set; }
        /// <summary>
        /// 地理位置信息
        /// </summary>
        public string Label { get; set; }
    }

2、地址位置的應用處理

不過上面的信息,顯然不符合我們擴展應用的要求,因此我們進一步進行完善里面對地理位置信息處理的操作。我們進一步把關于地理位置的操作,放到事件處理模塊里面進行處理,處理代碼如下所示。

 /// <summary>
        /// 對地理位置請求信息進行處理
        /// </summary>
        /// <param name="info">地理位置請求信息實體</param>
        /// <returns></returns>
        public string HandleLocation(Entity.RequestLocation info)
        {
            string xml = "";

            ResponseText txtinfo = new ResponseText(info);
            txtinfo.Content = string.Format("您發(fā)送的地理位置是:{0}", info.Label);
            xml = txtinfo.ToXml();

            return xml;
        }

在處理的時候,我們需要先保存用戶的地理位置信息,把它存儲到用戶的上下文記錄里面。這樣我們在處理指令的時候,把它獲取到,然后傳遞給相關的方法就可以實現(xiàn)地理位置的擴展應用了。

            //保存經(jīng)緯度
            string location = string.Format("{0},{1}", lat, lon);            
            bool result = BLLFactory<UserSet>.Instance.UpdateUserInput(info.FromUserName, location);

首先對用戶地理位置的請求,我根據(jù)數(shù)據(jù)庫配置給出了一個用戶選擇的指令提示,如下所示。

C# develops WeChat portals and applications using geographical location to expand related applications

為了對地理位置請求的處理,我定義了一個用于處理這個操作的指令操作

C# develops WeChat portals and applications using geographical location to expand related applications

這樣整個地理位置的指令操作,就在應答鏈里面進行很好的跳轉管理了。那么為了實現(xiàn)天氣、放映影片、附近影院、旅游線路、交通事件等方面的擴展應用,我們應該如何操作呢?

3、地址位置應用擴展

我們知道,百度或者騰訊都提供了一些開放平臺,給我們進行各種方式的使用。那么我們這里以使用百度LBS平臺應用來構建一些模塊。

C# develops WeChat portals and applications using geographical location to expand related applications

C# develops WeChat portals and applications using geographical location to expand related applications

這上面都有很多相關的接口供使用,我們可以根據(jù)其提供的數(shù)據(jù)格式進行封裝,然后進行調(diào)用處理就可以了。

剛才說了,我配置了一些指令,用來構建相關的應用,指令的最后是一些事件代碼的定義,我們對這些末端的事件代碼進行處理,就可以給用戶返回相關的信息了,總體的操作代碼如下所示。

/// <summary>
        /// 其他插件操作,如天氣,景點、電影影訊、交通等
        /// </summary>
        /// <param name="info">基礎消息</param>
        /// <param name="eventKey">事件標識</param>
        /// <returns></returns>
        public string DealPlugin(BaseMessage info, string eventKey)
        {
            //LogTextHelper.Info(eventKey);
            string userInput = BLLFactory<UserSet>.Instance.GetUserInput(info.FromUserName);
            string xml = "";
            switch (eventKey)
            {
                case "event-void-wether":
                    xml = new WeatherPlugin().Response(info, userInput);
                    break;
                case "event-void-movie":
                    xml = new MoviePlugin().Response(info, userInput);
                    break;
                case "event-void-cinema":
                    xml = new CinemaPlugin().Response(info, userInput);
                    break;
                case "event-void-travel":
                    xml = new TravelPlugin().Response(info, userInput);
                    break;
                case "event-void-traffic":
                    xml = new TrafficEventPlugin().Response(info, userInput);
                    break;
                default:
                    break;
            }
            return xml;
        }

這里以天氣為例,說明該如何調(diào)用百度的接口的,首先我們封裝一下相關的接口調(diào)用。

/// <summary>
        /// 根據(jù)參數(shù)調(diào)用百度接口,獲取相關的結果數(shù)據(jù)
        /// </summary>
        /// <param name="location">地理位置</param>
        /// <param name="ak">API調(diào)用鍵</param>
        /// <returns></returns>
        public BaiduWeatherResult Execute(string location, string ak)
        {
            location = HttpUtility.UrlEncode(location);
            var url = string.Format("http://api.map.baidu.com/telematics/v3/weather?location={0}&output=json&ak={1}", location, ak);

            BaiduWeatherResult result = BaiduJsonHelper<BaiduWeatherResult>.ConvertJson(url);
            return result;
        }

其中的BaiduWeatherResult 是我根據(jù)調(diào)用返回的Json結果,構建的一個實體類,用來存儲返回的內(nèi)容。具體代碼如下所示。

/// <summary>
    /// 天氣請求結果Json對象
    /// </summary>
    public class BaiduWeatherResult : BaiduResult
    {
        /// <summary>
        /// 天氣預報信息
        /// </summary>
        public List<BaiduWeatherData> results = new List<BaiduWeatherData>();
    }

    /// <summary>
    /// 城市的天氣信息
    /// </summary>
    public class BaiduWeatherData
    {
        /// <summary>
        /// 當前城市
        /// </summary>
        public string currentCity { get; set; }

        /// <summary>
        /// 天氣預報信息
        /// </summary>
        public List<BaiduWeatherJson> weather_data = new List<BaiduWeatherJson>();
    }

    /// <summary>
    /// 天氣預報的單條記錄Json信息
    /// </summary>
    public class BaiduWeatherJson
    {
        /// <summary>
        /// 天氣預報時間
        /// </summary>
        public string date { get; set; }

        /// <summary>
        /// 白天的天氣預報圖片url
        /// </summary>
        public string dayPictureUrl { get; set; }

        /// <summary>
        /// 晚上的天氣預報圖片url
        /// </summary>
        public string nightPictureUrl { get; set; }

        /// <summary>
        /// 天氣狀況
        /// </summary>
        public string weather { get; set; }

        /// <summary>
        /// 風力
        /// </summary>
        public string wind { get; set; }

        /// <summary>
        /// 溫度
        /// </summary>
        public string temperature { get; set; }
    }

為了構建返回給客戶的圖文數(shù)據(jù),我們需要構建一個News對象,然后生成XML數(shù)據(jù)返回給服務器進行處理即可。

/// <summary>
        /// 響應用戶請求,并返回相應的XML數(shù)據(jù)
        /// </summary>
        /// <param name="info">微信基礎信息</param>
        /// <param name="location">地理位置:經(jīng)緯度坐標或者地名</param>
        /// <returns></returns>
        public string Response(BaseMessage info, string location)
        {
            string xml = "";

            //"廣州" 或者 "116.305145,39.982368"    
            if (!string.IsNullOrEmpty(location))
            {
                BaiduWeatherResult result = Execute(location, baiduAK);
                if (result != null && result.results.Count > 0)
                {
                    BaiduWeatherData data = result.results[0];
                    if (data != null)
                    {
                        ArticleEntity first = new ArticleEntity();
                        first.Title = string.Format("{0} 天氣預報", data.currentCity);

                        ResponseNews news = new ResponseNews(info);
                        news.Articles.Add(first);

                        int i = 0;
                        foreach (BaiduWeatherJson json in data.weather_data)
                        {
                            ArticleEntity article = new ArticleEntity();
                            article.Title = string.Format("{0}\n{1} {2} {3}", json.date, json.weather, json.wind, json.temperature);
                            if (i++ == 0)
                            {
                                article.PicUrl = IsDayTime() ? json.dayPictureUrl : json.nightPictureUrl;
                            }
                            else
                            {
                                article.PicUrl = json.dayPictureUrl;
                            }
                            news.Articles.Add(article);
                        }

                        xml = news.ToXml();
                    }
                }
            }

            return xml;
        }

這樣就很好實現(xiàn)了整體的功能了,具體界面功能可以訪問我的微信(廣州愛奇迪)進行了解,下面是功能截圖供參考。

C# develops WeChat portals and applications using geographical location to expand related applications? ?C# develops WeChat portals and applications using geographical location to expand related applications

C# develops WeChat portals and applications using geographical location to expand related applications?C# develops WeChat portals and applications using geographical location to expand related applications

C# develops WeChat portals and applications using geographical location to expand related applications

For more C# development of WeChat portals and applications using geographical location to expand related applications, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

<acronym id="kjlln"></acronym>
    • ParametersDescription
      ToUserName DeveloperWeChat ID
      Geolocation dimension
      Geolocation longitude
      <big id="kjlln"></big>