From 275e2b9dec977546dd1a3f75eac29c22e6bb4ed2 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 11 十一月 2022 09:10:52 +0800 Subject: [PATCH] 1 --- ExportMap/cs/ExportUtil.cs | 66 +++++++++++++++++++++ ExportMap/Sources/Template.qpt | 2 ExportMap/Controllers/ExportController.cs | 33 ++++++++-- ExportMap/ExportMap.csproj | 1 ExportMap/Models/ExportArgs.cs | 2 ExportMap/Test.html | 8 ++ ExportMap/Models/ResponseMsg.cs | 49 ++++++++++++++++ ExportMap/Sources/说明.txt | 1 ExportMap/Web.config | 2 9 files changed, 152 insertions(+), 12 deletions(-) diff --git a/ExportMap/Controllers/ExportController.cs b/ExportMap/Controllers/ExportController.cs index b7c6cc6..beeaf36 100644 --- a/ExportMap/Controllers/ExportController.cs +++ b/ExportMap/Controllers/ExportController.cs @@ -12,16 +12,35 @@ public class ExportController : ApiController { [HttpPost] - public string Start([FromBody]ExportArgs args) + public ResponseMsg<string> Start([FromBody]ExportArgs args) { - if (args == null || - string.IsNullOrWhiteSpace(args.layers)|| - (args.xmin == 0 && args.ymin == 0 && args.xmax == 0 && args.ymax == 0)) + try { - return null; - } + if (args == null || + string.IsNullOrWhiteSpace(args.layers) || + string.IsNullOrWhiteSpace(args.token) || + (args.xmin == 0 && args.ymin == 0 && args.xmax == 0 && args.ymax == 0)) + { + return ResponseMsg<string>.fail("鍙傛暟涓嶅畬鏁�"); + } - return ExportUtil.Generate(args); + if (!ExportUtil.VerifyToken(args.token)) + { + return ResponseMsg<string>.fail("浠ょ墝鏃犳晥"); + } + + string imgPath = ExportUtil.Generate(args); + if (string.IsNullOrEmpty(imgPath)) + { + return ResponseMsg<string>.fail("澶辫触"); + } + + return ResponseMsg<string>.success("鎴愬姛", imgPath); + } + catch (Exception ex) + { + return ResponseMsg<string>.fail(ex.Message); + } } } } diff --git a/ExportMap/ExportMap.csproj b/ExportMap/ExportMap.csproj index 12bd5dc..65ecf2e 100644 --- a/ExportMap/ExportMap.csproj +++ b/ExportMap/ExportMap.csproj @@ -131,6 +131,7 @@ </Compile> <Compile Include="Models\Decrypt.cs" /> <Compile Include="Models\ExportArgs.cs" /> + <Compile Include="Models\ResponseMsg.cs" /> <Compile Include="Models\Secret.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> diff --git a/ExportMap/Models/ExportArgs.cs b/ExportMap/Models/ExportArgs.cs index e0cb920..cbd4524 100644 --- a/ExportMap/Models/ExportArgs.cs +++ b/ExportMap/Models/ExportArgs.cs @@ -12,6 +12,8 @@ { public ExportArgs() { } + public String token { set; get; } + /// <summary> /// 鏍囬 /// </summary> diff --git a/ExportMap/Models/ResponseMsg.cs b/ExportMap/Models/ResponseMsg.cs new file mode 100644 index 0000000..258a277 --- /dev/null +++ b/ExportMap/Models/ResponseMsg.cs @@ -0,0 +1,49 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace LFServer.Models +{ + public class ResponseMsg<T> + { + public ResponseMsg() + { + time = DateTime.Now.Ticks; + } + + public ResponseMsg(int code) + : this() + { + this.code = code; + } + + public int code { set; get; } + + public String msg { set; get; } + + public long count { set; get; } + + public T result { set; get; } + + public long time { set; get; } + + public static ResponseMsg<T> success(String msg, T result, long count = 0) + { + ResponseMsg<T> rm = new ResponseMsg<T>(200); + rm.msg = msg; + rm.result = result; + rm.count = count; + + return rm; + } + + public static ResponseMsg<T> fail(String msg) + { + ResponseMsg<T> rm = new ResponseMsg<T>(500); + rm.msg = msg; + + return rm; + } + } +} diff --git a/ExportMap/Sources/Template.qpt b/ExportMap/Sources/Template.qpt index 26f3d68..ca3ad2c 100644 --- a/ExportMap/Sources/Template.qpt +++ b/ExportMap/Sources/Template.qpt @@ -92,7 +92,7 @@ <LabelFont style="甯歌" description="瀹嬩綋,14,-1,5,50,0,0,0,0,0,甯歌"/> <FontColor red="0" blue="0" green="0" alpha="255"/> </LayoutItem> - <LayoutItem svgFillColor="255,255,255,255" svgBorderColor="0,0,0,255" opacity="1" itemRotation="0" blendMode="0" frame="false" pictureHeight="10.7409" mapUuid="" templateUuid="{29298722-a58a-42f7-85d1-04564ad9366d}" outlineWidthM="0.3,mm" zValue="7" type="65640" background="false" frameJoinStyle="miter" mode="1" northOffset="0" resizeMode="0" size="11.6809,10.7409,mm" positionLock="true" anchorPoint="0" position="200.5,194.948,mm" referencePoint="0" northMode="0" uuid="{29298722-a58a-42f7-85d1-04564ad9366d}" visibility="1" excludeFromExports="0" groupUuid="" positionOnPage="200.5,194.948,mm" file="E:/terrait/TianJin/ExportMap/ExportMap/Sources/logo.png" pictureWidth="11.4207" id="Logo" pictureRotation="0" svgBorderWidth="0.2"> + <LayoutItem svgFillColor="255,255,255,255" svgBorderColor="0,0,0,255" opacity="1" itemRotation="0" blendMode="0" frame="false" pictureHeight="10.7409" mapUuid="" templateUuid="{29298722-a58a-42f7-85d1-04564ad9366d}" outlineWidthM="0.3,mm" zValue="7" type="65640" background="false" frameJoinStyle="miter" mode="1" northOffset="0" resizeMode="0" size="11.6809,10.7409,mm" positionLock="true" anchorPoint="0" position="200.5,194.948,mm" referencePoint="0" northMode="0" uuid="{29298722-a58a-42f7-85d1-04564ad9366d}" visibility="1" excludeFromExports="0" groupUuid="" positionOnPage="200.5,194.948,mm" file="{sourcesPath}\logo.png" pictureWidth="11.4207" id="Logo" pictureRotation="0" svgBorderWidth="0.2"> <FrameColor red="0" blue="0" green="0" alpha="255"/> <BackgroundColor red="255" blue="255" green="255" alpha="255"/> <LayoutObject> diff --git "a/ExportMap/Sources/\350\257\264\346\230\216.txt" "b/ExportMap/Sources/\350\257\264\346\230\216.txt" index 1961547..68c03b6 100644 --- "a/ExportMap/Sources/\350\257\264\346\230\216.txt" +++ "b/ExportMap/Sources/\350\257\264\346\230\216.txt" @@ -24,6 +24,7 @@ <Extent xmin="59.058299" ymin="9.565969" ymax="64.123674" xmax="146.815824"/> <Extent xmin="103.394023" ymin="30.690466" ymax="37.871048" xmax="112.534648"/> +浣嶇疆鍜屽ぇ灏忥細9锛�18 280,174 ================================================================================ 搴撶畝浠� 鏍煎紡鍖栵細ctrl + alt + l PyQGIS搴撶殑浜斾釜鍖咃細 diff --git a/ExportMap/Test.html b/ExportMap/Test.html index 8b274e7..9f0d353 100644 --- a/ExportMap/Test.html +++ b/ExportMap/Test.html @@ -5,6 +5,8 @@ <title></title> <script src="js/jquery.1.12.4.js"></script> <script> + var token = ""; + function ajax(url, type, data, dataType, contentType, fn) { $.ajax({ url: url, @@ -25,6 +27,7 @@ function exportMap1() { var page = $("#selectPage").find("option:selected").text(); var data = { + token: token, title: "绠¢亾鍩虹澶ф暟鎹钩鍙帮紙DW1-01锛�", pageSize: page, province: "娌冲寳鐪�", @@ -40,7 +43,7 @@ }; ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) { - alert(rs); + alert("code = " + rs.code + ", result = " + rs.result); console.log(rs); }); } @@ -48,6 +51,7 @@ function exportMap2() { var page = $("#selectPage").find("option:selected").text(); var data = { + token: token, title: "绠¢亾鍩虹澶ф暟鎹钩鍙帮紙DW1-02锛�", pageSize: page, province: "灞变笢鐪�", @@ -63,7 +67,7 @@ }; ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) { - alert(rs); + alert("code = " + rs.code + ", result = " + rs.result); console.log(rs); }); } diff --git a/ExportMap/Web.config b/ExportMap/Web.config index a6873e3..1693cea 100644 --- a/ExportMap/Web.config +++ b/ExportMap/Web.config @@ -2,7 +2,7 @@ <configuration> <appSettings> <!-- 192.168.20.39,127.0.0.1 --> - <add key="lfServer" value="http://127.0.0.1:12316/"/> + <add key="lfServer" value="http://127.0.0.1:12316"/> <add key="exportFolder" value="D:\LF\export"/> <add key="pgConn" value="Server=127.0.0.1;Port=5432;Database=langfang;User Id=postgres;Password=postgres;" /> <add key="webpages:Version" value="3.0.0.0" /> diff --git a/ExportMap/cs/ExportUtil.cs b/ExportMap/cs/ExportUtil.cs index 6fa1110..32bfe64 100644 --- a/ExportMap/cs/ExportUtil.cs +++ b/ExportMap/cs/ExportUtil.cs @@ -1,10 +1,13 @@ 锘縰sing LFServer.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.IO; using System.Linq; +using System.Net; +using System.Text; using System.Web; namespace LFServer.cs @@ -76,6 +79,17 @@ get { return ConfigurationManager.AppSettings["exportFolder"]; + } + } + + /// <summary> + /// 鍚庡彴鏈嶅姟鍦板潃 + /// </summary> + public static string LFServer + { + get + { + return ConfigurationManager.AppSettings["lfServer"]; } } @@ -188,7 +202,10 @@ File.Delete(qptFile); } - return args.imgPath; + string imgPath = Path.Combine(ExportFolder, args.imgPath); + bool flag = File.Exists(imgPath); + + return flag ? args.imgPath : null; } /// <summary> @@ -219,9 +236,56 @@ .Replace("{resolution}", args.resolution) .Replace("{date}", args.date) .Replace("{layers}", args.layers) + .Replace("{sourcesPath}", SourcesPath) .Replace("{imgPath}", imgPath); File.WriteAllText(qptFile, xml); } + + /// <summary> + /// 楠岃瘉浠ょ墝 + /// </summary> + /// <param name="token">浠ょ墝</param> + /// <returns>鏄�/鍚︽湁鏁�</returns> + public static bool VerifyToken(string token) + { + try + { + string json = GetData(LFServer + "/sign/check?token=" + token.Trim()); + if (string.IsNullOrWhiteSpace(json)) + { + return false; + } + + ResponseMsg<bool> rm = JsonConvert.DeserializeObject<ResponseMsg<bool>>(json); + + return rm != null && rm.code == 200 && rm.result; + } + catch (Exception ex) + { + return false; + } + } + + /// <summary> + /// Get鑾峰彇鏁版嵁 + /// </summary> + /// <param name="url">URL</param> + /// <returns>鏁版嵁</returns> + public static string GetData(string url) + { + + Uri uri = new Uri(url); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); + request.Method = "GET"; + request.ContentType = "application/x-www-form-urlencoded"; + + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); + string str = reader.ReadToEnd(); + reader.Close(); + + return str; + } } } -- Gitblit v1.9.3