lqq il y a 8 ans
Parent
commit
608a3f08a4

+ 44 - 0
Winsoft.GOV.XF.SPA.WXCore/Controllers/ValuesController.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Winsoft.GOV.XF.SPA.WXCore.Controllers
+{
+    [Route("api/[controller]")]
+    public class ValuesController : Controller
+    {
+        // GET api/values
+        [HttpGet]
+        public IEnumerable<string> Get()
+        {
+            return new string[] { "value1", "value2" };
+        }
+
+        // GET api/values/5
+        [HttpGet("{id}")]
+        public string Get(int id)
+        {
+            return "value";
+        }
+
+        // POST api/values
+        [HttpPost]
+        public void Post([FromBody]string value)
+        {
+        }
+
+        // PUT api/values/5
+        [HttpPut("{id}")]
+        public void Put(int id, [FromBody]string value)
+        {
+        }
+
+        // DELETE api/values/5
+        [HttpDelete("{id}")]
+        public void Delete(int id)
+        {
+        }
+    }
+}

+ 26 - 0
Winsoft.GOV.XF.SPA.WXCore/Program.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+
+namespace Winsoft.GOV.XF.SPA.WXCore
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            var host = new WebHostBuilder()
+                .UseKestrel()
+                .UseContentRoot(Directory.GetCurrentDirectory())
+                .UseIISIntegration()
+                .UseStartup<Startup>()
+                .UseApplicationInsights()
+                .Build();
+
+            host.Run();
+        }
+    }
+}

+ 29 - 0
Winsoft.GOV.XF.SPA.WXCore/Properties/launchSettings.json

@@ -0,0 +1,29 @@
+{
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:58794/",
+      "sslPort": 0
+    }
+  },
+  "profiles": {
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "launchUrl": "api/values",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "Winsoft.GOV.XF.SPA.WXCore": {
+      "commandName": "Project",
+      "launchBrowser": true,
+      "launchUrl": "api/values",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      },
+      "applicationUrl": "http://localhost:58795/"
+    }
+  }
+}

+ 43 - 0
Winsoft.GOV.XF.SPA.WXCore/Startup.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace Winsoft.GOV.XF.SPA.WXCore
+{
+    public class Startup
+    {
+        public Startup(IHostingEnvironment env)
+        {
+            var builder = new ConfigurationBuilder()
+                .SetBasePath(env.ContentRootPath)
+                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
+                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
+                .AddEnvironmentVariables();
+            Configuration = builder.Build();
+        }
+
+        public IConfigurationRoot Configuration { get; }
+
+        // This method gets called by the runtime. Use this method to add services to the container.
+        public void ConfigureServices(IServiceCollection services)
+        {
+            // Add framework services.
+            services.AddMvc();
+        }
+
+        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
+        {
+            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
+            loggerFactory.AddDebug();
+
+            app.UseMvc();
+        }
+    }
+}

+ 22 - 0
Winsoft.GOV.XF.SPA.WXCore/Winsoft.GOV.XF.SPA.WXCore.csproj

@@ -0,0 +1,22 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp1.1</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Folder Include="wwwroot\" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
+    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
+    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
+    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
+  </ItemGroup>
+
+</Project>

+ 10 - 0
Winsoft.GOV.XF.SPA.WXCore/appsettings.Development.json

@@ -0,0 +1,10 @@
+{
+  "Logging": {
+    "IncludeScopes": false,
+    "LogLevel": {
+      "Default": "Debug",
+      "System": "Information",
+      "Microsoft": "Information"
+    }
+  }
+}

+ 8 - 0
Winsoft.GOV.XF.SPA.WXCore/appsettings.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "IncludeScopes": false,
+    "LogLevel": {
+      "Default": "Warning"
+    }
+  }
+}

+ 8 - 7
Winsoft.GOV.XF.WebApi.ManagerCore/Winsoft.GOV.XF.WebApi.ManagerCore/Controllers/AuthorizationController.cs

@@ -1,4 +1,4 @@
-// ======================================
+// ======================================
 // Author: Ebenezer Monney
 // Email:  info@ebenmonney.com
 // Copyright (c) 2017 www.ebenmonney.com
@@ -54,13 +54,14 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
         {
             if (request.IsPasswordGrantType())
             {
+                //用户是否存在
                 var user = await _userManager.FindByEmailAsync(request.Username) ?? await _userManager.FindByNameAsync(request.Username);
                 if (user == null)
                 {
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "Please check that your email and password is correct"
+                        ErrorDescription = "请检查您的用户名和密码"
                     });
                 }
 
