Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
7
Indexable
Never
public static String createFacePayToken(String phone, String sessionId) {
        try {
            MemCacheCommon cache = MemCacheCommon.getInstance();
            String key = cache.findConfig("FACEPAY_KEY", "VBBˣretKey#*Da@2024");
            HmacUtils hmac256 = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key.getBytes());
            long timeStamp = System.currentTimeMillis();
            String token = UUID.randomUUID().toString();
            String signedData = new String(java.util.Base64.getEncoder().encode(hmac256.hmac(phone + sessionId + token + timeStamp)));
            FacePayTokenEntity facePayTokenEntity = FacePayTokenEntity.builder()
                    .timestamp(timeStamp)
                    .token(token)
                    .signature(signedData)
                    .build();
            String tokenResult = new String(java.util.Base64.getEncoder().encode(Common.GSON.toJson(facePayTokenEntity).getBytes()));
            log.info("facePayTokenEntity = {} | tokenResult={}", Common.GSON.toJson(facePayTokenEntity), tokenResult);
            return tokenResult;
        } catch (Exception ex) {
            log.error("createFacePayToken ex: {}", ex.toString());
        }
        return "";
    }
Leave a Comment