mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-04-05 17:37:54 +08:00
test(wxapi): 新增验证微信回调通知事件签名的单元测试
This commit is contained in:
parent
741754c2c7
commit
21832ca18b
@ -48,11 +48,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Sample_Net5.Controllers
|
||||
// 文档:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html
|
||||
|
||||
var client = _wechatApiHttpClientFactory.Create(appId);
|
||||
bool valid = client.VerifyEventSignature(
|
||||
callbackTimestamp: timestamp,
|
||||
callbackNonce: nonce,
|
||||
callbackSignature: signature
|
||||
);
|
||||
bool valid = client.VerifyEventSignatureForEcho(callbackTimestamp: timestamp, callbackNonce: nonce, callbackSignature: signature);
|
||||
if (!valid)
|
||||
{
|
||||
return Content("fail");
|
||||
|
@ -16,9 +16,12 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
string xml = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[this is a test]]></Content><MsgId>1234567890123456</MsgId></xml>";
|
||||
|
||||
var xDoc = XDocument.Parse(xml);
|
||||
string @event = xDoc.Root!.Element("MsgType")!.Value.ToUpper();
|
||||
string msgType = xDoc.Root!.Element("MsgType")!.Value;
|
||||
|
||||
Assert.Equal("TEXT", @event);
|
||||
Assert.Equal("TEXT", msgType, ignoreCase: true);
|
||||
|
||||
var eventModel = TestClients.Instance.DeserializeEventFromXml(xml);
|
||||
Assert.Equal("TEXT", eventModel.MessageType, ignoreCase: true);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "反序列化 TEXT 事件")]
|
||||
|
Loading…
Reference in New Issue
Block a user