Skip to content

Commit

Permalink
Merge pull request #1540 from JeffreySu/Developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
JeffreySu authored Dec 29, 2018
2 parents 6fcb214 + 673f655 commit d454493
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ActionResult Index()
var guid = Guid.NewGuid().ToString("n");
ViewData["Guid"] = guid;

var configHelper = new ConfigHelper(this.HttpContext);
var configHelper = new ConfigHelper();

try
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public ActionResult Download(string guid)
var codeRecord = ConfigHelper.CodeCollection[guid];
codeRecord.Used = true;
//codeRecord.AllowDownload = false;//这里如果只允许一次下载,有的浏览器插件或者防护软件会自动访问页面上的链接,导致用户真实的下载时效
var configHelper = new ConfigHelper(this.HttpContext);
var configHelper = new ConfigHelper();
var filePath = configHelper.Download(codeRecord.Version, codeRecord.IsWebVersion).Replace("/","\\");
//var file = File(filePath, "application/octet-stream");(此方法在.net core中会失败)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ActionResult Index()
TempData["CacheStrategy"] = containerCacheStrategy.GetType().Name.Replace("ContainerCacheStrategy", "");

//文档下载版本
var configHelper = new ConfigHelper(this.HttpContext);
var configHelper = new ConfigHelper();
var config = configHelper.GetConfig();
TempData["NewestDocumentVersion"] = config.Versions.First();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Web;

using Microsoft.AspNetCore.Mvc;
using Senparc.CO2NET.Utilities;
using Senparc.Weixin.MP.Sample.CommonService.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers
Expand Down Expand Up @@ -61,7 +62,7 @@ public ActionResult TestUploadMediaFile(string token, UploadMediaFileType type,
}

