小编van*_*102的帖子

如何延长java json web令牌的到期时间?

我尝试使用jjwt库在Java中创建Json Web Token

但是当我尝试延长到期时间时,我遇到了问题.

我通过下面的代码尝试.

public class Main {
public static void main(String args[]) {
    byte[] key = new byte[64];
    new SecureRandom().nextBytes(key);
    Date date = new Date();
    long t = date.getTime();
    Date expirationTime = new Date(t + 5000l); // set 5 seconds

    String compact = Jwts.builder().setSubject("Joe").setExpiration(expirationTime).signWith(SignatureAlgorithm.HS256, key).compact();
    System.out.println("compact : " + compact);
    try {
        String unpack = Jwts.parser().setSigningKey(key).parseClaimsJws(compact).getBody().getSubject();
        System.out.println("unpackage 0 : " + unpack);

        // check if the expiration work.
        Thread.sleep(3000);
        System.out.println("unpackage 1 : " + Jwts.parser().setSigningKey(key).parseClaimsJws(compact).getBody().getSubject());

        //extend …
Run Code Online (Sandbox Code Playgroud)

java token jwt

10
推荐指数
1
解决办法
2万
查看次数

在订单确认页面获取订单 ID

我正在为 BigCommerce 开发一个应用程序,我必须将脚本注入订单确认页面。

在脚本中,我想读取当前订单详细信息,所以我试试这个

<script>
 function getOrderDetail(orderId) {
    return fetch("/api/storefront/order/" + orderId, {
      credentials: "include",
    }).then(function (response) {
      return response.json();
    });
  }
let ORDER_ID=123;
getOrderDetail(ORDER_ID).then(data=>{
// do this ,do that,
})

</script>
Run Code Online (Sandbox Code Playgroud)

我没有找到任何与获取当前 Order_ID 相关的文档,我检查了 HTML 代码并尝试

function getOrderId() {
    const orderIdRegex = /\s+orderId:\s'(\d+)',/;
    return document.body.innerHTML.match(orderIdRegex)[1];
  }

Run Code Online (Sandbox Code Playgroud)

我知道如果 UI 发生变化,代码可能会中断。

Shopify,有一个全局变量window.Shopify

我想知道是否有更好的解决方案,或者类似于 Shopify。

更新正确答案

谢谢@MattCoy

<script>
 function getOrderDetail(){
    return fetch("/api/storefront/order/{{checkout.order.id}}", {
      credentials: "include",
    }).then(function (response) {
      return response.json();
    });
  }

 getOrderDetail().then(data=>{
   // …
Run Code Online (Sandbox Code Playgroud)

bigcommerce bigcommerce-checkout-sdk

1
推荐指数
1
解决办法
115
查看次数

标签 统计

bigcommerce ×1

bigcommerce-checkout-sdk ×1

java ×1

jwt ×1

token ×1