Commit 43af2247 authored by eddie.woo's avatar eddie.woo

ebs api

parent 3192c8cf
......@@ -54,7 +54,7 @@ org_sync_token=174af08f
dd_pubkey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKUfMPRKV6I5num1dDWcxTrgTjXf5LctsVj0CpbwHE83mmjUO5CAlvA0Fwy30ajCX5sLmsyi+Eu/4uNmM6GQF3kCAwEAAQ==
ebs_call_url=http://172.20.201.201:8020/ebs-proxy-test/dts
ebs_call_url=http://172.20.3.109:8020/ebs-proxy-test/dts
#tableau config
tableau_unreturned_tax=http://10.158.230.16:8890/trusted/%s/views/Didi_Tax_20190307/sheet8?iframeSizedToWindow=true&:embed=y&:showAppBanner=false&:display_count=no&:showVizHome=no&:toolbar=no
......
......@@ -2,6 +2,7 @@ package pwc.taxtech.atms.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Lists;
import org.junit.Test;
......@@ -26,14 +27,21 @@ import pwc.taxtech.atms.dto.ebsdto.*;
import pwc.taxtech.atms.dto.organization.DDSyncOrgInfo;
import pwc.taxtech.atms.dto.organization.OrgSyncData;
import pwc.taxtech.atms.entity.*;
import pwc.taxtech.atms.exception.ServiceException;
import pwc.taxtech.atms.security.dd.DtsTokenService;
import pwc.taxtech.atms.service.EbsApiService;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.annotation.Resource;
import javax.crypto.Cipher;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
public class EbsApiServiceImplTest extends CommonIT {
......@@ -52,6 +60,9 @@ public class EbsApiServiceImplTest extends CommonIT {
@Value("${org_sync_token}")
private String token;
@Resource
private DtsTokenService dtsTokenService;
private static String ebsCallUrl = "http://172.20.201.201:8020/ebs-proxy-test/dts";
private static int corePoolSize = 15;
......@@ -698,4 +709,66 @@ public class EbsApiServiceImplTest extends CommonIT {
return new Integer(1);
}
}
public String encryptInput(){
BASE64Encoder base64 = new BASE64Encoder();
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] encodeData;
try {
byte[] publicKey = base64Decoder.decodeBuffer("MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKUfMPRKV6I5num1dDWcxTrgTjXf5LctsVj0CpbwHE83mmjUO5CAlvA0Fwy30ajCX5sLmsyi+Eu/4uNmM6GQF3kCAwEAAQ==");
String nonce = generateNonce();
String sDate = generateDate();
long rNum = generateRandomNumber();
String inputStr1 = sDate + "@@" + "DTS" + "@@" + nonce+rNum;
byte[] data1 = inputStr1.getBytes();
logger.debug("原文:" + inputStr1);
encodeData = encryptByPublicKey(data1, publicKey);
logger.debug("公钥加密后:" + base64.encode(encodeData));
} catch (Exception ex) {
throw new ServiceException("cus" + ex);
}
return base64.encode(encodeData);
}
private String generateNonce() throws Exception {
String dateTimeString = Long.toString(System.currentTimeMillis());
byte[] nonceByte = dateTimeString.getBytes();
return Base64.encodeBase64String(nonceByte);
}
private String generateDate() throws Exception {
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
Date today = Calendar.getInstance().getTime();
String created = dateFormatter.format(today);
return created;
}
private long generateRandomNumber() throws Exception {
final double d = Math.random();
final long num = (int)(d*100000000000000L);
return num;
}
private static byte[] encryptByPublicKey(byte[] data, byte[] key) throws Exception {
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return cipher.doFinal(data);
}
public static void main(String[] args) {
System.out.println("--------------");
System.out.println(new EbsApiServiceImplTest().encryptInput());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment