Skip to content

Commit

Permalink
preview3 - v3.3.2 修改 DateTime 为 DateTimeOffset Senparc/Senparc.CO2NET#59
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Dec 26, 2018
1 parent 9f97044 commit 4d5887c
Show file tree
Hide file tree
Showing 101 changed files with 549 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public ActionResult Index()
{
Analysis_IndexVD vd = new Analysis_IndexVD()
{
StartDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
EndDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
StartDate = SystemTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
EndDate = SystemTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ActionResult Index()
/// <returns></returns>
public async Task<RedirectResult> QrCodeTest()
{
var ticks = DateTime.Now.Ticks.ToString();
var ticks = SystemTime.Now.Ticks.ToString();
var sceneId = int.Parse(ticks.Substring(ticks.Length - 7, 7));

var qrResult = await QrCodeApi.CreateAsync(appId, 100, sceneId, QrCode_ActionName.QR_SCENE, "QrTest");
Expand Down Expand Up @@ -67,7 +67,7 @@ public async Task<ActionResult> TemplateMessageTest(string checkcode)
first = new TemplateDataItem("【异步模板消息测试】"),
keyword1 = new TemplateDataItem(openId),
keyword2 = new TemplateDataItem("网页测试"),
keyword3 = new TemplateDataItem(DateTime.Now.ToString("O")),
keyword3 = new TemplateDataItem(SystemTime.Now.ToString("O")),
remark = new TemplateDataItem("更详细信息,请到Senparc.Weixin SDK官方网站(http://sdk.weixin.senparc.com)查看!")
};

Expand Down Expand Up @@ -115,7 +115,7 @@ private async Task<string> GetRemoteData()
await Task.Run(() =>
{
Task.Delay(1000);
result = "hi " + DateTime.Now.ToString();
result = "hi " + SystemTime.Now.ToString();
});
return result;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ private async Task<string> GetRemoteData2()
await Task.Run(() =>
{
Task.Delay(1000);
result = "hi " + DateTime.Now.ToString();
result = "hi " + SystemTime.Now.ToString();
}).ConfigureAwait(false);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Senparc.Weixin.MP.CoreSample.Controllers
[Serializable]
internal class TestContainerBag1 : BaseContainerBag
{
private DateTime _dateTime;
private DateTimeOffset _dateTime;

public DateTime DateTime { get; set; }
public DateTimeOffset DateTime { get; set; }
//{
// get { return _dateTime; }
// set { this.SetContainerProperty(ref _dateTime, value); }
Expand All @@ -31,8 +31,8 @@ internal class TestContainerBag1 : BaseContainerBag
//[Serializable]
//internal class TestContainerBag2 : BaseContainerBag
//{
// private DateTime _dateTime;
// public DateTime DateTime
// private DateTimeOffset _dateTime;
// public DateTimeOffset DateTime
// {
// get { return _dateTime; }
// set { this.SetContainerProperty(ref _dateTime, value); }
Expand Down Expand Up @@ -84,11 +84,11 @@ public ActionResult Redis(int id = 1)
sb.AppendFormat("Count1:{0}<br />", itemCollection != null ? itemCollection.Count() : -1);


var bagKey = "Redis." + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss-ffff");
var bagKey = "Redis." + SystemTime.Now.ToString("yyyy-MM-dd--HH-mm-ss-ffff");
var bag = new TestContainerBag1()
{
Key = bagKey,
DateTime = DateTime.Now
DateTime = SystemTime.Now
};

TestContainer1.Update(bagKey, bag,TimeSpan.FromHours(1));//更新到缓存(立即更新)
Expand All @@ -99,7 +99,7 @@ public ActionResult Redis(int id = 1)

if (itemCollection != null)
{
itemCollection[DateTime.Now.Ticks.ToString()] = bag;
itemCollection[SystemTime.Now.Ticks.ToString()] = bag;
}

itemCollection = containerCacheStrategy.GetAll<TestContainerBag1>();//如果是分布式缓存,这里的数字通常不会变
Expand All @@ -122,19 +122,19 @@ public ActionResult RunTest()
for (int i = 0; i < 3; i++)
{
sb.AppendFormat("<br />====== {0}:{1} ======<br /><br />", "开始一轮测试", i + 1);
var shortBagKey = DateTime.Now.ToString("yyyyMMdd-HHmmss");
var shortBagKey = SystemTime.Now.ToString("yyyyMMdd-HHmmss");
var finalBagKey = baseCacheStrategy.GetFinalKey(ContainerHelper.GetItemCacheKey(typeof(TestContainerBag1), shortBagKey));//获取最终缓存中的键
var bag = new TestContainerBag1()
{
Key = shortBagKey,
DateTime = DateTime.Now
DateTime = SystemTime.Now
};
TestContainer1.Update(shortBagKey, bag,TimeSpan.FromHours(1)); //更新到缓存(立即更新)
sb.AppendFormat("{0}:{1}<br />", "bag.DateTime", bag.DateTime.ToString("o"));

Thread.Sleep(1);

bag.DateTime = DateTime.Now; //进行修改
bag.DateTime = SystemTime.Now; //进行修改

//读取队列
var mq = new SenparcMessageQueue();
Expand Down Expand Up @@ -171,7 +171,7 @@ public ActionResult RunTest()

itemCollection = containerCacheStrategy.GetAll<TestContainerBag1>();
existed = itemCollection.ContainsKey(finalBagKey);
finalExisted = existed && itemCollection[finalBagKey].CacheTime.Date == DateTime.Now.Date;
finalExisted = existed && itemCollection[finalBagKey].CacheTime.Date == SystemTime.Now.Date;
sb.AppendFormat("{0}:{1}<br />", "当前缓存是否存在", existed);
sb.AppendFormat("{0}:{1}<br />", "插入缓存时间",
!existed ? "不存在" : itemCollection[finalBagKey].CacheTime.ToString("o")); //应为当前加入到缓存的最新时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ActionResult PostTest()

var isAjax = Request.IsAjaxRequest();

Response.Cookies.Append("TestCookie", DateTime.Now.ToString());
Response.Cookies.Append("TestCookie", SystemTime.Now.ToString());

return Content(data + " Ajax:" + isAjax + " Server Time:" + DateTime.Now);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class OAuth2Controller : Controller
/// <returns></returns>
public ActionResult Index(string returnUrl)
{
var state = "JeffreySu-" + DateTime.Now.Millisecond;//随机数,用于识别请求可靠性
var state = "JeffreySu-" + SystemTime.Now.Millisecond;//随机数,用于识别请求可靠性
HttpContext.Session.SetString("State", state);//储存随机数到Session

ViewData["returnUrl"] = returnUrl;
Expand Down Expand Up @@ -94,7 +94,7 @@ public ActionResult UserInfoCallback(string code, string state, string returnUrl
}
//下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
//如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
HttpContext.Session.SetString("OAuthAccessTokenStartTime", DateTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessTokenStartTime", SystemTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessToken", result.ToJson());

//因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息
Expand Down Expand Up @@ -147,7 +147,7 @@ public ActionResult BaseCallback(string code, string state, string returnUrl)

//下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
//如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
HttpContext.Session.SetString("OAuthAccessTokenStartTime", DateTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessTokenStartTime", SystemTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessToken", result.ToJson());

//因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public ActionResult FastRegisterAuth() {
[HttpPost]
public ActionResult Notice(PostModel postModel)
{
var logPath = Server.GetMapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd")));
var logPath = Server.GetMapPath(string.Format("~/App_Data/Open/{0}/", SystemTime.Now.ToString("yyyy-MM-dd")));
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}

//using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_RequestStream.txt", DateTime.Now.Ticks))))
//using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_RequestStream.txt", SystemTime.Now.Ticks))))
//{
// using (var sr = new StreamReader(Request.InputStream))
// {
Expand All @@ -99,13 +99,13 @@ public ActionResult Notice(PostModel postModel)
// postModel, 10);

//记录RequestMessage日志(可选)
//messageHandler.EcryptRequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request.txt", DateTime.Now.Ticks)));
messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId)));
//messageHandler.EcryptRequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request.txt", SystemTime.Now.Ticks)));
messageHandler.RequestDocument.Save(Path.Combine(logPath, string.Format("{0}_Request_{1}.txt", SystemTime.Now.Ticks, messageHandler.RequestMessage.AppId)));

messageHandler.Execute();//执行

//记录ResponseMessage日志(可选)
using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", DateTime.Now.Ticks, messageHandler.RequestMessage.AppId))))
using (TextWriter tw = new StreamWriter(Path.Combine(logPath, string.Format("{0}_Response_{1}.txt", SystemTime.Now.Ticks, messageHandler.RequestMessage.AppId))))
{
tw.WriteLine(messageHandler.ResponseMessageText);
tw.Flush();
Expand Down Expand Up @@ -133,7 +133,7 @@ public ActionResult Callback(Entities.Request.PostModel postModel)

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

var logPath = Server.GetMapPath(string.Format("~/App_Data/Open/{0}/", DateTime.Now.ToString("yyyy-MM-dd")));
var logPath = Server.GetMapPath(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 +171,7 @@ public ActionResult Callback(Entities.Request.PostModel postModel)
{
using (
TextWriter tw =
new StreamWriter(Server.GetMapPath("~/App_Data/Open/Error_" + DateTime.Now.Ticks + ".txt")))
new StreamWriter(Server.GetMapPath("~/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 @@ -139,7 +139,7 @@ public ActionResult UserInfoCallback(string code, string state, string appId)
}
//下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
//如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
HttpContext.Session.SetString("OAuthAccessTokenStartTime", DateTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessTokenStartTime", SystemTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessToken", result.ToJson());

//因为第一步选择的是OAuthScope.snsapi_userinfo,这里可以进一步获取用户详细信息
Expand Down Expand Up @@ -186,7 +186,7 @@ public ActionResult BaseCallback(string code, string state, string appId)

//下面2个数据也可以自己封装成一个类,储存在数据库中(建议结合缓存)
//如果可以确保安全,可以将access_token存入用户的cookie中,每一个人的access_token是不一样的
HttpContext.Session.SetString("OAuthAccessTokenStartTime", DateTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessTokenStartTime", SystemTime.Now.ToString());
HttpContext.Session.SetString("OAuthAccessToken", result.ToJson());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private XDocument GetrequestMessaageDoc(string url, string token, RequestMsgType
}

requestMessaage.MsgId = long.Parse(Request.Form["MsgId"]);
requestMessaage.CreateTime = DateTime.Now;
requestMessaage.CreateTime = SystemTime.Now;
requestMessaage.FromUserName = requestMessaage.FromUserName ?? "FromUserName(OpenId)";//用于区别不同的请求用户
requestMessaage.ToUserName = "ToUserName";

Expand All @@ -271,7 +271,7 @@ private string TestAsyncTask(string url, string token, XDocument requestMessaage
if (requestMessaageDoc.Root.Element("MsgId") != null)
{
requestMessaageDoc.Root.Element("MsgId").Value =
DateTimeHelper.GetWeixinDateTime(DateTime.Now.AddSeconds(Thread.CurrentThread.GetHashCode())).ToString();
DateTimeHelper.GetUnixDateTime(SystemTime.Now.AddSeconds(Thread.CurrentThread.GetHashCode())).ToString();
}

var responseMessageXml = MessageAgent.RequestXml(null, url, token, requestMessaageDoc.ToString(), 1000 * 20);
Expand Down Expand Up @@ -311,7 +311,7 @@ public ActionResult Index(string url, string token, RequestMsgType requestType,

try
{
DateTime dt1 = DateTime.Now;
var dt1 = SystemTime.Now;
if (testConcurrence)
{
testConcurrenceCount = testConcurrenceCount > 30 ? 30 : testConcurrenceCount;//设定最高限额
Expand All @@ -325,7 +325,7 @@ public ActionResult Index(string url, string token, RequestMsgType requestType,
}
Task.WaitAll(taskList.ToArray(), 1000 * 10);
}
DateTime dt2 = DateTime.Now;
var dt2 = SystemTime.Now;

var data =new { Success = true, LoadTime = (dt2 - dt1).TotalMilliseconds.ToString("##.####"), Result = responseMessageXml } ;
return Json(data, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SubscribeMsgController : BaseController
{
public ActionResult Index()
{
var reserved = DateTime.Now.Ticks.ToString();
var reserved = SystemTime.Now.Ticks.ToString();

//(非必须)reserved用于保持请求和回调的状态,授权请后原样带回给第三方。
// 该参数可用于防止csrf攻击(跨站请求伪造攻击),建议第三方带上该参数,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public ActionResult JsApi()

string sp_billno = Request.Form["order_no"];
//当前时间 yyyyMMdd
string date = DateTime.Now.ToString("yyyyMMdd");
string date = SystemTime.Now.ToString("yyyyMMdd");

if (null == sp_billno)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
sp_billno = DateTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
sp_billno = SystemTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
}
else
{
Expand Down Expand Up @@ -158,12 +158,12 @@ public ActionResult Native()
{
string sp_billno = Request.Form["order_no"];
//当前时间 yyyyMMdd
string date = DateTime.Now.ToString("yyyyMMdd");
string date = SystemTime.Now.ToString("yyyyMMdd");

if (null == sp_billno)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
sp_billno = DateTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
sp_billno = SystemTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
}
else
{
Expand Down Expand Up @@ -199,14 +199,14 @@ public ActionResult NativeCall()
{
string sp_billno = Request.Form["order_no"];
//当前时间 yyyyMMdd
string date = DateTime.Now.ToString("yyyyMMdd");
string date = SystemTime.Now.ToString("yyyyMMdd");
//订单号,此处用时间和随机数生成,商户根据自己调整,保证唯一
string out_trade_no = "" + DateTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
string out_trade_no = "" + SystemTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);

if (null == sp_billno)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
sp_billno = DateTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
sp_billno = SystemTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
}
else
{
Expand Down Expand Up @@ -432,12 +432,12 @@ public ActionResult Delivernotify()
//string appId, string openId, string transId, string out_Trade_No, string deliver_TimesTamp, string deliver_Status, string deliver_Msg, string app_Signature,
string sp_billno = Request.Form["order_no"];
//当前时间 yyyyMMdd
string date = DateTime.Now.ToString("yyyyMMdd");
string date = SystemTime.Now.ToString("yyyyMMdd");

if (null == sp_billno)
{
//生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
sp_billno = DateTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
sp_billno = SystemTime.Now.ToString("HHmmss") + TenPayUtil.BuildRandomStr(4);
}
else
{
Expand Down
Loading

0 comments on commit 4d5887c

Please sign in to comment.