Explorar el Código

基于AutoUpdateSample新增app版本控制接口

linhong hace 3 años
padre
commit
495af2c29e

+ 6 - 4
Controllers/L1SvrController.cs

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
 using Newtonsoft.Json;
 using System.IO;
 using System.Text;
+using Newtonsoft.Json.Linq;
 
 namespace LJProxy.Controllers
 {
@@ -77,23 +78,24 @@ namespace LJProxy.Controllers
             return rslt;
         }
 
-        [Route("CRP/{apiName}")]
+        [Route("CRP/{apiName}/{**restPath}")]
         [HttpPost]
         [HttpGet]
         public async Task<IActionResult> CRP(string apiName)
-        {
+        { 
             string requestBody;
             using(StreamReader reader = new StreamReader(Request.Body,Encoding.UTF8))
             {
                 requestBody = await reader.ReadToEndAsync();
             }
             var excuteResult = GlobalVar.Excute(apiName, requestBody, Request);
-            if (excuteResult.Item1) return Json( excuteResult.Item2);
+            if (excuteResult.Item1) return excuteResult.Item2;
             else
             {
                 var rslt = CRPPool.DoExcute(apiName, requestBody);
-                return Json( rslt);
+                return Content(rslt,"application/json");
             }
         }
+
     }
 }

+ 11 - 8
Excutor/CheckUpdateExcutor.cs

@@ -5,26 +5,28 @@ using System.Collections.Generic;
 using System.Linq;
 using System.IO;
 using LJLib;