//储存文件,对比是否上传成功
using (FileStream ms = new FileStream(Server.GetMapPath("~/TestUploadMediaFile.jpg"), FileMode.OpenOrCreate))
using (FileStream ms = new FileStream(ServerUtility.ContentRootMapPath("~/TestUploadMediaFile.jpg"), FileMode.OpenOrCreate))
{
inputStream.CopyTo(ms, 256);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Senparc.Weixin.HttpUtility;
using Senparc.CO2NET.HttpUtility;
using Senparc.Weixin.Open.AccountAPIs;
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers
{
Expand Down Expand Up @@ -68,7 +69,7 @@ public ActionResult FastRegisterAuth() {
[HttpPost]
public ActionResult Notice(PostModel postModel)
{
var logPath = Server.GetMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
Expand Down Expand Up @@ -133,7 +134,7 @@ public ActionResult Callback(Entities.Request.PostModel postModel)

//处理微信普通消息,可以直接使用公众号的MessageHandler。此处的URL也可以直接填写公众号普通的URL,如本Demo中的/Weixin访问地址。

var logPath = Server.GetMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
Expand Down Expand Up @@ -171,7 +172,7 @@ public ActionResult Callback(Entities.Request.PostModel postModel)
{
using (
TextWriter tw =
new StreamWriter(Server.GetMapPath("~/App_Data/Open/Error_" + SystemTime.Now.Ticks + ".txt")))
new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Open/Error_" + SystemTime.Now.Ticks + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
using Senparc.Weixin.MP.Sample.CommonService.Utilities;
using Senparc.CO2NET.Extensions;
using Senparc.CO2NET.Helpers;
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers
{
Expand Down Expand Up @@ -488,7 +489,7 @@ public ActionResult PayNotifyUrl()

#region 记录日志

var logDir = Server.GetMapPath(string.Format("~/App_Data/TenPayNotify/{0}", SystemTime.Now.ToString("yyyyMMdd")));
var logDir = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/TenPayNotify/{0}", SystemTime.Now.ToString("yyyyMMdd")));
if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Senparc.Weixin.MP.Sample.CommonService.WorkMessageHandlers;
using Senparc.Weixin.HttpUtility;
using Senparc.CO2NET.HttpUtility;
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers
{
Expand Down Expand Up @@ -44,15 +45,15 @@ public ActionResult Get(string msg_signature = "", string timestamp = "", string
echostr);
if (verifyUrl != null)
{
var fileStream = System.IO.File.OpenWrite(Server.GetMapPath("~/1.txt"));
var fileStream = System.IO.File.OpenWrite(ServerUtility.ContentRootMapPath("~/1.txt"));
fileStream.Write(Encoding.Default.GetBytes(verifyUrl), 0, Encoding.Default.GetByteCount(verifyUrl));
fileStream.Close();
//return Content(verifyUrl); //返回解密后的随机字符串则表示验证通过
return Content("Success");
}
else
{
var fileStream = System.IO.File.OpenWrite(Server.GetMapPath("~/1.txt"));
var fileStream = System.IO.File.OpenWrite(ServerUtility.ContentRootMapPath("~/1.txt"));
fileStream.Write(Encoding.Default.GetBytes("asd"), 0, Encoding.Default.GetByteCount("asd"));
fileStream.Close();
return Content("如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。");
Expand Down Expand Up @@ -83,24 +84,24 @@ public ActionResult Post(PostModel postModel)
try
{
//测试时可开启此记录,帮助跟踪数据,使用前请确保App_Data文件夹存在,且有读写权限。
messageHandler.RequestDocument.Save(Server.GetMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Request_" + messageHandler.RequestMessage.FromUserName + ".txt"));
messageHandler.RequestDocument.Save(ServerUtility.ContentRootMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Request_" + messageHandler.RequestMessage.FromUserName + ".txt"));
//执行微信处理过程
messageHandler.Execute();
//测试时可开启,帮助跟踪数据

if (!string.IsNullOrEmpty(messageHandler.TextResponseMessage))
{
//messageHandler.ResponseDocument.Save(Server.GetMapPath("~/App_Data/Qy/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"));
//messageHandler.ResponseDocument.Save(ServerUtility.ContentRootMapPath("~/App_Data/Qy/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"));
var responseText = messageHandler.TextResponseMessage;
using (StreamWriter sw = new StreamWriter(Server.GetMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"), true))
using (StreamWriter sw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"), true))
{
sw.Write(responseText);
}

if (messageHandler.FinalResponseDocument != null)
{
//messageHandler.FinalResponseDocument.Save(Server.GetMapPath("~/App_Data/Qy/" + SystemTime.Now.Ticks + "_FinalResponse_" + messageHandler.ResponseMessage.ToUserName + ".txt"));
using (StreamWriter sw = new StreamWriter(Server.GetMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"), true))
//messageHandler.FinalResponseDocument.Save(ServerUtility.ContentRootMapPath("~/App_Data/Qy/" + SystemTime.Now.Ticks + "_FinalResponse_" + messageHandler.ResponseMessage.ToUserName + ".txt"));
using (StreamWriter sw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Work/" + SystemTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt"), true))
{
sw.Write(messageHandler.FinalResponseDocument.ToString());
}
Expand All @@ -112,7 +113,7 @@ public ActionResult Post(PostModel postModel)
}
catch (Exception ex)
{
using (TextWriter tw = new StreamWriter(Server.GetMapPath("~/App_Data/Work_Error_" + SystemTime.Now.Ticks + ".txt")))
using (TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Work_Error_" + SystemTime.Now.Ticks + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Senparc.Weixin.MP.CoreSample.Controllers
{
using Microsoft.Extensions.Options;
using Senparc.CO2NET.HttpUtility;
using Senparc.CO2NET.Utilities;
using Senparc.Weixin.Entities;
using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.MP.MvcExtension;
Expand Down Expand Up @@ -111,7 +112,7 @@ public ActionResult Post(PostModel postModel)
#region 异常处理
WeixinTrace.Log("MessageHandler错误:{0}", ex.Message);

using (TextWriter tw = new StreamWriter(Server.GetMapPath("~/App_Data/Error_" + _getRandomFileName() + ".txt")))
using (TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Error_" + _getRandomFileName() + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace Senparc.Weixin.MP.CoreSample.Controllers
{
using Senparc.CO2NET.Utilities;
using Senparc.NeuChar;
using Senparc.NeuChar.Entities;
using Senparc.Weixin.MP.Entities;
Expand Down Expand Up @@ -57,7 +58,7 @@ public ActionResult OldPost(string signature, string timestamp, string nonce, st
//如果不需要记录requestDoc,只需要:
//var requestMessage = RequestMessageFactory.GetRequestEntity(Request.InputStream);

requestDoc.Save(Server.GetMapPath("~/App_Data/" + SystemTime.Now.Ticks + "_Request_" + requestMessage.FromUserName + ".txt"));//测试时可开启,帮助跟踪数据
requestDoc.Save(ServerUtility.ContentRootMapPath("~/App_Data/" + SystemTime.Now.Ticks + "_Request_" + requestMessage.FromUserName + ".txt"));//测试时可开启,帮助跟踪数据
ResponseMessageBase responseMessage = null;
switch (requestMessage.MsgType)
{
Expand Down Expand Up @@ -121,7 +122,7 @@ public ActionResult OldPost(string signature, string timestamp, string nonce, st
throw new ArgumentOutOfRangeException();
}
var responseDoc = Senparc.NeuChar.Helpers.EntityHelper.ConvertEntityToXml(responseMessage);
responseDoc.Save(Server.GetMapPath("~/App_Data/" + SystemTime.Now.Ticks + "_Response_" + responseMessage.ToUserName + ".txt"));//测试时可开启,帮助跟踪数据
responseDoc.Save(ServerUtility.ContentRootMapPath("~/App_Data/" + SystemTime.Now.Ticks + "_Response_" + responseMessage.ToUserName + ".txt"));//测试时可开启,帮助跟踪数据

return Content(responseDoc.ToString());
//如果不需要记录responseDoc,只需要:
Expand All @@ -130,7 +131,7 @@ public ActionResult OldPost(string signature, string timestamp, string nonce, st
catch (Exception ex)
{
using (
TextWriter tw = new StreamWriter(Server.GetMapPath("~/App_Data/Error_" + SystemTime.Now.Ticks + ".txt")))
TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Error_" + SystemTime.Now.Ticks + ".txt")))
{
tw.WriteLine(ex.Message);
tw.WriteLine(ex.InnerException.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Senparc.Weixin.MP.Sample.CommonService.Utilities;
using Senparc.Weixin.HttpUtility;
using Senparc.CO2NET.HttpUtility;
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers
{
Expand Down Expand Up @@ -83,7 +84,7 @@ public ActionResult Post(PostModel postModel)
//var sr = new StreamReader(ms);
//var xml = sr.ReadToEnd();
//var doc = XDocument.Parse(xml);
//doc.Save(Server.GetMapPath("~/App_Data/TestWork.log"));
//doc.Save(ServerUtility.ContentRootMapPath("~/App_Data/TestWork.log"));
//return null;
#endregion

Expand All @@ -109,7 +110,7 @@ public ActionResult Post(PostModel postModel)
}
catch (Exception ex)
{
using (TextWriter tw = new StreamWriter(Server.GetMapPath("~/App_Data/Work_Error_" + SystemTime.Now.Ticks + ".txt")))
using (TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Work_Error_" + SystemTime.Now.Ticks + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.IO;
using Senparc.Weixin.TenPay.V3;
using Senparc.Weixin.MP.Sample.CommonService;
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample.Controllers.WxOpen
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public ActionResult Post(PostModel postModel)
//v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制
var maxRecordCount = 10;

var logPath = Server.GetMapPath(string.Format("~/App_Data/WxOpen/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
var logPath = ServerUtility.ContentRootMapPath(string.Format("~/App_Data/WxOpen/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
Expand Down Expand Up @@ -102,7 +103,7 @@ public ActionResult Post(PostModel postModel)
}
catch (Exception ex)
{
using (TextWriter tw = new StreamWriter(Server.GetMapPath("~/App_Data/Error_WxOpen_" + _getRandomFileName() + ".txt")))
using (TextWriter tw = new StreamWriter(ServerUtility.ContentRootMapPath("~/App_Data/Error_WxOpen_" + _getRandomFileName() + ".txt")))
{
tw.WriteLine("ExecptionMessage:" + ex.Message);
tw.WriteLine(ex.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Senparc.Weixin.TenPay;//DPBMARK TenPay DPBMARK_END
using Senparc.Weixin.Work;//DPBMARK Work DPBMARK_END
using Senparc.Weixin.WxOpen;//DPBMARK MiniProgram DPBMARK_END
using Senparc.CO2NET.Utilities;

namespace Senparc.Weixin.MP.CoreSample
{
Expand Down Expand Up @@ -78,14 +79,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions
});


#region 提供网站根目录(当前 Sample 用到,和 SDK 无关)
if (env.ContentRootPath != null)
{
Senparc.Weixin.MP.Sample.CommonService.Utilities.Server.AppDomainAppPath = env.ContentRootPath;// env.ContentRootPath;
}
Senparc.Weixin.MP.Sample.CommonService.Utilities.Server.WebRootPath = env.WebRootPath;// env.ContentRootPath;
#endregion

// 启动 CO2NET 全局注册,必须!
IRegisterService register = RegisterService.Start(env, senparcSetting.Value)
//关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
Expand Down Expand Up @@ -235,7 +228,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions
//getComponentVerifyTicketFunc
componentAppId =>
{
var dir = Path.Combine(Server.GetMapPath("~/App_Data/OpenTicket"));
var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/OpenTicket"));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
Expand All @@ -255,7 +248,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions
//getAuthorizerRefreshTokenFunc
(componentAppId, auhtorizerId) =>
{
var dir = Path.Combine(Server.GetMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
Expand All @@ -278,7 +271,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions
//authorizerTokenRefreshedFunc
(componentAppId, auhtorizerId, refreshResult) =>
{
var dir = Path.Combine(Server.GetMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
<a href="http://weibo.com/jeffreysu1984" target="_blank">@@苏震巍</a>*@
@*QQ:<a href="javascript:;">498977166</a>*@

当前框架:.NET Core 2.2 | 当前缓存策略:@ViewData["CacheType"]
当前框架:<a href="https://dotnet.microsoft.com/download" target="_blank">.NET Core 2.2</a> | 当前缓存策略:@ViewData["CacheType"]
</p>
<p class="footer-icon">&copy; 2006-@SystemTime.Now.Year Senparc,苏州盛派网络科技有限公司,版权所有,保留所有权利。</p>
</div>
Expand Down
Loading

0 comments on commit d454493

Please sign in to comment.