using JWT.Algorithms;
using JWT;
using JWT.Serializers;
private string GetToken(string timeStamp, string deptName, string doctorName, string idNo)
{
string token = string.Empty;
string appID = config.AppID;
string secretKey = config.AppSecret;
long expTimeStamp = Convert.ToInt64(timeStamp) + 600000;
var payload = new Dictionary<string, object>
{
{ "jti",config.AppID},
{ "name", config.AppName },
{ "orgName",config.HospitalName},
{ "deptName",deptName},
{ "doctorName",doctorName},
{ "idNo",idNo},
{ "idNoType","01"},
{ "nbf", timeStamp },
{ "exp", expTimeStamp.ToString() },
{ "iat", timeStamp}
};
StringBuilder builder = new StringBuilder();
foreach (var value in payload)
{
builder.Append(value.Key);
builder.Append(":");
builder.Append(value.Value);
builder.Append(" ");
}
string logPayLoad = builder.ToString();
LoggerSimple.WriteInfo($"载荷:{logPayLoad}");
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
token = encoder.Encode(payload, secretKey);
LoggerSimple.WriteInfo($"生成token:{token}");
return token;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53