+using Microsoft.AspNetCore.Mvc;
 
 namespace LJProxy.Excutor
 {
-    public class CheckUpdateExcutor : ExcutorBase<CheckUpdateRequest, CheckUpdateResponse>
+    public class CheckUpdateExcutor : ExcutorBase<CheckUpdateRequest>
     {
         private static object _syncRoot = new object();
-        protected override void ExcuteInternal(CheckUpdateRequest request, object state, CheckUpdateResponse rslt)
+        protected override IActionResult ExcuteInternal(CheckUpdateRequest request, object state)
         {
+            CheckUpdateResponse rslt = new CheckUpdateResponse();
             rslt.ErrCode = "0";
             if (string.IsNullOrEmpty(request.CurrentVersion))
             {
                 rslt.ErrMsg = "CurrentVersion can not be empty";
-                return;
+                return new JsonResult(rslt);
             }
 
             var apkDirs =@$"{AppDomain.CurrentDomain.BaseDirectory}apk\";
             if (!Directory.Exists(apkDirs))
             {
                 rslt.ErrMsg = "apk file folder not exists";
-                return;
+                return new JsonResult(rslt);
             }
 
             //cache file version
@@ -32,7 +34,7 @@ namespace LJProxy.Excutor
             string cacheKey = "NewestApkVersion";
             lock (_syncRoot)
             {
-                newVersion = CacheHelper.DefaultCache.Get(cacheKey) as string;
+                newVersion = Cache.DefaultCache.Get(cacheKey) as string;
                 if (string.IsNullOrEmpty(newVersion))
                 {
                     var dirinfo = new DirectoryInfo(apkDirs);
@@ -42,13 +44,13 @@ namespace LJProxy.Excutor
                     if (file == null)
                     {
                         rslt.ErrMsg = "can not found apk";
-                        return;
+                        return new JsonResult(rslt);
                     }
 
                     APKHelper apkHelper = new APKHelper();
                     newVersion = apkHelper.GetVersionName(file.FullName);
                     //TODO:文件夹缓存依赖不生效,待扩展
-                    CacheHelper.DefaultCache.Add(cacheKey, newVersion, CacheHelper.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
+                    Cache.DefaultCache.Add(cacheKey, newVersion, Cache.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
                 }
             }
 
@@ -57,7 +59,8 @@ namespace LJProxy.Excutor
                 rslt.ErrCode = "1";
                 rslt.NewVersion = newVersion;
             }
-
+            return new JsonResult(rslt);
         }
+
     }
 }

+ 41 - 0
Excutor/GetAppUpdateExcutor.cs

@@ -0,0 +1,41 @@
+using LJProxy.LJLib.Net.SPI.Server;
+using LJProxy.Models;
+using LJProxy.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace LJProxy.Excutor
+{
+    public class GetAppUpdateExcutor : ExcutorBase<GetAppUpdateRequest>
+    {
+        VersionService _service = new VersionService();
+        protected override IActionResult ExcuteInternal(GetAppUpdateRequest request, object state)
+        {
+            HttpRequest httpRequest = state as HttpRequest;
+            Regex regx = new Regex(@"GetAppUpdate/(?<apkName>.*?\.apk)", RegexOptions.IgnoreCase);
+            var matchResult=regx.Match(httpRequest.Path.ToString());
+            if (matchResult.Success)
+            {
+                var apkName = matchResult.Groups["apkName"]?.Value;
+                var fs = _service.GetAPK(apkName);
+                if (fs==null)
+                {
+                    return new NotFoundResult();
+                }
+                else
+                {
+                    return new FileContentResult(fs, "application/vnd.android.package-archive");
+                }
+            }
+            else
+            {
+                return new NotFoundResult();
+            }
+        }
+    }
+}

+ 6 - 3
Excutor/GetProxyDomainListExcutor.cs

@@ -1,5 +1,6 @@
 using LJProxy.LJLib.Net.SPI.Server;
 using LJProxy.Models;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -7,16 +8,18 @@ using System.Threading.Tasks;
 
 namespace LJProxy.Excutor
 {
-    public class GetProxyDomainListExcutor : ExcutorBase<GetProxyDomainListRequest, GetProxyDomainListResponse>
+    public class GetProxyDomainListExcutor : ExcutorBase<GetProxyDomainListRequest>
     {
-        protected override void ExcuteInternal(GetProxyDomainListRequest request, object state, GetProxyDomainListResponse rslt)
+        protected override IActionResult ExcuteInternal(GetProxyDomainListRequest request, object state)
         {
+            GetProxyDomainListResponse rslt = new GetProxyDomainListResponse();
             rslt.ErrMsg = "";
             //TODO:get domain list from config file?
             rslt.DomainList = new List<string>() {
                 "192.168.0.94","192.168.0"
             };
-
+            return new JsonResult(rslt);
         }
+        
     }
 }

+ 25 - 0
Excutor/GetUpdateJsonExcutor.cs

@@ -0,0 +1,25 @@
+using LJProxy.LJLib.Net.SPI.Server;
+using LJProxy.Models;
+using LJProxy.Services;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LJProxy.Excutor
+{
+    public class GetUpdateJsonExcutor : ExcutorBase<GetUpdateJsonRequest>
+    {
+        VersionService _service = new VersionService();
+        protected override IActionResult ExcuteInternal(GetUpdateJsonRequest request, object state)
+        {
+            string updateJson = _service.GetUpdateJson();
+            var result = new ContentResult();
+            result.Content = updateJson;
+            result.ContentType = "application/json";
+            return result;
+        }
+    }
+}

+ 18 - 13
Excutor/GetUpdatePkgExcutor.cs

@@ -1,6 +1,9 @@
 using LJLib;
+using LJLib.Net.SPI.Com;
+using LJLib.Tools.Encry;
 using LJProxy.LJLib.Net.SPI.Server;
 using LJProxy.Models;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -9,26 +12,29 @@ using System.Threading.Tasks;
 
 namespace LJProxy.Excutor
 {
-    public class GetUpdatePkgExcutor : ExcutorBase<GetUpdatePkgRequest, GetUpdatePkgResponse>
+    public class GetUpdatePkgExcutor : ExcutorBase<GetUpdatePkgRequest>
     {
         private static object _syncRoot = new object();
-        protected override void ExcuteInternal(GetUpdatePkgRequest request, object state, GetUpdatePkgResponse rslt)
+
+
+        protected override IActionResult ExcuteInternal(GetUpdatePkgRequest request, object state)
         {
+            GetUpdatePkgResponse rslt = new GetUpdatePkgResponse();
             rslt.ErrCode = "0";
 
             var apkDirs = @$"{AppDomain.CurrentDomain.BaseDirectory}apk\";
             if (!Directory.Exists(apkDirs))
             {
                 rslt.ErrMsg = "apk file folder not exists";
-                return;
+                return new JsonResult(rslt);
             }
 
             //cache file version
-            ApkInfo apkInfo = null;
+            GetUpdatePkgResponse apkInfo = null;
             string cacheKey = "NewestApkData";
             lock (_syncRoot)
             {
-                apkInfo = CacheHelper.DefaultCache.Get(cacheKey) as ApkInfo;
+                apkInfo = Cache.DefaultCache.Get(cacheKey) as GetUpdatePkgResponse;
                 if (apkInfo == null)
                 {
                     var dirinfo = new DirectoryInfo(apkDirs);
@@ -38,7 +44,7 @@ namespace LJProxy.Excutor
                     if (file == null)
                     {
                         rslt.ErrMsg = "can not found apk";
-                        return;
+                        return new JsonResult(rslt);
                     }
 
                     byte[] apkData = null;
@@ -58,23 +64,22 @@ namespace LJProxy.Excutor
                     }
 
                     APKHelper apkHelper = new APKHelper();
+                    var md5Helper = new MD5();
                     var clientVer = apkHelper.GetVersionName(apkData);
-                    apkInfo = new ApkInfo();
+                    apkInfo = new GetUpdatePkgResponse();
                     apkInfo.Version = clientVer;
                     apkInfo.ApkData = apkData;
+                    apkInfo.Checksum = md5Helper.GetMD5(apkData);
                     //TODO:文件夹缓存依赖不生效,待扩展
-                    CacheHelper.DefaultCache.Add(cacheKey, apkInfo, CacheHelper.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
+                    Cache.DefaultCache.Add(cacheKey, apkInfo, Cache.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { file.FullName }));
                 }
             }
 
             rslt.Version = apkInfo.Version;
             rslt.ApkData = apkInfo.ApkData;
+            rslt.Checksum = apkInfo.Checksum;
+            return new JsonResult(rslt);
         }
 
-        public class ApkInfo
-        {
-            public string Version { get; set; }
-            public byte[] ApkData { get; set; }
-        }
     }
 }

