function TfrmSimple.BuildTokenFR(path, key: string; validtime:Int64): string; var LToken: TJWT; begin LToken := TJWT.Create; try LToken.Claims.Subject := path; LToken.Claims.IssuedAt := Now; LToken.Claims.Expiration := Now + validtime; LToken.Claims.Issuer := ''; LToken.Claims.JWTId:=''; result:=TJOSE.SHA256CompactToken(key,LToken); finally LToken.Free; end; end;
直接上代码,下面是调用代码:
memoCompact.Lines.Add( BuildTokenFR('order.cpt','123456',30*60*1000));
返回结果:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvcmRlci5jcHQiLCJpYXQiOjE1OTQwMzAzNTIsImV4cCI6MTU3MTE0MDMwMzUyfQ.DsceM8yrgp8S4-2Xor7de11YXq9eULYkD2-blY6B2BE
开源地址: