Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.1 kB
2
Indexable
Never
 public String generateTokenFacePay(FacePayRequest facePayRequest, String phone, boolean success, String sid) throws JsonProcessingException {
        FacepayTokenEntity tokenEntity = new FacepayTokenEntity();
        tokenEntity.setToken(Utils.generateUid());
        tokenEntity.setPhone(phone);
        tokenEntity.setTransId((facePayRequest.getTransId() != null) ? facePayRequest.getTransId() : "");
        tokenEntity.setSid(sid);
        tokenEntity.setTimestamp((System.currentTimeMillis()));
        tokenEntity.setIsGoodEkyc(success ? "1" : "0");
        tokenEntity.setFromAcc((facePayRequest.getFromAcc() != null) ? facePayRequest.getFromAcc() : "");
        tokenEntity.setToAcc((facePayRequest.getToAcc() != null) ? facePayRequest.getToAcc() : "");
        tokenEntity.setAmount((facePayRequest.getAmount() != null) ? facePayRequest.getAmount() : "");

//        Token số ngẫu nhiên + phone + TransID(mã giao dịch tài chính nếu có) + sid(ID bản ghi eKYC) + time(Thời điểm sinh token)
//        + isGoodEkyc  (Kết quả xác thực giao dịch: 0→ Thất bại, 1-> Thành công) + fromAcc + toAcc + amount
        String dataToSign = tokenEntity.getToken() + tokenEntity.getPhone() + tokenEntity.getTransId() + tokenEntity.getSid()
                + tokenEntity.getTimestamp() + tokenEntity.getIsGoodEkyc() + tokenEntity.getFromAcc() + tokenEntity.getToAcc() + tokenEntity.getAmount();
        log.debug("Data to sign : {}", dataToSign);
        String signature = Security.mc(dataToSign, VNConstants.getShareKey());
        log.debug("Sign to Client: {}", signature);
        tokenEntity.setSignature(signature);
        String dataEncode = objectMapper.writeValueAsString(tokenEntity);
//        String ekycToken = new String(Base64.encode(Utils.getWmfGson().toJson(tokenEntity).getBytes()));
        log.debug("dataEncode: {}", dataEncode);
        String ekycToken = new String(java.util.Base64.getEncoder().encodeToString(dataEncode.getBytes(StandardCharsets.UTF_8)));
        log.debug("ekycToken: {}", ekycToken);
        return ekycToken;
    }
Leave a Comment