@@ -70,7 +71,7 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "The specified user is not allowed to sign in"
+                        ErrorDescription = "该账号不允许登录"
                     });
                 }
 
@@ -80,7 +81,7 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "The specified user is not allowed to sign in"
+                        ErrorDescription = "该账号不允许登录"
                     });
                 }
 
@@ -90,7 +91,7 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "The specified user account has been suspended"
+                        ErrorDescription = "该账号已经被挂起"
                     });
                 }
 
@@ -100,7 +101,7 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "The specified user account is disabled"
+                        ErrorDescription = "该账号不可用"
                     });
                 }
 
@@ -115,7 +116,7 @@ namespace Winsoft.GOV.XF.WebApi.ManagerCore.Controllers
                     return BadRequest(new OpenIdConnectResponse
                     {
                         Error = OpenIdConnectConstants.Errors.InvalidGrant,
-                        ErrorDescription = "Please check that your email and password is correct"
+                        ErrorDescription = "请检查您的用户名和密码"
                     });
                 }
 

+ 7 - 42
Winsoft.GOV.XF.WebApi.WXCore/Controllers/ValuesController.cs

@@ -1,37 +1,27 @@
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Mvc;
-using Winsoft.GOV.XF.WebApi.WXCore.Filters;
 using Senparc.Weixin.MP.AdvancedAPIs;
 using Senparc.Weixin;
-using Microsoft.AspNetCore.Session;
 using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Options;
 using Senparc.Weixin.Entities;
-using Senparc.Weixin.MP.CoreMvcExtension;
+using Microsoft.Extensions.Options;
+
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
 
 namespace Winsoft.GOV.XF.WebApi.WXCore.Controllers
 {
     [Route("api/[controller]")]
-    public class ValuesController : BaseController
+    public class AuthController :  BaseController
     {
-        public ValuesController(IOptions<SenparcWeixinSetting> senparcWeixinSetting) : base(senparcWeixinSetting)
+        public AuthController(IOptions<SenparcWeixinSetting> senparcWeixinSetting) : base(senparcWeixinSetting)
         {
         }
 
-        // GET api/values
         [HttpGet]
-        [WeixinInternalRequest("访问被拒绝,请通过微信客户端访问!", "nofilter")]
-        [WXOAuth(appId: null, oauthCallbackUrl: "/api/values/OAuthCallback")]
-        public string Get()
-        {
-            return HttpContext.Session.GetString("OpenId");
-        }
-
-        [HttpGet("OAuthCallback")]
-        public ActionResult OAuthCallback(string code, string state, string returnUrl)
+        public ActionResult Get(string code, string state, string returnUrl)
         {
             if (string.IsNullOrEmpty(code))
             {
@@ -63,30 +53,5 @@ namespace Winsoft.GOV.XF.WebApi.WXCore.Controllers
                 return Content("错误:" + e.Message);
             }
         }
-
-        // GET api/values/5
-        [HttpGet("{id}")]
-        public string Get(int id)
-        {
-            return "value";
-        }
-
-        // POST api/values
-        [HttpPost]
-        public void Post([FromBody]string value)
-        {
-        }
-
-        // PUT api/values/5
-        [HttpPut("{id}")]
-        public void Put(int id, [FromBody]string value)
-        {
-        }
-
-        // DELETE api/values/5
-        [HttpDelete("{id}")]
-        public void Delete(int id)
-        {
-        }
     }
 }

+ 74 - 0
Winsoft.GOV.XF.WebApi.WXCore/Controllers/UserController.cs

