Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developer #1539

Merged
merged 4 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public class FixWeixinBugWeixinResultTest : BaseTest
/// <param name="xmlFormat"></param>
private string InitXml(string xmlFormat, string content)
{
return string.Format(xmlTextFormat,
DateTimeHelper.GetWeixinDateTime(DateTime.Now), content);
return string.Format(xmlTextFormat, DateTimeHelper.GetUnixDateTime(SystemTime.Now), content);
}

[TestMethod]
Expand All @@ -111,7 +110,7 @@ public void MvcExtensionTest()
messageHandler.Execute();

var result = new FixWeixinBugWeixinResult(messageHandler);
Assert.AreEqual("success",result.Content);
Assert.AreEqual("success", result.Content);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void AsyncTest()
protected void InitAsync(Controller targetAsync, Stream inputStreamAsync, string xmlFormat)
{
//target = StructureMap.ObjectFactory.GetInstance<WeixinController>();//使用IoC的在这里必须注入,不要直接实例化
var xml = string.Format(xmlFormat, DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(xmlFormat, DateTimeHelper.GetUnixDateTime(SystemTime.Now));
var bytes = System.Text.Encoding.UTF8.GetBytes(xml);

inputStreamAsync.Write(bytes, 0, bytes.Length);
Expand Down Expand Up @@ -127,7 +127,7 @@ public void AsyncMessageHandlerTest(bool testRepeatOmit = true)
var repeatedMessageCount = 0;//确定去重的消息数量
var repeatedRequestMessage = new List<IRequestMessageBase>();//被去重的请求消息记录

var dt1 = DateTime.Now;
var dt1 = SystemTime.Now;

//每个线程的测试过程
ParameterizedThreadStart task = async p =>
Expand All @@ -141,13 +141,13 @@ public void AsyncMessageHandlerTest(bool testRepeatOmit = true)
string openId = dt1.Ticks.ToString();//对每一轮测试进行分组,防止串数据
if (testRepeatOmit)
{
msgId = DateTime.Today.Ticks.ToString();
msgId = SystemTime.Today.Ticks.ToString();
openId += "0";
}
else
{
//MsgId,保证每次时间不一样
msgId = (DateTime.Today.Ticks + index).ToString();
msgId = (SystemTime.Today.Ticks + index).ToString();
//OpenId后缀,可以模拟不同人发送,也可以模拟对人多发:i%10
//如果需要测试去重功能,可以将index改为固定值,并且将MsgId设为固定值
openId += index.ToString();
Expand All @@ -156,7 +156,7 @@ public void AsyncMessageHandlerTest(bool testRepeatOmit = true)
//按钮测试
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "SubClickRoot_Text"),
////确保每次时间戳不同
DateTimeHelper.GetWeixinDateTime(DateTime.Now.AddHours(index)),
DateTimeHelper.GetUnixDateTime(SystemTime.Now.AddHours(index)),
msgId, openId);

var timestamp = "itsafaketimestamp";
Expand All @@ -173,10 +173,10 @@ public void AsyncMessageHandlerTest(bool testRepeatOmit = true)
Stream streamAsync = new MemoryStream();
InitAsync(targetAsync, streamAsync, xml);//初始化

var dtt1 = DateTime.Now;
var dtt1 = SystemTime.Now;
var actual = await targetAsync.Post(postModel) as FixWeixinBugWeixinResult;

var dtt2 = DateTime.Now;
var dtt2 = SystemTime.Now;

Assert.IsNotNull(actual);

Expand Down Expand Up @@ -225,7 +225,7 @@ public void AsyncMessageHandlerTest(bool testRepeatOmit = true)
{

}
var dt2 = DateTime.Now;
var dt2 = SystemTime.Now;

Console.WriteLine("总耗时:{0}ms", (dt2 - dt1).TotalMilliseconds);
Console.WriteLine("Empty Content Count:" + emptyContentCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected void Init(string xmlFormat)

inputStream = new MemoryStream();

var xml = string.Format(xmlFormat, DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(xmlFormat, DateTimeHelper.GetUnixDateTime(SystemTime.Now));
var bytes = System.Text.Encoding.UTF8.GetBytes(xml);

inputStream.Write(bytes, 0, bytes.Length);
Expand All @@ -134,7 +134,7 @@ protected void PostTest(string xml)
var nonce = "whateveryouwant";
var signature = Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, WeixinController.Token);

DateTime st = DateTime.Now;
var st = SystemTime.Now;
//这里使用MiniPost,绕过日志记录

var postModel = new PostModel()
Expand All @@ -144,7 +144,7 @@ protected void PostTest(string xml)
Nonce = nonce,
};
var actual = target.MiniPost(postModel) as FixWeixinBugWeixinResult;
DateTime et = DateTime.Now;
var et = SystemTime.Now;

Assert.IsNotNull(actual);
Assert.IsNotNull(actual.Content);
Expand Down Expand Up @@ -183,7 +183,7 @@ public void ImagePostTest()
public void MessageAgent_TextTest()
{
//文字测试
var xml = string.Format(string.Format(xmlTextFormat, "托管"), DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(string.Format(xmlTextFormat, "托管"), DateTimeHelper.GetUnixDateTime(SystemTime.Now));
Init(xml);//初始化

var timestamp = "itsafaketimestamp";
Expand All @@ -203,7 +203,7 @@ public void MessageAgent_TextTest()
public void MessageAgent_NewsTest()
{
//按钮测试-图文
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "SubClickRoot_Agent"), DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "SubClickRoot_Agent"), DateTimeHelper.GetUnixDateTime(SystemTime.Now));
Init(xml);//初始化

var timestamp = "itsafaketimestamp";
Expand All @@ -223,7 +223,7 @@ public void MessageAgent_NewsTest()
public void MessageAgent_MemberTest()
{
//按钮测试-会员
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "Member"), DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "Member"), DateTimeHelper.GetUnixDateTime(SystemTime.Now));
Init(xml);//初始化

