From d841ef9b66496dc871ac25eef918bd257521615d Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Thu, 15 Aug 2024 11:05:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(wxapi):=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=8E=A5=E5=8F=A3=E5=9C=A8=E5=AE=89=E5=85=A8=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=AD=BE=E5=90=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interceptors/WechatApiSecureApiInterceptor.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Interceptors/WechatApiSecureApiInterceptor.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Interceptors/WechatApiSecureApiInterceptor.cs index 468fa96f..47d32dbc 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Interceptors/WechatApiSecureApiInterceptor.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Interceptors/WechatApiSecureApiInterceptor.cs @@ -122,7 +122,7 @@ public override async Task BeforeCallAsync(HttpInterceptorContext context, Cance return; string urlpath = GetRequestUrlPath(context.FlurlCall.HttpRequestMessage.RequestUri); - string timestamp = DateTimeOffset.Now.ToLocalTime().ToUnixTimeSeconds().ToString(); + long timestamp = DateTimeOffset.Now.ToLocalTime().ToUnixTimeSeconds(); string postData = "{}"; string postDataEncrypted; if (context.FlurlCall.HttpRequestMessage?.Content is not null) @@ -156,7 +156,7 @@ public override async Task BeforeCallAsync(HttpInterceptorContext context, Cance JsonObject jsonObj = JsonObject.Parse(postData)!.AsObject(); jsonObj["_n"] = GenerateSymmetricEncryptionNonce(16); jsonObj["_appid"] = _appId; - jsonObj["_timestamp"] = timestamp; + jsonObj["_timestamp"] = timestamp; // NOTICE: must be a number NameValueCollection queryParams = HttpUtility.ParseQueryString(context.FlurlCall.HttpRequestMessage!.RequestUri.Query); foreach (string? key in queryParams.AllKeys) @@ -424,11 +424,21 @@ private string GenerateSymmetricEncryptionNonce(int byteLength) return Convert.ToBase64String(bytes); } + private string GenerateSymmetricEncryptionAssociatedData(string urlpath, string appId, long timestamp) + { + return GenerateSymmetricEncryptionAssociatedData(urlpath, appId, timestamp.ToString()); + } + private string GenerateSymmetricEncryptionAssociatedData(string urlpath, string appId, string timestamp) { return $"{urlpath}|{appId}|{timestamp}|{_symmetricNum}"; } + private string GenerateAymmetricSigningData(string urlpath, string appId, long timestamp, string postdata) + { + return GenerateAymmetricSigningData(urlpath, appId, timestamp.ToString(), postdata); + } + private string GenerateAymmetricSigningData(string urlpath, string appId, string timestamp, string postdata) { return $"{urlpath}\n{appId}\n{timestamp}\n{postdata}";