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}";