+ 4 - 4
GlobalVar/CacheHelper.cs

@@ -6,7 +6,7 @@ using System.Runtime.Caching;
 
 namespace LJProxy
 {
-    public static class CacheHelper
+    public static class Cache
     {
         public static MemoryCache DefaultCache
         {
@@ -16,12 +16,12 @@ namespace LJProxy
             }
         }
 
-        private static MemoryCache _imgCache = new MemoryCache("ImgCache");
-        public static MemoryCache ImgCache
+        private static MemoryCache _fileCache = new MemoryCache("FileCache");
+        public static MemoryCache FileCache
         {
             get
             {
-                return _imgCache;
+                return _fileCache;
             }
         }
 

+ 6 - 3
GlobalVar/GlobalVar.cs

@@ -7,6 +7,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using Newtonsoft.Json.Linq;
+using Microsoft.AspNetCore.Mvc;
 
 namespace LJProxy
 {
@@ -25,17 +26,19 @@ namespace LJProxy
             excutorManager.AddMap(new CheckUpdateRequest().GetApiName(), typeof(CheckUpdateRequest), new CheckUpdateExcutor());
             excutorManager.AddMap(new GetUpdatePkgRequest().GetApiName(), typeof(GetUpdatePkgRequest), new GetUpdatePkgExcutor());
             excutorManager.AddMap(new GetProxyDomainListRequest().GetApiName(), typeof(GetProxyDomainListRequest), new GetProxyDomainListExcutor());
+            excutorManager.AddMap(new GetUpdateJsonRequest().GetApiName(), typeof(GetUpdateJsonRequest), new GetUpdateJsonExcutor());
+            excutorManager.AddMap(new GetAppUpdateRequest().GetApiName(), typeof(GetAppUpdateRequest), new GetAppUpdateExcutor());
         }
 
-        public static Tuple<bool,LJResponse> Excute(string apiName,string requestBody,object requestState)
+        public static Tuple<bool,IActionResult> Excute(string apiName,string requestBody,object requestState)
         {
             var requestType = excutorManager.GetRequestType(apiName);
-            if (requestType == null) return new Tuple<bool, LJResponse>(false, null);
+            if (requestType == null) return new Tuple<bool, IActionResult>(false, null);
             ILJRequest request = null;
             if(!string.IsNullOrEmpty(requestBody)) request = JObject.Parse(requestBody).ToObject(requestType) as ILJRequest;
             else request = new JObject().ToObject(requestType) as ILJRequest;
             var result = excutorManager.DoExcute( request, requestState);
-            return new Tuple<bool, LJResponse>(true, result);
+            return new Tuple<bool, IActionResult>(true, result);
         }
     }
 }

