Esempio n. 1
0
        public string ResponseText(WXReceiveTextMessage receiveMessage)
        {
            string result = "";

            if (receiveMessage.Content.StartsWith("103/002/"))
            {
                string[] arrFields = receiveMessage.Content.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (arrFields.Length == 12)
                {
                    string lat       = arrFields[3]; //当前位置纬度
                    string log       = arrFields[2]; //当前位置经度
                    string mapAPIKey = "00001";
                    if (!string.IsNullOrEmpty(GlobalManager.TheServiceAccount.MapAPI))
                    {
                        if (GlobalManager.TheMapAPIOfInverseAdressParse.ContainsKey(GlobalManager.TheServiceAccount.MapAPI))
                        {
                            mapAPIKey = GlobalManager.TheServiceAccount.MapAPI;
                        }
                    }
                    string antiGeocodingUrl = GlobalManager.TheMapAPIOfInverseAdressParse[mapAPIKey].ReplaceWithKeys(new { lat = lat, log = log }.ToStringObjectDictionary());


                    HttpAdapter.apiJ(antiGeocodingUrl, (ret, res) =>
                    {
                        if (ret.status == 0)
                        {
                            string detailAddress = ret.result.address;
                            if (mapAPIKey == "00002")
                            {
                                detailAddress = string.IsNullOrEmpty(ret.result.street_number) ? ret.result.formatted_address + "附近" : ret.result.formatted_address;
                            }
                            result = XmlSerializeAdapter.Serialize <WXResponseTextMessage>(new WXResponseTextMessage {
                                ToUserName = receiveMessage.FromUserName, FromUserName = receiveMessage.ToUserName, CreateTime = DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), MsgType = "text", Content = detailAddress
                            }, true);
                            //result = string.Format("<xml><ToUserName>{0}</ToUserName><FromUserName>{1}</FromUserName><CreateTime>{2}</CreateTime><MsgType>text</MsgType><Content>{3}</Content></xml>", requestMessage.FromUserName, requestMessage.ToUserName, DateTimeAdapter.ConvertDateTimeUnix(DateTime.Now), detailAddress);
                        }
                    });
                }
            }
            //else
            //{
            //    result = FormatOutputText(receiveMessage.FromUserName, receiveMessage.ToUserName, "/:coffee");
            //}
            return(result);
        }