public void refundPay(){
logger.info("=====银联快捷退款开始=====");
// 银联退款逻辑
String hdurl = "http://退款回调路径";
logger.info("======退款回调地址======" + hdurl);
// map存放参数 用于签名 我这只填写自己需要的必填参数
TreeMap<String, String> sendMap = new TreeMap<String, String>();
sendMap.put("Version", "20140728");// 版本号
sendMap.put("MerId", "");// 设置自己的商户号
sendMap.put("MerOrderNo","");//设置自己生产的订单号
sendMap.put("TranDate", new SimpleDateFormat("yyyyMMdd").format(new Date()));// 交易日期
sendMap.put("TranTime", new SimpleDateFormat("HHmmss").format(new Date()));// 交易时间
sendMap.put("OriOrderNo","");// 原始交易订单号 就是之前支付的订单号
sendMap.put("OriTranDate", new SimpleDateFormat("yyyyMMdd").format("原始日期"));//原始支付交易日期
sendMap.put("RefundAmt", new BigDecimal("0.01").multiply(new BigDecimal(100)).setScale(0, BigDecimal.ROUND_HALF_UP).toString());// 退款金额
sendMap.put("TranType", "0401");// 交易类型
sendMap.put("BusiType", "0001");// 业务类型
sendMap.put("MerBgUrl", hdurl);// 回调地址
// 签名
SecssUtil secssUtil = getSecssUtil("存放证书的路径","证书名称");//银联证书路径
secssUtil.sign(sendMap);//将存放参数的map进行签名
if (SecssConstants.SUCCESS.equals(secssUtil.getErrCode())) {//判断签名是否成功
sendMap.put("Signature", secssUtil.getSign());//添加签名
System.out.println("-----------签名成功-------"+ secssUtil.getSign());
}
// 调用退款接口
String unionurl = "https://银联退款路径";
System.out.println("-----------退款路径-------"+ unionurl);
String resp = HttpUtils.send(unionurl, sendMap);//post 请求 form形式提交
System.out.println("-----------响应参数-------" + resp);
Map<String, String> resultMap = new TreeMap<String, String>();
String[] strs = resp.split("&", -1);
resultMap = getDecode(strs, "0401", "0401");//base64解码
String respCode = resultMap.get("respCode");// 响应状态码
String respMsg = resultMap.get("respMsg");// 响应信息
System.out.println("-----------解密-------"+ respCode + " : " + respMsg);
if (respCode.equals("0000")|| respCode.equals("1003")) {// 请求成功
//自行逻辑处理
} else {//退款失败 自行逻辑处理
}
// 跟新数据
}