记得上下班打卡 | git大法好,push需谨慎

Commit aca6d629 authored by zhengfuxin's avatar zhengfuxin

开发银联退款

parent e190463f
......@@ -11,6 +11,9 @@ import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.dragon.channel.unionpay.constant.UnionpayConstant;
import com.liquidnet.service.dragon.channel.unionpay.sdk.AcpService;
import com.liquidnet.service.dragon.channel.unionpay.sdk.SDKConfig;
import com.liquidnet.service.dragon.channel.wepay.resp.AliPayRefundReturnCallBackDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBackDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnCallBackInfoDto;
......@@ -41,6 +44,7 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -56,6 +60,13 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
MqHandleUtil mqHandleUtil;
@Value("${liquidnet.dragon.url}")
private String url;
@Autowired
private SDKConfig sdkConfig;
@Autowired
private AcpService acpService;
//银联 商户号码
@Value("${liquidnet.dragon.unionpay.merchantId}")
private String unionMerchantId;
@Override
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) {
......@@ -128,6 +139,126 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return ResponseDto.failure("退款失败:" + e.getMessage());
}
}
//银联退款
public DragonRefundChannelDto UnionWapPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) {
try {
RefundContentDto contentDto = new RefundContentDto();
DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
String txnTime = DateUtil.format(LocalDateTime.now(),DateUtil.Formatter.yyyyMMddHHmmssTrim);
Map<String, String> data=ObjectUtil.cloneHashMapStringAndString();
/***银联全渠道系统,产品参数,除了encoding自行选择外其他不需修改***/
data.put("version", sdkConfig.getVersion()); //版本号
data.put("encoding", UnionpayConstant.encoding); //字符集编码 可以使用UTF-8,GBK两种方式
data.put("signMethod", sdkConfig.getSignMethod()); //签名方法
data.put("txnType", "04"); //交易类型 04-退货
data.put("txnSubType", "00"); //交易子类型 默认00
data.put("bizType", "000201"); //业务类型
data.put("channelType", "08"); //渠道类型,07-PC,08-手机
/***商户接入参数***/
data.put("merId", unionMerchantId); //商户号码,请改成自己申请的商户号或者open上注册得来的777商户号测试
data.put("accessType", "0"); //接入类型,商户接入固定填0,不需修改
data.put("orderId", refundCode); //商户订单号,8-40位数字字母,不能含“-”或“_”,可以自行定制规则,重新产生,不同于原消费
data.put("txnTime", txnTime); //订单发送时间,格式为yyyyMMddHHmmss,必须取当前时间,否则会报txnTime无效
data.put("currencyCode", "156"); //交易币种(境内商户一般是156 人民币)
data.put("txnAmt", (price.doubleValue() * 100) + ""); //交易金额 单位为分
data.put("backUrl", sdkConfig.getBackUrl()); //后台通知地址,后台通知参数详见open.unionpay.com帮助中心 下载 产品接口规范 网关支付产品接口规范 退货交易 商户通知,其他说明同消费交易的后台通知
/***要调通交易以下字段必须修改***/
data.put("origQryId", paymentId); //****原消费交易返回的的queryId,可以从消费交易后台通知接口中或者交易状态查询接口中获取
// 请求方保留域,
// 透传字段,查询、通知、对账文件中均会原样出现,如有需要请启用并修改自己希望透传的数据。
// 出现部分特殊字符时可能影响解析,请按下面建议的方式填写:
// 1. 如果能确定内容不会出现&={}[]"'等符号时,可以直接填写数据,建议的方法如下。
// data.put("reqReserved", "透传信息1|透传信息2|透传信息3");
// 2. 内容可能出现&={}[]"'符号时:
// 1) 如果需要对账文件里能显示,可将字符替换成全角&={}【】“‘字符(自己写代码,此处不演示);
// 2) 如果对账文件没有显示要求,可做一下base64(如下)。
// 注意控制数据长度,实际传输的数据长度不能超过1024位。
// 查询、通知等接口解析时使用new String(Base64.decodeBase64(reqReserved), UnionpayConstant.encoding);解base64后再对数据做后续解析。
// data.put("reqReserved", Base64.encodeBase64String("任意格式的信息都可以".toString().getBytes(UnionpayConstant.encoding)));
/**请求参数设置完毕,以下对请求参数进行签名并发送http post请求,接收同步应答报文------------->**/
Map<String, String> reqData = acpService.sign(data,UnionpayConstant.encoding); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
String url = sdkConfig.getBackTransUrl(); //交易请求url从配置文件读取对应属性文件acp_sdk.properties中的 acpsdk.backTransUrl
Map<String, String> rspData = acpService.post(reqData, url,UnionpayConstant.encoding);//这里调用signData之后,调用submitUrl之前不能对submitFromData中的键值对做任何修改,如果修改会导致验签不通过
String refundError = "";
/**对应答码的处理,请根据您的业务逻辑来编写程序,以下应答码处理逻辑仅供参考------------->**/
//应答码规范参考open.unionpay.com帮助中心 下载 产品接口规范 《平台接入接口规范-第5部分-附录》
if(!rspData.isEmpty()){
if(acpService.validate(rspData, UnionpayConstant.encoding)){
log.info("验证签名成功");
String respCode = rspData.get("respCode") ;
if(("00").equals(respCode)){
//交易已受理(不代表交易已成功),等待接收后台通知更新订单状态,也可以主动发起 查询交易确定交易状态。
// 创建退款日志
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{orderRefundId, paymentType, data, nowTime, nowTime},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
try {
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, null, DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), code},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
} catch (Exception e) {
e.printStackTrace();
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(JSON.toJSONString(reqData));
contentDto.setResponse(JSON.toJSONString(rspData));
channelDto.setContent(contentDto);
return channelDto;
}
}else{
//其他应答码为失败请排查原因
try {
String refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if(("03").equals(respCode)|| ("04").equals(respCode)|| ("05").equals(respCode)){
refundError="银联返回状态"+respCode+"请稍后确认。";
}else{
refundError=rspData.get("respMsg")==null? "退款失败,原因未知":rspData.get("respMsg").toString();
}
// 修改退款订单
mqHandleUtil.sendMySqlRedis(
SqlMapping.get("dragon_order_refund_error.update"),
new Object[]{nowTime, refundError, refundStatus, code},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
} catch (Exception e) {
e.printStackTrace();
//保存错误信息
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(JSON.toJSONString(reqData));
contentDto.setResponse(JSON.toJSONString(rspData));
channelDto.setContent(contentDto);
return channelDto;
}
channelDto.setResult("error");
channelDto.setMessage(refundError);
contentDto.setRequest(JSON.toJSONString(reqData));
contentDto.setResponse(JSON.toJSONString(rspData));
channelDto.setContent(contentDto);
return channelDto;
}
}else{
log.error("银联退款,验证签名失败");
return null;
}
}else{
//未返回正确的http状态
log.error("银联退款,未获取到返回报文或返回http状态码非200");
return null;
}
return null;
}catch (Exception e){
e.printStackTrace();
log.error("");
return null;
}
}
//微信退款接口
public DragonRefundChannelDto weyPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) {
......
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