@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Winsoft.GOV.XF.WebApi.WXCore.Models;
+using Senparc.Weixin.MP.CoreMvcExtension;
+using Winsoft.GOV.XF.WebApi.WXCore.Filters;
+using Microsoft.Extensions.Options;
+using Senparc.Weixin.Entities;
+using Winsoft.GOV.XF.WebApi.WXCore.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Controllers
+{
+    [Produces("application/json")]
+    [Route("api/User")]
+    public class UserController : BaseController
+    {
+        XFContext _context;
+        ILogger _logger;
+        public UserController(IOptions<SenparcWeixinSetting> senparcWeixinSetting, XFContext context, ILogger<UserController> logger) : base(senparcWeixinSetting)
+        {
+            _context = context;
+            _logger = logger;
+        }
+
+        [HttpGet]
+        [WeixinInternalRequest("访问被拒绝,请通过微信客户端访问!", "nofilter")]
+        [WXOAuth(appId: null, oauthCallbackUrl: "/api/Auth")]
+        public async Task<IActionResult> Get()
+        {
+            WXUser u = await _context.WXUsers.AsNoTracking().SingleOrDefaultAsync<WXUser>(m => m.OpenId == HttpContext.Session.GetString("OpenId"));
+            if (u != null)
+                return Ok(u);
+            else
+                return NotFound();
+        }
+
+        [HttpPost]
+        [WeixinInternalRequest("访问被拒绝,请通过微信客户端访问!", "nofilter")]
+        [WXOAuth(appId: null, oauthCallbackUrl: "/api/Auth")]
+        public async Task<IActionResult> Post([FromBody]WXUser value)
+        {
+            WXUser u = await _context.WXUsers.AsNoTracking().SingleOrDefaultAsync<WXUser>(m => m.OpenId == HttpContext.Session.GetString("OpenId"));
+            if (u != null && u.Mobile.Equals(value.Mobile, StringComparison.CurrentCultureIgnoreCase))
+            {
+                return Ok(u);                
+            }
+            else
+            {
+                value.OpenId = HttpContext.Session.GetString("OpenId");
+                value.Id = Guid.NewGuid();
+                try
+                {
+                    if (ModelState.IsValid)
+                    {
+                        _context.WXUsers.Add(value);
+                        await _context.SaveChangesAsync();
+                        return Ok(value);
+                    }
+                    return BadRequest("系统繁忙,稍后再试");
+                }
+                catch(Exception e)
+                {
+                    _logger.LogError(e.Message);
+                    return BadRequest("系统异常,稍后再试");
+                }
+            }
+        }
+    }
+}

+ 138 - 0
Winsoft.GOV.XF.WebApi.WXCore/DBProvider/BaseDBProvider.cs

@@ -0,0 +1,138 @@
+//using Dapper;
+//using MySql.Data.MySqlClient;
+//using System;
+//using System.Collections.Generic;
+//using System.Data;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
+
+//namespace Winsoft.GOV.XF.WebApi.WXCore.DBProvider
+//{
+//    public class DBConfig
+//    {
+//        public static string DefaultConnectionString { get; set; }
+//    }
+//    public class BaseDBProvider<T>
+//    {
+//        #region instance
+//        private static object lockObj = new object();
+//        private static string createWXUser = "CREATE TABLE IF NOT EXISTS `wxuser` (" +
+//                                             " `id` INT GENERATED ALWAYS AS(0)," +
+//                                             " `openid` VARCHAR(64) NOT NULL," +
+//                                             " `mobile` VARCHAR(11) NULL," +
+//                                             " `email` VARCHAR(100) NULL," +
+//                                             " UNIQUE INDEX `openid_UNIQUE` (`openid` ASC)," +
+//                                             " PRIMARY KEY(`id`));";
+//        private static string createWXBatch = "CREATE TABLE  IF NOT EXISTS  `wxbatch` (" +
+//                                              " `id` VARCHAR(64) NOT NULL," +
+//                                              " `decribe` VARCHAR(500) NULL," +
+//                                              " PRIMARY KEY(`id`));";
+//        private static string createWXResource = "CREATE TABLE  IF NOT EXISTS  `wxresource` (" +
+//                                              " `id` VARCHAR(64) NOT NULL," +
+//                                              " `batchId` VARCHAR(64) NOT NULL," +
+//                                              " `url` VARCHAR(500) NULL," +
+//                                              " PRIMARY KEY(`id`));";
+
+
+//        protected static void CreateInstance<K>(ref K singleInstance) where K : BaseDBProvider<T>, new()
+//        {
+//            if (singleInstance == null)
+//            {
+//                lock (lockObj)
+//                {
+//                    if (singleInstance == null)
+//                    {
+//                        singleInstance = new K();
+//                    }
+//                }
+//            }
+//        }
+//        #endregion
+
+//        #region        connection
+
+        
+
+//        public BaseDBProvider()
+//        {
+//        }
+
+//        /// <summary>
+//        /// </summary>
+//        /// <param name="connectionStr"></param>
+//        /// <returns></returns>
+//        protected IDbConnection GetDbConnection()
+//        {
+//            var connection = new MySqlConnection
+//            {
+//                ConnectionString = DBConfig.DefaultConnectionString
+//            };
+//            connection.Open();
+//            return connection;
+//        }
+
+//        protected string BuildTotalSQL(string sql)
+//        {
+//            var selectCount = new StringBuilder("SELECT COUNT(1) from (");
+//            return
+//                selectCount.Append(sql + ") as t")
+//                    .ToString();
+//        }
+//        /// <summary>
+//        /// </summary>
+//        /// <param name="total"></param>
+//        /// <param name="sql"></param>
+//        /// <param name="pageIndex">内部索引从0开始,页码从1开始</param>
+//        /// <code>
+//        ///   if (pageIndex - 1 >= 0)
+//        ///   {
+//        ///       pageIndex = pageIndex - 1;
+//        ///   }
+//        /// </code>
+//        /// <param name="pageSize"></param>
+//        /// <param name="param"></param>
+//        /// <param name="areaCode"></param>
+//        /// <returns></returns>
+//        //protected PagedResult<T> GetPagedList(string sql, int pageIndex, int pageSize, object param)
+//        //{
+//        //    long total = 0;
+//        //    pageIndex -= 1;
+//        //    if (pageIndex < 0)
+//        //    {
+//        //        pageIndex = 0;
+//        //    }
+//        //    if (pageSize <= 0)
+//        //    {
+//        //        pageSize = 20;
+//        //    }
+//        //    using (IDbConnection connection = GetDbConnection())
+//        //    {
+//        //        string totalSql = BuildTotalSQL(sql);
+//        //        total = connection.Query<long>(totalSql, param).FirstOrDefault();
+//        //        var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", pageIndex * pageSize, pageSize), param);
+
+//        //        return new PagedResult<T>(list, pageIndex + 1, pageSize, total);
+
+//        //    }
+//        //}
+
+//        protected IEnumerable<T> GetItemList(string sql, int itemIndex, int pageSize, object param)
+//        {
+//            if (itemIndex < 0)
+//            {
+//                itemIndex = 0;
+//            }
+//            if (pageSize <= 0)
+//            {
+//                pageSize = 20;
+//            }
+//            using (IDbConnection connection = GetDbConnection())
+//            {
+//                var list = connection.Query<T>(String.Format(sql + " limit {0},{1}", itemIndex, pageSize), param);
+//                return list;
+//            }
+//        }
+//        #endregion
+//    }
+//}

