增加测试退款
This commit is contained in:
parent
dff8fe7d25
commit
021a5b6fa0
@ -6,7 +6,6 @@ import co.intella.crypto.KeyReader;
|
|||||||
import co.intella.model.IntegratedRequestBody;
|
import co.intella.model.IntegratedRequestBody;
|
||||||
import co.intella.model.RequestHeader;
|
import co.intella.model.RequestHeader;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.xhpc.order.intella.Utility;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
@ -17,7 +16,13 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static co.intella.net.HttpRequestUtil.getEncryptRequestJson;
|
import static co.intella.net.HttpRequestUtil.getEncryptRequestJson;
|
||||||
|
|
||||||
@ -31,8 +36,10 @@ public class IntellaTest {
|
|||||||
final static String MchId = "SLGtest"; // your MchId (login account)
|
final static String MchId = "SLGtest"; // your MchId (login account)
|
||||||
final static String RefundKey = "13b7994fae9387c2e1b598524ba1204ae404d02fa67016ed86c74183ab1aabcd"; // SHA256 encoded
|
final static String RefundKey = "13b7994fae9387c2e1b598524ba1204ae404d02fa67016ed86c74183ab1aabcd"; // SHA256 encoded
|
||||||
final static String DeviceId = "01300123"; // for EasyCard API
|
final static String DeviceId = "01300123"; // for EasyCard API
|
||||||
|
final static String DeviceInfo = "skb0001";
|
||||||
|
|
||||||
public static String SHA256(String data, String key) throws NoSuchAlgorithmException {
|
|
||||||
|
public static String SHA256(String data) throws NoSuchAlgorithmException {
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
byte[] encodedhash = digest.digest(data.getBytes(StandardCharsets.UTF_8));
|
byte[] encodedhash = digest.digest(data.getBytes(StandardCharsets.UTF_8));
|
||||||
return bytesToHex(encodedhash);
|
return bytesToHex(encodedhash);
|
||||||
@ -50,24 +57,28 @@ public class IntellaTest {
|
|||||||
return hexString.toString();
|
return hexString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() throws Exception {
|
|
||||||
|
|
||||||
File der = new File("C:\\intella\\pub.der");
|
final static String orderNo = "20222061515350342327";
|
||||||
|
final static String fee = "1";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void paymentTest() throws Exception {
|
||||||
|
|
||||||
|
File der = new File("D:\\intella\\pub.der");
|
||||||
InputStream is = new FileInputStream(der);
|
InputStream is = new FileInputStream(der);
|
||||||
Map<String, String> rm = new HashMap<>();
|
Map<String, String> rm = new HashMap<>();
|
||||||
rm.put("MchId", MchId);
|
rm.put("MchId", MchId);
|
||||||
rm.put("Method", Method);
|
rm.put("Method", Method);
|
||||||
rm.put("ServiceType", ServiceType);
|
rm.put("ServiceType", ServiceType);
|
||||||
String TradeKey = SHA256("0000", "8651731586517315"); // SHA256 encoded
|
String TradeKey = SHA256("0000").toLowerCase(Locale.ROOT); // SHA256 encoded
|
||||||
rm.put("TradeKey", TradeKey.toLowerCase(Locale.ROOT));
|
rm.put("TradeKey", TradeKey);
|
||||||
Date date = Calendar.getInstance().getTime();
|
Date date = Calendar.getInstance().getTime();
|
||||||
String format = DateUtil.format(date, "yyyyMMddHHmmss");
|
String format = DateUtil.format(date, "yyyyMMddHHmmss");
|
||||||
rm.put("CreateTime", format);
|
rm.put("CreateTime", format);
|
||||||
rm.put("DeviceInfo","80836000050001");
|
rm.put("DeviceInfo", DeviceInfo);
|
||||||
rm.put("StoreOrderNo","80836000050001022205251204372344");
|
rm.put("StoreOrderNo", orderNo);
|
||||||
rm.put("Body","ChargingFee");
|
rm.put("Body","ChargingFee");
|
||||||
rm.put("TotalFee","1");
|
rm.put("TotalFee", fee);
|
||||||
rm.put("CardId","4477578739678291");
|
rm.put("CardId","4477578739678291");
|
||||||
rm.put("ExtenNo","879");
|
rm.put("ExtenNo","879");
|
||||||
rm.put("ExpireDate","2703");
|
rm.put("ExpireDate","2703");
|
||||||
@ -106,4 +117,63 @@ public class IntellaTest {
|
|||||||
System.out.println(resp);
|
System.out.println(resp);
|
||||||
System.out.println("--");
|
System.out.println("--");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
private void refundTest() throws Exception {
|
||||||
|
File der = new File("D:\\intella\\pub.der");
|
||||||
|
InputStream is = new FileInputStream(der);
|
||||||
|
Map<String, String> rm = new HashMap<>();
|
||||||
|
rm.put("MchId", MchId);
|
||||||
|
rm.put("Method", "00000");
|
||||||
|
rm.put("ServiceType", "Refund");
|
||||||
|
String TradeKey = SHA256("0000").toLowerCase(Locale.ROOT); // SHA256 encoded
|
||||||
|
rm.put("TradeKey", TradeKey);
|
||||||
|
Date date = Calendar.getInstance().getTime();
|
||||||
|
String format = DateUtil.format(date, "yyyyMMddHHmmss");
|
||||||
|
rm.put("CreateTime", format);
|
||||||
|
rm.put("DeviceInfo", DeviceInfo);
|
||||||
|
rm.put("StoreOrderNo", orderNo);
|
||||||
|
|
||||||
|
rm.put("StoreRefundNo", "RF202206151441003712"); // 长度必须20位
|
||||||
|
rm.put("RefundKey", TradeKey.toLowerCase(Locale.ROOT));
|
||||||
|
rm.put("RefundFee", fee);
|
||||||
|
rm.put("RefundedMsg", "退费");
|
||||||
|
// rm.put("Data", "{\"DeviceInfo\":\"skb0001\",\"StoreOrderNo\":\"PO-20180715-001\",\"Body\":\"Chicken Rice\",\"TotalFee\":\"1\"}");//消費者主掃
|
||||||
|
PublicKey rsaPubKey = KeyReader.loadPublicKeyFromDER(der);
|
||||||
|
SecretKey aesKey = AesCryptoUtil.generateSecreteKey();
|
||||||
|
System.out.println(getEncryptRequestJson(rm, rsaPubKey, aesKey));
|
||||||
|
String rawJson = (new Gson()).toJson(rm);
|
||||||
|
RequestHeader header = (RequestHeader)(new Gson()).fromJson(rawJson, RequestHeader.class);
|
||||||
|
Map<String, String> dataMap = new HashMap();
|
||||||
|
ArrayList<String> ignoreList = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
this.add("Method");
|
||||||
|
this.add("ServiceType");
|
||||||
|
this.add("MchId");
|
||||||
|
this.add("CreateTime");
|
||||||
|
this.add("TradeKey");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Iterator var10 = rm.keySet().iterator();
|
||||||
|
|
||||||
|
String key;
|
||||||
|
while(var10.hasNext()) {
|
||||||
|
key = (String)var10.next();
|
||||||
|
if (!ignoreList.contains(key)) {
|
||||||
|
dataMap.put(key, rm.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IntegratedRequestBody body = new IntegratedRequestBody();
|
||||||
|
body.setRequestData((new Gson()).toJson(dataMap));
|
||||||
|
body.setRequestHeader(header);
|
||||||
|
String json = (new Gson()).toJson(body);
|
||||||
|
System.out.println(json);
|
||||||
|
System.out.println("--");
|
||||||
|
String resp = Utility.doRequest(API_URL, is, rm);
|
||||||
|
System.out.println(resp);
|
||||||
|
System.out.println("--");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user