var timestamp = "itsafaketimestamp";
Expand All @@ -243,7 +243,7 @@ public void MessageAgent_MemberTest()
public void MessageContextRecordLimtTest()
{
//测试MessageContext的数量限制
var xml = string.Format(string.Format(xmlTextFormat, "测试限制"), DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(string.Format(xmlTextFormat, "测试限制"), DateTimeHelper.GetUnixDateTime(SystemTime.Now));
for (int i = 0; i < 100; i++)
{
Init(xml);//初始化
Expand Down Expand Up @@ -271,7 +271,7 @@ public void MessageContextRecordLimtTest()
public void TextMuteTest()
{
//测试无返回消息
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "mute"), DateTimeHelper.GetWeixinDateTime(DateTime.Now));
var xml = string.Format(string.Format(xmlEvent_ClickFormat, "mute"), DateTimeHelper.GetUnixDateTime(SystemTime.Now));
Init(xml);//初始化

PostTest(string.Format(xmlTextFormat, "mute"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void MassageAgentTest()
var requestMessage = new RequestMessageText()
{
Content = "代理",
CreateTime = DateTime.Now,
CreateTime = SystemTime.Now,
FromUserName = "FromeUserName",
ToUserName = "ToUserName",
MsgId = 123,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ActionResult Index()
{
Analysis_IndexVD vd = new Analysis_IndexVD()
{
StartDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
StartDate = SystemTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
EndDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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 @@ -66,7 +66,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.LocalDateTime.ToString()),
remark = new TemplateDataItem("更详细信息,请到Senparc.Weixin SDK官方网站(https://sdk.weixin.senparc.com)查看!\r\n\r\n这里我做了两个换行!\r\n\r\n点击详情可跳转到 BookHelper 小程序!")
};

Expand Down Expand Up @@ -114,7 +114,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 @@ -152,7 +152,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 @@ -28,5 +28,11 @@ protected string AppId
return Config.SenparcWeixinSetting.WeixinAppId;//与微信公众账号后台的AppId设置保持一致,区分大小写。
}
}

protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
ViewData["CacheType"] = CO2NET.Cache.CacheStrategyFactory.GetObjectCacheStrategyInstance().GetType().Name;
base.OnResultExecuting(filterContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Senparc.Weixin.MP.Sample.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 Down Expand Up @@ -83,11 +83,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 @@ -98,7 +98,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 @@ -121,19 +121,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 @@ -170,7 +170,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 @@ -25,9 +25,9 @@ public ActionResult PostTest()

var isAjax = Request.IsAjaxRequest();

Response.SetCookie(new HttpCookie("TestCookie", DateTime.Now.ToString()));
Response.SetCookie(new HttpCookie("TestCookie", SystemTime.Now.ToString()));

return Content(data + " Ajax:" + isAjax + " Server Time:" + DateTime.Now);
return Content(data + " Ajax:" + isAjax + " Server Time:" + SystemTime.Now);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public ActionResult Index()
var version = System.Reflection.Assembly.GetAssembly(type).GetName().Version;
return getDisplayVersion(version);
};
TempData["SampleVersion"] = getTypeVersionInfo(this.GetType());//当前Demo的版本号
TempData["CO2NETVersion"] = getTypeVersionInfo(typeof(CO2NET.Config));//CO2NET版本号
TempData["NeuCharVersion"] = getTypeVersionInfo(typeof(Senparc.NeuChar.ApiBindInfo));//NeuChar版本号

TempData["CO2NETVersion"] = getTypeVersionInfo(typeof(CO2NET.Config));
TempData["WeixinVersion"] = getTypeVersionInfo(typeof(Senparc.Weixin.Config));
TempData["TenPayVersion"] = getTypeVersionInfo(typeof(Senparc.Weixin.TenPay.Register));//DPBMARK TenPay DPBMARK_END
TempData["MpVersion"] = getTypeVersionInfo(typeof(Senparc.Weixin.MP.Register));//DPBMARK MP DPBMARK_END
Expand All @@ -59,7 +61,7 @@ public ActionResult Index()

//缓存
//var containerCacheStrategy = CacheStrategyFactory.GetContainerCacheStrategyInstance();
var containerCacheStrategy = ContainerCacheStrategyFactory.GetContainerCacheStrategyInstance();
var containerCacheStrategy = ContainerCacheStrategyFactory.GetContainerCacheStrategyInstance()/*.ContainerCacheStrategy*/;
TempData["CacheStrategy"] = containerCacheStrategy.GetType().Name.Replace("ContainerCacheStrategy", "");

//文档下载版本
Expand All @@ -69,6 +71,10 @@ public ActionResult Index()

Weixin.WeixinTrace.SendCustomLog("首页被访问", string.Format("Url:{0}\r\nIP:{1}", Request.Url, Request.UserHostName));

//获取编译时间
//因为官方在线 Demo CI 自动生成使用的服务器为 UTC-0,所以北京时间需要+8小时
TempData["BuildTime"] = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).AddHours(8).ToString("yyyyMMdd.HH.mm");

return View();
}

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

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

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

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

//因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
Expand Down
Loading