+ 20 - 0
Winsoft.GOV.XF.WebApi.WXCore/Data/DbInitializer.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Data
+{
+    public class DbInitializer
+    {
+        XFContext _context;
+        public DbInitializer(XFContext context)
+        {
+            _context = context;
+        }
+        public void Initialize()
+        {
+            _context.Database.EnsureCreated();
+        }
+    }
+}

+ 26 - 0
Winsoft.GOV.XF.WebApi.WXCore/Data/XFContext.cs

@@ -0,0 +1,26 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Winsoft.GOV.XF.WebApi.WXCore.Models;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Data
+{
+    public class XFContext: DbContext
+    {
+        public XFContext(DbContextOptions<XFContext> options) : base(options)
+        {
+        }
+        public DbSet<WXUser> WXUsers { get; set; }
+        public DbSet<Asset> Assets { get; set; }
+        public DbSet<Bundle> Bundles { get; set; }
+
+        protected override void OnModelCreating(ModelBuilder modelBuilder)
+        {
+            modelBuilder.Entity<WXUser>().ToTable("WXUser");
+            modelBuilder.Entity<Asset>().ToTable("Asset");
+            modelBuilder.Entity<Bundle>().ToTable("Bundle");
+        }
+    }
+}

+ 21 - 0
Winsoft.GOV.XF.WebApi.WXCore/Models/Asset.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Models
+{
+    public enum AssetType
+    {
+        Positon,
+        Image
+    }
+    public class Asset
+    {
+        public Guid Id { get; set; }
+        public Guid BundleId { get; set; }
+        public string Describe { get; set; }
+        public AssetType AssetType { get; set; }
+        public string Data { get; set; }
+    }
+}

+ 14 - 0
Winsoft.GOV.XF.WebApi.WXCore/Models/Bundle.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Models
+{
+    public class Bundle
+    {
+        public Guid Id { get; set; }
+        public string Describe { get; set; }
+        public IEnumerable<Asset> Assets { get; set; }
+    }
+}

+ 14 - 0
Winsoft.GOV.XF.WebApi.WXCore/Models/WXUser.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Winsoft.GOV.XF.WebApi.WXCore.Models
+{
+    public class WXUser
+    {
+        public Guid Id { get; set; }
+        public string OpenId { get; set; }
+        public string Mobile { get; set; }
+    }
+}

+ 15 - 2
Winsoft.GOV.XF.WebApi.WXCore/Startup.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
@@ -12,6 +12,10 @@ using Winsoft.GOV.XF.WebApi.WXCore.Utilities;
 using Senparc.Weixin.Entities;
 using Microsoft.Extensions.Options;
 using Senparc.Weixin.MP.Containers;
