public void pay() {
PayWayRecord payWayRecord = psyService.getPayWay(PayWayEnum.TONGTONG.getCode());
Map sendParams = new HashMap<>();
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
sendParams.put("app_id", "s100000040");
sendParams.put("terminal_type", " web");
sendParams.put("version", "1.0");
sendParams.put("service", "fosun.sumpay.cashier.web.trade.order.apply");
sendParams.put("timestamp", simpleDateFormat.format(date.getTime()));
sendParams.put("mer_no", "s100000040");
sendParams.put("trade_code", "T0002");
sendParams.put("user_id", "111");
//sendParams.put("mer_id", "100001465");
sendParams.put("order_no", "D100174978");
sendParams.put("order_time", simpleDateFormat.format(date.getTime()));
sendParams.put("order_amount", "100.00");
sendParams.put("need_notify", "1");
sendParams.put("need_return", "0");
sendParams.put("goods_name", "Preety Toy");
sendParams.put("goods_num", "1");
sendParams.put("goods_type", "1");
// sendParams.put("mer_no", "100001465");
sendParams.put("amount", "1");
SignService signService = new SignServiceImpl();
String aesKey = AESUtil.getKey();
sendParams.put("aes_key", aesKey);
System.out.println(sendParams.get("aes_key"));
//sendParams.put("mor_id", "13131");
List keyList = new ArrayList(sendParams.keySet());
Collections.sort(keyList);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
String keyValue = sendParams.get(key);
sb.append(key).append("=").append(keyValue);
if (i < keyList.size() - 1) {
sb.append("&");
}
}
//SignServiceImpl signService=new SignServiceImpl();
String signMsg = signService.signMsg(sb.toString(), pricateKeyPath, password, charset);
System.out.println("签名之后是:" + signMsg);
sendParams.put("sign", signMsg);
sendParams.put("sign_type", "CERT");
FormBody.Builder builder = new FormBody.Builder();
for (String key : sendParams.keySet()) {
builder.add(key, sendParams.get(key));
}
RequestBody formBody = builder.build();
Request request3 = new Request.Builder()
.url(TEST_URL)
.post(formBody)
// .addHeader("Referer","domain")
//.get()
.build();
Response response= null;
try {
response = okHttpClient.newCall(request3).execute();
String returnMsg=response.body().string();
if (response.isSuccessful()){
// boolean ss= signService.verifyMsg(returnMsg, String.valueOf(sb),publicKeyPath);
// logger.info("[tong query] response is {}", ss);
logger.info("[tong query] response is {}", returnMsg);
}else{
logger.error("[tongfu query] failed");
}
} catch (IOException e) {
e.printStackTrace();
}
}
单元测试返回:
2019-04-25 10:55:25.560 INFO 10908 --- [ main] ALL : [tong query] response is {"resp_code":"EG000001","resp_msg":"验签失败"}
这类错误的问题一般是什么情况造成的,希望大佬给点意见