+ 1 - 1
LJLib.Net.SPI.Com/ILJRequest.cs

@@ -6,7 +6,7 @@ namespace LJLib.Net.SPI.Com
         string GetApiName();
     }
 
-    public abstract class LJRequest<T> : ILJRequest where T : LJResponse
+    public abstract class LJRequest: ILJRequest 
     {
         public string GetApiName()
         {

+ 10 - 16
LJLib.Net.SPI.Server/ExcutorBase.cs

@@ -1,4 +1,5 @@
 using LJLib.Net.SPI.Com;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -8,28 +9,21 @@ namespace LJProxy.LJLib.Net.SPI.Server
 {
     public abstract class ExcutorBase
     {
-        public abstract LJResponse Excute(ILJRequest request,object state);
+        public abstract IActionResult Excute(ILJRequest request,object state);
     }
 
-    public abstract class ExcutorBase<T1,T2>:ExcutorBase where T1: LJRequest<T2> where T2:LJResponse,new()
+    public abstract class ExcutorBase<T1>:ExcutorBase where T1: class,ILJRequest
     {
-        protected abstract void ExcuteInternal(T1 request, object state, T2 rslt);
-        public override LJResponse Excute(ILJRequest request, object state)
+        protected abstract IActionResult ExcuteInternal(T1 request, object state);
+        public override IActionResult Excute(ILJRequest request, object state)
         {
-            T2 rslt = new T2();
-            try
+            T1 req = request as T1;
+            if (req == null)
             {
-                T1 req = request as T1;
-                if(req == null)
-                {
-                    rslt.ErrMsg = string.Format("request 不能转换成类型[{0}]",typeof(T1).Name);
-                    return rslt;
-                }
-                ExcuteInternal(req, state, rslt);
-            }catch(Exception e)
-            {
-                rslt.ErrMsg = e.Message.ToString();
+                ErrResponse err = new ErrResponse(string.Format("request 不能转换成类型[{0}]", typeof(T1).Name));
+                return new JsonResult(err);
             }
+            var rslt = ExcuteInternal(req, state);
             return rslt;
         }
     }

+ 0 - 14
LJLib.Net.SPI.Server/ILJServer.cs

@@ -1,14 +0,0 @@
-using LJLib.Net.SPI.Com;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace LJProxy.LJLib.Net.SPI.Server
-{
-    public interface ILJServer
-    {
-        LJResponse DoExcute(ILJRequest request, object state);
-        Type GetRequestType(string apiName);
-    }
-}

+ 4 - 3
LJLib.Net.SPI.Server/LJServerBase.cs

@@ -1,4 +1,5 @@
 using LJLib.Net.SPI.Com;
+using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -6,13 +7,13 @@ using System.Threading.Tasks;
 
 namespace LJProxy.LJLib.Net.SPI.Server
 {
-    public abstract class LJServerBase : ILJServer
+    public abstract class LJServerBase
     {
-        public delegate LJResponse DHandle(ILJRequest request, object state);
+        public delegate IActionResult DHandle(ILJRequest request, object state);
         protected Dictionary<string, DHandle> handlers = new Dictionary<string, DHandle>(StringComparer.OrdinalIgnoreCase);
         protected Dictionary<string, Type> requestTypes = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
 
-        public LJResponse DoExcute(ILJRequest request, object state)
+        public IActionResult DoExcute(ILJRequest request, object state)
         {
             if (!handlers.ContainsKey(request.GetApiName()))
             {

+ 4 - 0
LJProxy.csproj

@@ -16,5 +16,9 @@
     <PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
   </ItemGroup>
 
+  <ItemGroup>
+    <Folder Include="apk\" />
+  </ItemGroup>
+
 
 </Project>

+ 1 - 1
LJProxy.csproj.user

@@ -4,6 +4,6 @@
     <Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
     <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
     <ShowAllFiles>false</ShowAllFiles>
-    <NameOfLastUsedPublishProfile>D:\ImportantData\Develop\ProjectCode\LJProxy\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
+    <NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
   </PropertyGroup>
 </Project>

+ 1 - 1
Models/CheckUpdate.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace LJProxy.Models
 {
-    public class CheckUpdateRequest : LJRequest<CheckUpdateResponse>
+    public class CheckUpdateRequest : LJRequest
     {
         public string CurrentVersion { get; set; }
     }

+ 12 - 0
Models/GetAppUpdate.cs

@@ -0,0 +1,12 @@
+using LJLib.Net.SPI.Com;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy.Models
+{
+    public class GetAppUpdateRequest: LJRequest
+    {
+    }
+}

+ 1 - 1
Models/GetProxyDomainList.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace LJProxy.Models
 {
-    public class GetProxyDomainListRequest : LJRequest<GetProxyDomainListResponse>
+    public class GetProxyDomainListRequest : LJRequest
     {
         
     }

+ 13 - 0
Models/GetUpdateJson.cs

@@ -0,0 +1,13 @@
+using LJLib.Net.SPI.Com;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy.Models
+{
+    public class GetUpdateJsonRequest: LJRequest
+    {
+    }
+
+}

+ 2 - 1
Models/GetUpdatePkg.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace LJProxy.Models
 {
-    public class GetUpdatePkgRequest : LJRequest<GetUpdatePkgResponse>
+    public class GetUpdatePkgRequest : LJRequest
     {
         
     }
@@ -15,5 +15,6 @@ namespace LJProxy.Models
     {
         public string Version { get; set; }
         public byte[] ApkData { get; set; }
+        public string Checksum { get; set; }
     }
 }

+ 2 - 2
Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
 -->
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <_PublishTargetUrl>D:\ImportantData\Develop\ProjectCode\LJProxy\bin\Release\netcoreapp3.1\publish\</_PublishTargetUrl>
-    <History>True|2021-08-16T06:51:54.8412175Z;True|2021-08-16T11:30:00.7278175+08:00;</History>
+    <_PublishTargetUrl>F:\projects\LJProxy\bin\Release\netcoreapp3.1\publish\</_PublishTargetUrl>
+    <History>True|2021-09-05T02:02:29.7646709Z;True|2021-09-04T22:32:42.5817800+08:00;True|2021-08-16T14:51:54.8412175+08:00;True|2021-08-16T11:30:00.7278175+08:00;</History>
   </PropertyGroup>
 </Project>

+ 1 - 1
Properties/launchSettings.json

@@ -4,7 +4,7 @@
     "anonymousAuthentication": true,
     "iisExpress": {
       "applicationUrl": "http://127.0.0.1:58966",
-      "sslPort": 0
+      "sslPort": 44358
     }
   },
   "$schema": "http://json.schemastore.org/launchsettings.json",

+ 11 - 0
Services/ServiceBase.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace LJProxy.Services
+{
+    public abstract class ServiceBase
+    {
+    }
+}

+ 71 - 0
Services/VersionService.cs

@@ -0,0 +1,71 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace LJProxy.Services
+{
+    public class VersionService:ServiceBase
+    {
+        private static object _updateJsonSyncRoot = new object();
+        private static object _apkSyncRoot = new object();
+
+        public string GetUpdateJson()
+        {
+            string updateJson = string.Empty;
+            string key = "UpdateJson";
+            lock (_updateJsonSyncRoot)
+            {
+                updateJson = Cache.DefaultCache.Get(key) as string;
+                if (string.IsNullOrEmpty(updateJson))
+                {
+                    string updateJsonPath = @$"{AppDomain.CurrentDomain.BaseDirectory}apk\update.json";
+                    updateJson = System.IO.File.ReadAllText(updateJsonPath, Encoding.UTF8);
+                    Cache.DefaultCache.Add(key, updateJson, Cache.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { updateJsonPath }));
+                }
+            }
+            return updateJson;
+        }
+
+
+        public byte[] GetAPK(string apkName)
+        {
+            if (string.IsNullOrEmpty(apkName)) return null;
+            var updateJson = GetUpdateJson();
+            var updateInfoObj = JObject.Parse(updateJson);
+            string url = updateInfoObj["url"]?.ToString();
+            if (string.IsNullOrEmpty(url))
+            {
+                return null;
+            }
+            Regex regx = new Regex(@"GetAppUpdate/(?<apkName>.*?\.apk)", RegexOptions.IgnoreCase);
+            var matchResult = regx.Match(url);
+            if (matchResult.Success)
+            {
+                var jsonApkName = matchResult.Groups["apkName"]?.Value;
+                if (!apkName.Equals(jsonApkName, StringComparison.OrdinalIgnoreCase)) return null;
+                string key = apkName.ToLower();
+                byte[] result = null;
+                lock (_apkSyncRoot)
+                {
+                    result = Cache.DefaultCache.Get(key) as byte[];
+                    if (result == null)
+                    {
+                        string apkFilePath = @$"{AppDomain.CurrentDomain.BaseDirectory}apk\{apkName}";
+                        if (!System.IO.File.Exists(apkFilePath))
+                        {
+                            return null;
+                        }
+                        result = System.IO.File.ReadAllBytes(apkFilePath);
+                        Cache.DefaultCache.Add(key, result, Cache.CreateCacheItemPolicy(null, DateTime.Now.AddMinutes(30), new List<string>() { apkFilePath }));
+                    }
+                }
+                return result;
+            }
+            return null;
+        }
+    }
+}

+ 1 - 1
Startup.cs

@@ -27,7 +27,7 @@ namespace LJProxy
         public void ConfigureServices(IServiceCollection services)
         {
             services.AddControllers().AddNewtonsoftJson(opt => {
-                opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
+                //opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
             });
             services.Configure<AppSettings>(Configuration.GetSection("Appsettings"));
         }

+ 64 - 0
Utilities/MD5.cs

@@ -0,0 +1,64 @@
+using System;
+using System.IO;
+
+namespace LJLib.Tools.Encry
+{
+    public class MD5
+    {
+        public byte[] ComputeHash(byte[] bytes)
+        {
+            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
+            {
+                return md5.ComputeHash(bytes);
+            }
+        }
+
+        public byte[] ComputeHash(byte[] bytes, int offset, int count)
+        {
+            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
+            {
+                return md5.ComputeHash(bytes, offset, count);
+            }
+        }
+
+        public byte[] ComputeHash(System.IO.Stream inputStream)
+        {
+            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
+            {
+                return md5.ComputeHash(inputStream);
+            }
+        }
+
+        public string GetMD5(byte[] bytes)
+        {
+                byte[] rslt = this.ComputeHash(bytes);
+                string str_rslt = BitConverter.ToString(rslt);
+                str_rslt = str_rslt.Replace("-", "");
+                return str_rslt;
+        }
+
+        public string GetMD5(byte[] bytes, int offset, int count)
+        {
+                byte[] rslt = this.ComputeHash(bytes, offset, count);
+                string str_rslt = BitConverter.ToString(rslt);
+                str_rslt = str_rslt.Replace("-", "");
+                return str_rslt;
+        }
+
+        public string GetMD5(System.IO.Stream inputStream)
+        {
+            byte[] rslt = this.ComputeHash(inputStream);
+            string str_rslt = BitConverter.ToString(rslt);
+            str_rslt = str_rslt.Replace("-", "");
+            return str_rslt;
+        }
+
+        public string GetMD5(string filename)
+        {
+            using (var fs = System.IO.File.OpenRead(filename))
+            {
+                return GetMD5(fs);
+            }
+        }
+    }
+}

+ 5 - 0
apk/update.json

@@ -0,0 +1,5 @@
+{
+  "url":"http://127.0.0.1:58966/api/l1svr/crp/GetAppUpdate/android-auto-update-v1.3.apk",
+  "versionCode":4,
+  "updateMessage":"1. 适配 Android 8.0\n2. 适配 Android 9.0\n3. 更新说明"
+}