+using Winsoft.GOV.XF.WebApi.WXCore.Data;
+using Pomelo.EntityFrameworkCore.MySql;
+using Microsoft.EntityFrameworkCore;
+//using Winsoft.GOV.XF.WebApi.WXCore.DBProvider;
 
 namespace Winsoft.GOV.XF.WebApi.WXCore
 {
@@ -44,19 +48,24 @@ namespace Winsoft.GOV.XF.WebApi.WXCore
             // Adds a default in-memory implementation of IDistributedCache.
             services.AddDistributedMemoryCache();
 
+            services.AddDbContext<XFContext>(options =>
+                options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));
+
             services.AddSession(options =>
             {
                 // Set a short timeout for easy testing.
                 options.IdleTimeout = TimeSpan.FromSeconds(10);
                 options.CookieHttpOnly = true;
             });
+            services.AddTransient<DbInitializer>();
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
-        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
+        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions<SenparcWeixinSetting> senparcWeixinSetting, DbInitializer dbInitializer)
         {
             loggerFactory.AddConsole(Configuration.GetSection("Logging"));
             loggerFactory.AddDebug();
+            loggerFactory.AddFile(Configuration.GetSection("Logging"));
 
             app.UseStaticFiles();
 
@@ -75,6 +84,10 @@ namespace Winsoft.GOV.XF.WebApi.WXCore
 
             //注册微信
             AccessTokenContainer.Register(senparcWeixinSetting.Value.WeixinAppId, senparcWeixinSetting.Value.WeixinAppSecret);
+            dbInitializer.Initialize();
+
+
+            //DBConfig.DefaultConnectionString = Configuration["Data:DefaultConnection:ConnectionString"];
 
             //Senparc.Weixin SDK 配置
             Senparc.Weixin.Config.DefaultSenparcWeixinSetting = senparcWeixinSetting.Value;

+ 15 - 14
Winsoft.GOV.XF.WebApi.WXCore/Winsoft.GOV.XF.WebApi.WXCore.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp1.1</TargetFramework>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
     <PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
   </PropertyGroup>
 
@@ -9,19 +9,20 @@
     <Folder Include="wwwroot\" />
   </ItemGroup>
   <ItemGroup>
-    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
-    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
-    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
-    <PackageReference Include="Microsoft.AspNetCore.Session" Version="1.1.2" />
-    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
-    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
-    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
-    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" />
-    <PackageReference Include="Senparc.Weixin.MP" Version="14.5.4.2" />
-    <PackageReference Include="Senparc.Weixin.MP.CoreMvc" Version="1.2.0" />
+    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
+    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
+    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
+    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.0" />
+    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
+    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
+    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
+    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.0-rtm-10058" />
+    <PackageReference Include="Senparc.Weixin.MP" Version="14.6.7" />
+    <PackageReference Include="Senparc.Weixin.MP.CoreMvc" Version="1.4.0" />
   </ItemGroup>
   <ItemGroup>
     <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />

+ 16 - 2
Winsoft.GOV.XF.WebApi.WXCore/appsettings.json

@@ -1,10 +1,24 @@
-{
+{
+  "ConnectionStrings": {
+    "DefaultConnection": "Data Source=127.0.0.1;User ID=root;Password=root;Database=WXCore;"
+    //"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=Winsoft.GOV.XF.WebApi.ManagerCore;Trusted_Connection=True;MultipleActiveResultSets=true"
+  },
+  // LogLevel Severity: "Trace", "Debug", "Information", "Warning", "Error", "Critical", "None"
   "Logging": {
+    "PathFormat": "Logs/log-{Date}.log",
     "IncludeScopes": false,
     "LogLevel": {
-      "Default": "Warning"
+      "Default": "Debug",
+      "System": "Information",
+      "Microsoft": "Information"
     }
   },
+  //"Logging": {
+  //  "IncludeScopes": false,
+  //  "LogLevel": {
+  //    "Default": "Warning"
+  //  }
+  //},
   "SenparcWeixinSetting": {
     "Token": "lishui12345",
     "EncodingAESKey": "",

+ 1 - 1
Winsoft.GOV.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.26730.3
+VisualStudioVersion = 15.0.26730.10
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Winsoft.GOV.ConsoleSyncData", "Winsoft.GOV.ConsoleSyncData\Winsoft.GOV.ConsoleSyncData.csproj", "{0EDFFC90-32C5-4B06-91ED-C8DB47D431EC}"
 EndProject