在公司业务中,对接汇潮支付,--------该需求是调用汇潮的支付接口,他们作为中台,由他们调用支付宝接口
在异步回调的时候,遇到了“参数通过 post 方式提交, Content-Type: application/x-www-form-urlencoded ”,回调参数接收不到,无法转化,的问题。
解决思路如下,以往都是用json的方式,所以在controller里面写了@RequestBody,实际是,直接用一个对象接收,不用写@RequestBody,然后下面在serviceImpl里面,代码转换。
贴出代码
代码语言:javascript复制 /**
* 支付方式异步通知接口
* @param getHcPayRequest 异步通知获得json字符串
* @return 异步通知结果 success/fail
*/
/*汇潮支付--支付方式异步通知接口*/
public String notifyInfos(HcPayRequest getHcPayRequest) {
logger.info("汇潮异步回调参数" JSON.toJSONString(getHcPayRequest));
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);//针对fastjson解析 mq里面的redis获取值的解析,不然会出错
String merchantOutOrderNo =getHcPayRequest.getMerchantOutOrderNo();;//商户订单号
String merid = getHcPayRequest.getMerid();//商户号
String msg =getHcPayRequest.getMsg();//订单的详细信息 msg->pay Money
String res = null;
try {
res = URLDecoder.decode(msg,"UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("汇潮异步回调参数解码失败-" JSON.toJSONString(msg));
e.printStackTrace();
}
JSONObject jsonObject = JSON.parseObject(res);
System.out.println(getHcPayRequest.toString());
String orderNo =getHcPayRequest.getOrderNo();//平台订单号
String orderMoney = (String)jsonObject.get( "payMoney" );// 支付金额
/**
* 通知参数样例:
* 在汇潮的接口文档里面有这个
* merchantOutOrderNo=2017091316410597&merid=
* yft2017082500005&msg={"payMoney":"1.00"}&noncestr=adfasdfqwer&orderNo=20170913164
* 1128501&payResult=1&sign= 078c2637c96d714880fdb3364d440b51
*/
String trasactionId = orderNo;//平台订单编号 比如支付宝平台
try {
if (redisTemplate.hasKey(Constants.HC_PREFIX trasactionId)) { //放进Redis
logger.info("hcpay有重复通知" trasactionId);
return "success";
} else {
redisTemplate.opsForValue().set(Constants.HC_PREFIX trasactionId, "1", 2880, TimeUnit.MINUTES);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("hcpay写redis出错" e.getMessage());
}
HcPayRequest hcPayRequestnew = new HcPayRequest();
hcPayRequestnew.setMerchantOutOrderNo(merchantOutOrderNo);
hcPayRequestnew.setOrderNo(orderNo);
hcPayRequestnew.setAmount(orderMoney);
EvaFeeInfo evaFeeInfoNew =(EvaFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX Constants.PAY_PG merchantOutOrderNo);
if(evaFeeInfoNew!=null){
logger.info("hc汇潮支付redis获取的param" JSON.toJSONString(evaFeeInfoNew));
if (Constants.PAY_PG.equals(evaFeeInfoNew.getFlag())) {//评估费
EvaFeeInfo evaFeeInfo = new EvaFeeInfo();
evaFeeInfo.setEvaAmount(evaFeeInfoNew.getEvaAmount());//
evaFeeInfo.setUserId(evaFeeInfoNew.getUserId());//
evaFeeInfo.setMobile(evaFeeInfoNew.getMobile());//
evaFeeInfo.setCouponId(evaFeeInfoNew.getCouponId());//
evaFeeInfo.setRepayNo(orderNo);
evaFeeInfo.setTradeNo(evaFeeInfoNew.getTradeNo());//商家唯一标示 订单号
evaFeeInfo.setCurrentCash(evaFeeInfoNew.getCurrentCash());//
evaFeeInfo.setIsUseCash(evaFeeInfoNew.getIsUseCash());//
hcPayRequestnew.setFlag(Constants.PAY_PG);
try {
logger.info("评估费发送rabbitmq");
rabbitmqProducerProxy.convertAndSend("evaFee.ibank", evaFeeInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
RecFeeInfo recFeeInfoNew =(RecFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX Constants.PAY_TJ merchantOutOrderNo);
if(recFeeInfoNew!=null){
logger.info("hc汇潮支付redis获取的param" JSON.toJSONString(recFeeInfoNew));
if (Constants.PAY_TJ.equals(recFeeInfoNew.getFlag())) {//推荐费
RecFeeInfo recFeeInfo = new RecFeeInfo();
recFeeInfo.setRecAmount(recFeeInfoNew.getRecAmount());//
recFeeInfo.setUserId(recFeeInfoNew.getUserId());//
recFeeInfo.setMobile(recFeeInfoNew.getMobile());//
recFeeInfo.setBorrowPeriods(recFeeInfoNew.getBorrowPeriods());//借款周期//
recFeeInfo.setLoanAmount(recFeeInfoNew.getLoanAmount());//
// recFeeInfo.setType(hcPayRequest.getType());--------------------------------------------
recFeeInfo.setRepayNo(orderNo);//
recFeeInfo.setTradeNo(recFeeInfoNew.getTradeNo());//商家唯一标示 订单号
recFeeInfo.setCouponId(recFeeInfoNew.getCouponId());//
recFeeInfo.setAppCodeList(recFeeInfoNew.getAppCodeList());//
recFeeInfo.setCurrentCash(recFeeInfoNew.getCurrentCash());//
recFeeInfo.setIsUseCash(recFeeInfoNew.getIsUseCash());//
hcPayRequestnew.setFlag(Constants.PAY_TJ);
try {
logger.info("推荐费发送rabbitmq order");
rabbitmqProducerProxy.convertAndSend("recFee.ibank", recFeeInfo);
//去掉 发给 user的推荐费
// logger.info("推荐费发送rabbitmq user");
// rabbitmqProducerProxy.convertAndSend("recUser.ibank", recFeeInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
RechargeFeeInfo rechargeFeeInfoNew =(RechargeFeeInfo)redisTemplate.opsForValue().get(Constants.HC_PREFIX Constants.PAY_XJ merchantOutOrderNo);
if(rechargeFeeInfoNew!=null){
if(Constants.PAY_XJ.equals(rechargeFeeInfoNew.getFlag())){//充值现金券
RechargeFeeInfo rechargeFeeInfo = new RechargeFeeInfo();
rechargeFeeInfo.setAccountNumber(rechargeFeeInfoNew.getAccountNumber());//手机号//
rechargeFeeInfo.setAmount(rechargeFeeInfoNew.getAmount());//
rechargeFeeInfo.setCashId(rechargeFeeInfoNew.getCashId());//
rechargeFeeInfo.setOperStatus(1);// /**充值是否成功 0:失败 1:成功*/
rechargeFeeInfo.setRechargeFlowNo(orderNo);
rechargeFeeInfo.setTradeNo(rechargeFeeInfoNew.getTradeNo());//商家唯一标示 订单号
rechargeFeeInfo.setStatusMsg("1");//汇潮支付 1 为成功(目前只有成功才通知)
hcPayRequestnew.setFlag(Constants.PAY_XJ);
try {
logger.info("hc汇潮支付充值现金券发送rabbitmq order");
rabbitmqProducerProxy.convertAndSend("rechargeFee.ibank", rechargeFeeInfo);
} catch (Exception e) {
e.printStackTrace();
logger.error("hc汇潮支付现金券充值 异常", e);
}
}
}
payLogService.saveHcPay(hcPayRequestnew,Constants.REPAY_STATUS_ZERO );
logger.info("汇潮支付支付成功" orderNo);
return "success";
}
代码语言:javascript复制
代码语言:javascript复制
代码语言:javascript复制/**
* 支付方式异步通知接口
* @param getHcPayRequest 异步通知获得json字符串
* @return 异步通知结果 success/fail
*/
/*汇潮支付--支付方式异步通知接口*/
@RequestMapping(value = "/notifyInfos",method = RequestMethod.POST)
public String notifyInfos( HcPayRequest getHcPayRequest){
String toSuccessOrFail = hcPayService.notifyInfos(getHcPayRequest);
return toSuccessOrFail;
}