分类:
ABP
依赖包
using Abp.Authorization; using Abp.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.IO; using System.Net; using System.Text; using ZZY.Finance.Maps.Dto;
具体代码
/// <summary> /// 地图应用服务层 /// </summary> [AbpAuthorize] public class MapAppService : FinanceAppServiceBase, IMapAppService { /// <summary> /// 依赖注入 /// </summary> public MapAppService() { } /// <summary> /// 行政区域查询 /// </summary> /// <returns></returns> public JObject GetDistrict(DistrictQueryDto Query) { try { //AppConsts.GeoKeys:个人的key var Url = "https://restapi.amap.com/v3/config/district?key=" + AppConsts.GeoKeys; if (!string.IsNullOrEmpty(Query.Keywords)) { Url += "&keywords=" + Query.Keywords; } if (!string.IsNullOrEmpty(Query.Filter)) { Url += "&filter=" + Query.Filter; } //有缺省值的不用判断 Url += "&subdistrict=" + Query.SubDistrict; Url += "&page=" + Query.Page; Url += "&offset=" + Query.Offset; Url += "&extensions=" + Query.Extensions; var Result = GetFunction(Url); //json反序列化 JObject JoResult = (JObject)JsonConvert.DeserializeObject(Result); return JoResult; } catch { throw new UserFriendlyException("系统提示:获取行政区域失败!"); } } /// <summary> /// 调用接口-GET方法 /// </summary> /// <param name="Url"></param> /// <returns></returns> protected static string GetFunction(string Url) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8); string retString = myStreamReader.ReadToEnd(); return retString; } }
评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术