refactor(tenpayv2): 优化签名生成逻辑

This commit is contained in:
Fu Diwei
2022-02-05 19:16:11 +08:00
parent 64c0bf5bd8
commit 3ebe0c1517
3 changed files with 60 additions and 16 deletions

View File

@@ -0,0 +1,25 @@
using System;
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using Newtonsoft.Json;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
{
internal static class JwtUtility
{
private static readonly Lazy<IJwtEncoder> _encoder = new Lazy<IJwtEncoder>(() =>
{
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer(new JsonSerializer() { NullValueHandling = NullValueHandling.Ignore });
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
return encoder;
}, isThreadSafe: true);
public static string EncodeWithHS256(object payload, string secret)
{
return _encoder.Value.Encode(payload, secret);
}
}
}