diff --git a/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN.Abp.WeChat.Common.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN.Abp.WeChat.Common.Tests.csproj new file mode 100644 index 000000000..2d94c78c7 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN.Abp.WeChat.Common.Tests.csproj @@ -0,0 +1,25 @@ + + + + net10.0 + + false + Debug;Release + AnyCPU + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestBase.cs b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestBase.cs new file mode 100644 index 000000000..b4eebc5cc --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestBase.cs @@ -0,0 +1,7 @@ +using LINGYUN.Abp.Tests; + +namespace LINGYUN.Abp.WeChat.Common; + +public abstract class AbpWeChatCommonTestBase : AbpTestsBase +{ +} diff --git a/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestModule.cs new file mode 100644 index 000000000..26086eab2 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/AbpWeChatCommonTestModule.cs @@ -0,0 +1,11 @@ +using LINGYUN.Abp.Tests; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.WeChat.Common; + +[DependsOn( + typeof(AbpWeChatCommonModule), + typeof(AbpTestsBaseModule))] +public class AbpWeChatCommonTestModule : AbpModule +{ +} diff --git a/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/Crypto/Crypto_Tests.cs b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/Crypto/Crypto_Tests.cs new file mode 100644 index 000000000..01e28a7c7 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.WeChat.Common.Tests/LINGYUN/Abp/WeChat/Common/Crypto/Crypto_Tests.cs @@ -0,0 +1,69 @@ +using LINGYUN.Abp.WeChat.Common.Utils; +using Shouldly; +using System.Xml; +using Xunit; + +namespace LINGYUN.Abp.WeChat.Common.Crypto; + +public class Crypto_Tests : AbpWeChatCommonTestBase +{ + private const string sToken = "QDG6eK"; + private const string sCorpID = "wx5823bf96d3bd56c7"; + private const string sEncodingAESKey = "jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C"; + + [Fact] + public void CryptTest() + { + var wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID); + // string sVerifyMsgSig = HttpUtils.ParseUrl("msg_signature"); + string sVerifyMsgSig = "5c45ff5e21c57e6ad56bac8758b79b1d9ac89fd3"; + // string sVerifyTimeStamp = HttpUtils.ParseUrl("timestamp"); + string sVerifyTimeStamp = "1409659589"; + // string sVerifyNonce = HttpUtils.ParseUrl("nonce"); + string sVerifyNonce = "263014780"; + // string sVerifyEchoStr = HttpUtils.ParseUrl("echostr"); + string sVerifyEchoStr = "P9nAzCzyDtyTWESHep1vC5X9xho/qYX3Zpb4yKa9SKld1DsH3Iyt3tP3zNdtp+4RPcs8TgAE7OaBO+FZXvnaqQ=="; + int ret = 0; + string sEchoStr = ""; + ret = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr, ref sEchoStr); + + ret.ShouldBe(0); + + // string sReqTimeStamp = HttpUtils.ParseUrl("timestamp"); + string sReqTimeStamp = "1409659813"; + // string sReqNonce = HttpUtils.ParseUrl("nonce"); + string sReqNonce = "1372623149"; + + string sRespData = "13488318601234567890123456128"; + string sEncryptMsg = ""; //xml格式的密文 + ret = wxcpt.EncryptMsg(sRespData, sReqTimeStamp, sReqNonce, ref sEncryptMsg); + + ret.ShouldBe(0); + } + + [Fact] + public void DecryptTest() + { + var wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID); + + string sReqMsgSig = "477715d11cdb4164915debcba66cb864d751f3e6"; + // string sReqTimeStamp = HttpUtils.ParseUrl("timestamp"); + string sReqTimeStamp = "1409659813"; + // string sReqNonce = HttpUtils.ParseUrl("nonce"); + string sReqNonce = "1372623149"; + // Post请求的密文数据 + // string sReqData = HttpUtils.PostData(); + string sReqData = ""; + string sMsg = ""; // 解析之后的明文 + var ret = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, sReqData, ref sMsg); + + ret.ShouldBe(0); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(sMsg); + XmlNode root = doc.FirstChild; + string content = root["Content"].InnerText; + + content.ShouldNotBeNullOrWhiteSpace(); + } +}