test(wxapi): 新增验证微信回调通知事件签名的单元测试

This commit is contained in:
Fu Diwei 2021-08-02 20:21:45 +08:00
parent 741754c2c7
commit 21832ca18b
2 changed files with 6 additions and 7 deletions

View File

@ -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");

View File

@ -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 事件")]