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

Commit 424b7b69 authored by zhengfuxin's avatar zhengfuxin

修改 notify dragon

parent dbd81a91
...@@ -40,3 +40,5 @@ liquidnet: ...@@ -40,3 +40,5 @@ liquidnet:
certs-path: /data/certs/dragon/unionpay/test certs-path: /data/certs/dragon/unionpay/test
certs-prefix: acp_prod certs-prefix: acp_prod
pfx-pwd: '520360' pfx-pwd: '520360'
apple:
urlVerify: https://sandbox.itunes.apple.com/verifyReceipt
...@@ -39,4 +39,6 @@ liquidnet: ...@@ -39,4 +39,6 @@ liquidnet:
refund-url: https://gateway.95516.com refund-url: https://gateway.95516.com
certs-path: /data/certs/dragon/unionpay/test certs-path: /data/certs/dragon/unionpay/test
certs-prefix: acp_test certs-prefix: acp_test
pfx-pwd: '520360' pfx-pwd: '520360'
\ No newline at end of file apple:
urlVerify: https://sandbox.itunes.apple.com/verifyReceipt
\ No newline at end of file
...@@ -56,6 +56,7 @@ public class DragonServiceCommonBiz { ...@@ -56,6 +56,7 @@ public class DragonServiceCommonBiz {
// orders.setFinishedAt(); // orders.setFinishedAt();
orders.setCreatedAt(LocalDateTime.now()); orders.setCreatedAt(LocalDateTime.now());
// orders.setUpdatedAt(); // orders.setUpdatedAt();
orders.setReceiptData(dragonPayBaseReqDto.getReceiptData());
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
...@@ -72,7 +73,7 @@ public class DragonServiceCommonBiz { ...@@ -72,7 +73,7 @@ public class DragonServiceCommonBiz {
, orders.getNotifyUrl(), orders.getNotifyStatus(),orders.getPaymentType(), , orders.getNotifyUrl(), orders.getNotifyStatus(),orders.getPaymentType(),
orders.getPaymentId(), orders.getPaymentAt() orders.getPaymentId(), orders.getPaymentAt()
, orders.getFinishedAt(), orders.getCreatedAt() , orders.getFinishedAt(), orders.getCreatedAt()
, orders.getUpdatedAt(),orders.getDeletedAt()} , orders.getUpdatedAt(),orders.getDeletedAt(),orders.getReceiptData()}
,DragonConstant.MysqlRedisQueueEnum.DRAGON_PAY_KEY.getCode() ,DragonConstant.MysqlRedisQueueEnum.DRAGON_PAY_KEY.getCode()
); );
log.info("redis-queue-sendMySqlRedis->耗时:{}",(System.currentTimeMillis() - startTime)+"毫秒"); log.info("redis-queue-sendMySqlRedis->耗时:{}",(System.currentTimeMillis() - startTime)+"毫秒");
......
...@@ -65,6 +65,17 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat ...@@ -65,6 +65,17 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
//通知商户 //通知商户
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto)); return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
} }
@Transactional(rollbackFor = Exception.class)
public void completeSuccessOrderNoNotify(DragonOrdersDto dragonOrdersDto, String bankTrxNo, LocalDateTime timeEnd, String bankReturnMsg) {
log.info("订单支付成功!");
dragonOrdersDto.setPaymentAt(timeEnd);
dragonOrdersDto.setPaymentId(bankTrxNo);// 设置银行流水号
dragonOrdersDto.setStatus(Integer.parseInt(DragonConstant.PayStatusEnum.STATUS_PAID.getCode()));
//更新缓存
dataUtils.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto);
//修改订单状态
dragonServiceCommonBiz.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto.getStatus(),bankTrxNo);
}
/** /**
* 支付失败方法 * 支付失败方法
......
package com.liquidnet.service.dragon.channel.strategy.impl;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler;
import com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonOrdersDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto;
import com.liquidnet.service.dragon.service.impl.DragonOrdersServiceImpl;
import com.liquidnet.service.dragon.utils.DataUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: PayChannelStrategyAlipayImpl
* @Package com.liquidnet.service.dragon.channel.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/13 13:06
*/
@Slf4j
@Component
@StrategyPayChannelHandler(DragonConstant.PayChannelEnum.APPLEPAY)
public class ApplepayImpl extends AbstractPayChannelStrategyImpl {
@Autowired
private DataUtils dataUtils;
@Autowired
private DragonOrdersServiceImpl dragonOrdersService;
@Autowired
private DragonPayBiz dragonPayBiz;
public void completeSuccessOrder(DragonOrdersDto dragonOrdersDto,String code,String result){
this.completeSuccessOrderNoNotify(dragonOrdersDto, code, LocalDateTime.now(), result);
}
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
return null;
}
@Override
public String dragonNotify(HttpServletRequest request, String payType, String deviceFrom) {
return null;
}
@Override
public DragonPayOrderQueryRespDto checkOrderStatus(String code) {
DragonOrdersDto ordersDto = dataUtils.getPayOrderByCode(code);
//调用 苹果效验
String verifyResult=dragonOrdersService.buyAppVerify(ordersDto.getReceiptData());
if (verifyResult == null) {
// 苹果服务器没有返回验证结果
log.info("苹果支付查询(checkOrderStatus),查不到订单信息");
return null;
} else {
JSONObject job = JSONObject.parseObject(verifyResult);
String states = job.getString("status");
if (states.equals("0")) { // 前端所提供的收据是有效的 验证成功
DragonPayOrderQueryRespDto respDto = dragonPayBiz.buildPayOrderQueryRespDto(ordersDto);
respDto.setStatus(Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_PAID.getCode()));
return respDto;
}
}
return null;
}
}
package com.liquidnet.service.dragon.controller; package com.liquidnet.service.dragon.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author AnJiabin <anjiabin@zhengzai.tv> * @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0 * @version V1.0
...@@ -13,11 +9,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -13,11 +9,11 @@ import org.springframework.web.bind.annotation.RestController;
* @Copyright: LightNet @ Copyright (c) 2021 * @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/9 12:29 * @date 2021/7/9 12:29
*/ */
@Slf4j /*@Slf4j
@RestController @RestController
@RequestMapping("pay") @RequestMapping("pay")
public class PayController { public class PayController {
/* @Autowired @Autowired
private IDragonOrdersService dragonOrdersService; private IDragonOrdersService dragonOrdersService;
*//** *//**
...@@ -79,10 +75,10 @@ public class PayController { ...@@ -79,10 +75,10 @@ public class PayController {
dragonPayBaseReqDto.setType(type); dragonPayBaseReqDto.setType(type);
dragonPayBaseReqDto.setPrice(price); dragonPayBaseReqDto.setPrice(price);
dragonPayBaseReqDto.setAuthCode(authCode); dragonPayBaseReqDto.setAuthCode(authCode);
// if(StringUtil.isNotNull(name)&&name.length()>=32){ if(StringUtil.isNotNull(name)&&name.length()>=32){
// name = name.substring(0,32); name = name.substring(0,32);
// } }
dragonPayBaseReqDto.setName("正在现场"); dragonPayBaseReqDto.setName(name);
// if(StringUtil.isNotNull(detail)&&detail.length()>=64){ // if(StringUtil.isNotNull(detail)&&detail.length()>=64){
// detail = detail.substring(0,64); // detail = detail.substring(0,64);
// } // }
...@@ -141,5 +137,5 @@ public class PayController { ...@@ -141,5 +137,5 @@ public class PayController {
rs.put("code", code); rs.put("code", code);
rs.put("result", "" + respDto); rs.put("result", "" + respDto);
return ResponseDto.success(rs); return ResponseDto.success(rs);
}*/ }
} }*/
package com.liquidnet.service.dragon.controller; package com.liquidnet.service.dragon.controller;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.service.IDragonOrdersService; import com.liquidnet.service.dragon.service.IDragonOrdersService;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/** /**
* @author AnJiabin <anjiabin@zhengzai.tv> * @author AnJiabin <anjiabin@zhengzai.tv>
...@@ -41,4 +45,72 @@ public class PayNotifyController { ...@@ -41,4 +45,72 @@ public class PayNotifyController {
public String dragonNotify(@PathVariable("payType") String payType,@PathVariable("deviceFrom") String deviceFrom,HttpServletRequest request, HttpServletResponse respone) throws Exception { public String dragonNotify(@PathVariable("payType") String payType,@PathVariable("deviceFrom") String deviceFrom,HttpServletRequest request, HttpServletResponse respone) throws Exception {
return dragonOrdersService.dragonNotify(request,payType,deviceFrom); return dragonOrdersService.dragonNotify(request,payType,deviceFrom);
} }
/**
* 苹果内购
*/
@PostMapping("/apple/purchase")
@ApiOperation("苹果内购回调")
@ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "payType", value = "支付类型:alipay,wepay,unionpay,applepay", example = "unionpay"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "deviceFrom", value = "设备来源:web,wap,app,js,apple,micropay,inner", example = "wap"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "业务类型:TICKET,PRODUCT,COST,MBEANS,LIVE,VIDEO,VIP,CLUB,STRAWBERRY", example = "TICKET"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "price", value = "支付金额", example = "0.1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "name", value = "订单名称", example = "测试订单001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "detail", value = "订单描述", example = "测试订单001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderId", value = "订单id", example = "orderId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderCode", value = "订单编号", example = "ORDER0001"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "clientIp", value = "客户端ip", example = "127.0.0.1"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "devdragon.zhengzai.tv"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "createDate", value = "订单创建时间", example = "2021-11-10 13:00:00"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "expireTime", value = "订单过期时间", example = "1000"),
@ApiImplicitParam(type = "form", required = false, dataType = "String", name = "authCode", value = "付款码", example = "1000"),
})
public ResponseDto<DragonPayBaseRespDto> dragonNotifyApple(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") String payType,
@RequestParam(value = "deviceFrom") @NotNull(message = "设备来源不能为空") String deviceFrom,
@RequestParam(value = "openId", required = false) String openId,
@RequestParam(value = "type") @NotNull(message = "业务类型不能为空") String type,
@RequestParam(value = "price") @NotNull(message = "支付金额不能为空") BigDecimal price,
@RequestParam(value = "name") @NotNull(message = "订单名称不能为空") String name,
@RequestParam(value = "detail") @NotNull(message = "订单描述不能为空") String detail,
@RequestParam(value = "orderCode") @NotNull(message = "订单编号不能为空") String orderCode,
@RequestParam(value = "orderId", required = false) String orderId,
@RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp,
@RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl,
@RequestParam(value = "returnUrl", required = false) String returnUrl,
@RequestParam(value = "showUrl", required = false) String showUrl,
@RequestParam(value = "createDate", required = true) String createDate,
@RequestParam(value = "expireTime", required = true) String expireTime,
@RequestParam(value = "receiptData", required = true) String receiptData,
@RequestParam(value = "transactionId", required = true) String transactionId
) throws Exception {
long startTime = System.currentTimeMillis();
DragonPayBaseReqDto dragonPayBaseReqDto = DragonPayBaseReqDto.getNew();
dragonPayBaseReqDto.setPayType(payType);
dragonPayBaseReqDto.setDeviceFrom(deviceFrom);
dragonPayBaseReqDto.setType(type);
dragonPayBaseReqDto.setPrice(price);
if(StringUtil.isNotNull(name)&&name.length()>=32){
name = name.substring(0,32);
}
dragonPayBaseReqDto.setName(name);
dragonPayBaseReqDto.setDetail("正在现场");
dragonPayBaseReqDto.setOrderCode(orderCode);
if(orderId!=null) {
dragonPayBaseReqDto.setOrderId(orderId);
}
dragonPayBaseReqDto.setClientIp(clientIp);
dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
dragonPayBaseReqDto.setReturnUrl(returnUrl);
dragonPayBaseReqDto.setShowUrl(showUrl);
dragonPayBaseReqDto.setCreateDate(createDate);
dragonPayBaseReqDto.setExpireTime(expireTime);
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
dragonPayBaseReqDto.setReceiptData(receiptData);
dragonPayBaseReqDto.setTransactionId(transactionId);
//调用苹果
return ResponseDto.success( dragonOrdersService.dragonNotifyApple(dragonPayBaseReqDto));
}
} }
...@@ -73,6 +73,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -73,6 +73,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
private String unionMerchantId; private String unionMerchantId;
@Autowired @Autowired
private UnionpayBiz unionpayBiz; private UnionpayBiz unionpayBiz;
@Override @Override
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) { public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) {
try { try {
...@@ -88,7 +89,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -88,7 +89,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonRefundChannelDto dto = null; DragonRefundChannelDto dto = null;
String localWePayCallBackUrl = url + "/refund/callBack/wepay"; String localWePayCallBackUrl = url + "/refund/callBack/wepay";
String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay"; String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay";
String localUnionPayCallBackUrl= url+"/refund/callBack/union"; String localUnionPayCallBackUrl = url + "/refund/callBack/union";
if (insertResult) { if (insertResult) {
switch (paymentType) { switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY: case DragonConstant.REFUND_TYPE_APP_ALIPAY:
...@@ -122,16 +123,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -122,16 +123,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime); dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_APPLET_DOUYIN: case DragonConstant.REFUND_TYPE_APPLET_DOUYIN:
dataUtils.setOrderCode(orderRefundCode,orderCode); dataUtils.setOrderCode(orderRefundCode, orderCode);
dto = douYinRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localDouYinCallBackUrl, nowTime); dto = douYinRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localDouYinCallBackUrl, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_WAP_UNION: case DragonConstant.REFUND_TYPE_WAP_UNION:
dataUtils.setOrderCode(orderRefundCode,orderCode); dataUtils.setOrderCode(orderRefundCode, orderCode);
dto =UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime); dto = UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
break; break;
case DragonConstant.REFUND_TYPE_APP_UNION: case DragonConstant.REFUND_TYPE_APP_UNION:
dataUtils.setOrderCode(orderRefundCode,orderCode); dataUtils.setOrderCode(orderRefundCode, orderCode);
dto =UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime); dto = UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
break; break;
} }
...@@ -164,6 +165,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -164,6 +165,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return ResponseDto.failure("退款失败:" + e.getMessage()); return ResponseDto.failure("退款失败:" + e.getMessage());
} }
} }
/** /**
* @author zhangfuxin * @author zhangfuxin
* @Description: 抖音退款接口 * @Description: 抖音退款接口
...@@ -175,18 +177,18 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -175,18 +177,18 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonRefundChannelDto channelDto = new DragonRefundChannelDto(); DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
RefundContentDto contentDto = new RefundContentDto(); RefundContentDto contentDto = new RefundContentDto();
SortedMap<String, Object> parameters = new TreeMap<>(); SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("app_id",PayDouYinpayUtils.getInstance().getAPP_ID()); parameters.put("app_id", PayDouYinpayUtils.getInstance().getAPP_ID());
parameters.put("out_order_no",code); parameters.put("out_order_no", code);
parameters.put("out_refund_no",refundCode); parameters.put("out_refund_no", refundCode);
parameters.put("refund_amount",(int) (price.doubleValue() * 100)); parameters.put("refund_amount", price.multiply(new BigDecimal(100)).intValue()+"");
parameters.put("reason",reason); parameters.put("reason", reason);
parameters.put("notify_url",notifyUrl); parameters.put("notify_url", notifyUrl);
String sign = PayDouYinpayUtils.getInstance().createSign(parameters); String sign = PayDouYinpayUtils.getInstance().createSign(parameters);
parameters.put("sign",sign); parameters.put("sign", sign);
String data = JSON.toJSONString(parameters); String data = JSON.toJSONString(parameters);
String refundError = ""; String refundError = "";
try { try {
log.info("调用抖音退款:{}",data); log.info("调用抖音退款:{}", data);
HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/create_refund"); HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/create_refund");
httpost.setEntity(new StringEntity(data, "UTF-8")); httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayDouYinpayUtils.getInstance().getHttpClient().execute(httpost); CloseableHttpResponse response = PayDouYinpayUtils.getInstance().getHttpClient().execute(httpost);
...@@ -195,9 +197,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -195,9 +197,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
entity.getContent(); entity.getContent();
String jsonStr = EntityUtils.toString(entity, "UTF-8"); String jsonStr = EntityUtils.toString(entity, "UTF-8");
log.info("douYinRefund 返参{}", jsonStr); log.info("douYinRefund 返参{}", jsonStr);
Map result=JSON.parseObject(jsonStr, HashMap.class); Map result = JSON.parseObject(jsonStr, HashMap.class);
// //
if(!result.get("err_no").toString().equals("0")){ if (!result.get("err_no").toString().equals("0")) {
try { try {
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode(); refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
refundError = result.get("err_tips").toString(); refundError = result.get("err_tips").toString();
...@@ -263,19 +265,20 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -263,19 +265,20 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
} finally { } finally {
// PayWepayUtils.getInstance().getHttpClient().close(); // PayWepayUtils.getInstance().getHttpClient().close();
} }
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("退款发生错误",e); log.error("退款发生错误", e);
return null; return null;
} }
} }
//银联退款 //银联退款
public DragonRefundChannelDto UnionWapPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) { public DragonRefundChannelDto UnionWapPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) {
try { try {
RefundContentDto contentDto = new RefundContentDto(); RefundContentDto contentDto = new RefundContentDto();
DragonRefundChannelDto channelDto = new DragonRefundChannelDto(); DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
String txnTime = DateUtil.format(LocalDateTime.now(),DateUtil.Formatter.yyyyMMddHHmmssTrim); String txnTime = DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyyMMddHHmmssTrim);
Map<String, String> data=ObjectUtil.cloneHashMapStringAndString(); Map<String, String> data = ObjectUtil.cloneHashMapStringAndString();
/***银联全渠道系统,产品参数,除了encoding自行选择外其他不需修改***/ /***银联全渠道系统,产品参数,除了encoding自行选择外其他不需修改***/
data.put("version", sdkConfig.getVersion()); //版本号 data.put("version", sdkConfig.getVersion()); //版本号
data.put("encoding", UnionpayConstant.encoding); //字符集编码 可以使用UTF-8,GBK两种方式 data.put("encoding", UnionpayConstant.encoding); //字符集编码 可以使用UTF-8,GBK两种方式
...@@ -290,7 +293,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -290,7 +293,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
data.put("orderId", refundCode); //商户订单号,8-40位数字字母,不能含“-”或“_”,可以自行定制规则,重新产生,不同于原消费 data.put("orderId", refundCode); //商户订单号,8-40位数字字母,不能含“-”或“_”,可以自行定制规则,重新产生,不同于原消费
data.put("txnTime", txnTime); //订单发送时间,格式为yyyyMMddHHmmss,必须取当前时间,否则会报txnTime无效 data.put("txnTime", txnTime); //订单发送时间,格式为yyyyMMddHHmmss,必须取当前时间,否则会报txnTime无效
data.put("currencyCode", "156"); //交易币种(境内商户一般是156 人民币) data.put("currencyCode", "156"); //交易币种(境内商户一般是156 人民币)
data.put("txnAmt", price.multiply(BigDecimal.valueOf(100L)).intValue() + ""); //交易金额 单位为分 data.put("txnAmt", price.multiply(BigDecimal.valueOf(100L)).intValue() + ""); //交易金额 单位为分
data.put("backUrl", notifyUrl); //后台通知地址,后台通知参数详见open.unionpay.com帮助中心 下载 产品接口规范 网关支付产品接口规范 退货交易 商户通知,其他说明同消费交易的后台通知 data.put("backUrl", notifyUrl); //后台通知地址,后台通知参数详见open.unionpay.com帮助中心 下载 产品接口规范 网关支付产品接口规范 退货交易 商户通知,其他说明同消费交易的后台通知
/***要调通交易以下字段必须修改***/ /***要调通交易以下字段必须修改***/
data.put("origQryId", paymentId); //****原消费交易返回的的queryId,可以从消费交易后台通知接口中或者交易状态查询接口中获取 data.put("origQryId", paymentId); //****原消费交易返回的的queryId,可以从消费交易后台通知接口中或者交易状态查询接口中获取
...@@ -306,16 +309,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -306,16 +309,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
// 查询、通知等接口解析时使用new String(Base64.decodeBase64(reqReserved), UnionpayConstant.encoding);解base64后再对数据做后续解析。 // 查询、通知等接口解析时使用new String(Base64.decodeBase64(reqReserved), UnionpayConstant.encoding);解base64后再对数据做后续解析。
// data.put("reqReserved", Base64.encodeBase64String("任意格式的信息都可以".toString().getBytes(UnionpayConstant.encoding))); // data.put("reqReserved", Base64.encodeBase64String("任意格式的信息都可以".toString().getBytes(UnionpayConstant.encoding)));
/**请求参数设置完毕,以下对请求参数进行签名并发送http post请求,接收同步应答报文------------->**/ /**请求参数设置完毕,以下对请求参数进行签名并发送http post请求,接收同步应答报文------------->**/
Map<String, String> reqData = acpService.sign(data,UnionpayConstant.encoding); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。 Map<String, String> reqData = acpService.sign(data, UnionpayConstant.encoding); //报文中certId,signature的值是在signData方法中获取并自动赋值的,只要证书配置正确即可。
Map<String, String> rspData = acpService.post(reqData, sdkConfig.getBackTransUrl(),UnionpayConstant.encoding);//这里调用signData之后,调用submitUrl之前不能对submitFromData中的键值对做任何修改,如果修改会导致验签不通过 Map<String, String> rspData = acpService.post(reqData, sdkConfig.getBackTransUrl(), UnionpayConstant.encoding);//这里调用signData之后,调用submitUrl之前不能对submitFromData中的键值对做任何修改,如果修改会导致验签不通过
String refundError = ""; String refundError = "";
/**对应答码的处理,请根据您的业务逻辑来编写程序,以下应答码处理逻辑仅供参考------------->**/ /**对应答码的处理,请根据您的业务逻辑来编写程序,以下应答码处理逻辑仅供参考------------->**/
//应答码规范参考open.unionpay.com帮助中心 下载 产品接口规范 《平台接入接口规范-第5部分-附录》 //应答码规范参考open.unionpay.com帮助中心 下载 产品接口规范 《平台接入接口规范-第5部分-附录》
if(!rspData.isEmpty()){ if (!rspData.isEmpty()) {
if(acpService.validate(rspData, UnionpayConstant.encoding)){ if (acpService.validate(rspData, UnionpayConstant.encoding)) {
log.info("验证签名成功"); log.info("验证签名成功");
String respCode = rspData.get("respCode") ; String respCode = rspData.get("respCode");
if(("00").equals(respCode)){ if (("00").equals(respCode)) {
//交易已受理(不代表交易已成功),等待接收后台通知更新订单状态,也可以主动发起 查询交易确定交易状态。 //交易已受理(不代表交易已成功),等待接收后台通知更新订单状态,也可以主动发起 查询交易确定交易状态。
// 创建退款日志 // 创建退款日志
mqHandleUtil.sendMySqlRedis( mqHandleUtil.sendMySqlRedis(
...@@ -331,7 +334,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -331,7 +334,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
); );
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("异常信息",e); log.error("异常信息", e);
channelDto.setResult("exception"); channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage()); channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(JSON.toJSONString(reqData)); contentDto.setRequest(JSON.toJSONString(reqData));
...@@ -339,14 +342,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -339,14 +342,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
channelDto.setContent(contentDto); channelDto.setContent(contentDto);
return channelDto; return channelDto;
} }
}else{ } else {
//其他应答码为失败请排查原因 //其他应答码为失败请排查原因
try { try {
String refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode(); String refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if(("03").equals(respCode)|| ("04").equals(respCode)|| ("05").equals(respCode)){ if (("03").equals(respCode) || ("04").equals(respCode) || ("05").equals(respCode)) {
refundError="银联返回状态"+respCode+"请稍后确认。"; refundError = "银联返回状态" + respCode + "请稍后确认。";
}else{ } else {
refundError=rspData.get("respMsg")==null? "退款失败,原因未知":rspData.get("respMsg").toString(); refundError = rspData.get("respMsg") == null ? "退款失败,原因未知" : rspData.get("respMsg").toString();
} }
// 修改退款订单 // 修改退款订单
mqHandleUtil.sendMySqlRedis( mqHandleUtil.sendMySqlRedis(
...@@ -372,11 +375,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -372,11 +375,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
channelDto.setContent(contentDto); channelDto.setContent(contentDto);
return channelDto; return channelDto;
} }
}else{ } else {
log.error("银联退款,验证签名失败"); log.error("银联退款,验证签名失败");
return null; return null;
} }
}else{ } else {
//未返回正确的http状态 //未返回正确的http状态
log.error("银联退款,未获取到返回报文或返回http状态码非200"); log.error("银联退款,未获取到返回报文或返回http状态码非200");
return null; return null;
...@@ -387,9 +390,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -387,9 +390,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
contentDto.setResponse(JSON.toJSONString(rspData)); contentDto.setResponse(JSON.toJSONString(rspData));
channelDto.setContent(contentDto); channelDto.setContent(contentDto);
return channelDto; return channelDto;
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("异常信息",e); log.error("异常信息", e);
return null; return null;
} }
} }
...@@ -413,14 +416,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -413,14 +416,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
parameters.put("appid", PayWepayUtils.getInstance().getAPPLET_APP_ID()); parameters.put("appid", PayWepayUtils.getInstance().getAPPLET_APP_ID());
} else if (paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_WAP_WEPAY.getCode())) { } else if (paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_WAP_WEPAY.getCode())) {
parameters.put("appid", PayWepayUtils.getInstance().getWAP_APP_ID()); parameters.put("appid", PayWepayUtils.getInstance().getWAP_APP_ID());
} else if(paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_MICROPAY_WEPAY.getCode())){ }else if(paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_MICROPAY_WEPAY.getCode())){
parameters.put("appid", PayWepayUtils.getInstance().getAPP_ID()); parameters.put("appid", PayWepayUtils.getInstance().getAPP_ID());
} }
parameters.put("nonce_str", nonceStr); parameters.put("nonce_str", nonceStr);
parameters.put("out_refund_no", refundCode); parameters.put("out_refund_no", refundCode);
parameters.put("out_trade_no", code); parameters.put("out_trade_no", code);
parameters.put("refund_fee", (int) (price.doubleValue() * 100) + ""); parameters.put("refund_fee", (price.multiply(new BigDecimal(100)).intValue())+"");
parameters.put("total_fee", (int) (priceTotal.doubleValue() * 100) + ""); parameters.put("total_fee", (priceTotal.multiply(new BigDecimal(100)).intValue())+"");
parameters.put("notify_url", notifyUrl); parameters.put("notify_url", notifyUrl);
parameters.put("refund_desc", reason); parameters.put("refund_desc", reason);
parameters.put("refund_account", "REFUND_SOURCE_RECHARGE_FUNDS"); parameters.put("refund_account", "REFUND_SOURCE_RECHARGE_FUNDS");
...@@ -612,28 +615,29 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -612,28 +615,29 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return null; return null;
} }
} }
/** /**
* @author zhangfuxin * @author zhangfuxin
* @Description: 抖音退款回调 * @Description: 抖音退款回调
* @date 2021/11/11 上午10:55 * @date 2021/11/11 上午10:55
*/ */
public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response){ public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
try { try {
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject=PayDouYinpayUtils.getJsonObject(request); JSONObject jsonObject = PayDouYinpayUtils.getJsonObject(request);
log.info("接收到的抖音退款回调请求参数{}",JSON.toJSONString(jsonObject)); log.info("接收到的抖音退款回调请求参数{}", JSON.toJSONString(jsonObject));
//再次验证是退款的回调 //再次验证是退款的回调
if(!jsonObject.getString("type").equals("refund")){ if (!jsonObject.getString("type").equals("refund")) {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_PARAM_ERROR.getCode(),DragonErrorCodeEnum.TRADE_PARAM_ERROR.getMessage()); throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_PARAM_ERROR.getCode(), DragonErrorCodeEnum.TRADE_PARAM_ERROR.getMessage());
} }
JSONObject msg=jsonObject.getJSONObject("msg"); JSONObject msg = jsonObject.getJSONObject("msg");
NotifyUrlDto dto = new NotifyUrlDto(); NotifyUrlDto dto = new NotifyUrlDto();
// 验签 // 验签
if (PayDouYinpayUtils.getInstance().notifySign(jsonObject.get("msg_signature").toString(),jsonObject)) {// 根据配置信息验证签名 if (PayDouYinpayUtils.getInstance().notifySign(jsonObject.get("msg_signature").toString(), jsonObject)) {// 根据配置信息验证签名
//查看退款状态 (退款状态 PROCESSING-处理中|SUCCESS-成功|FAIL-失败) //查看退款状态 (退款状态 PROCESSING-处理中|SUCCESS-成功|FAIL-失败)
if(msg.getString("status").equals("SUCCESS")){ if (msg.getString("status").equals("SUCCESS")) {
dto.setStatus(1); dto.setStatus(1);
}else{ } else {
dto.setStatus(0); dto.setStatus(0);
} }
//开发者自定义的退款单号 //开发者自定义的退款单号
...@@ -641,7 +645,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -641,7 +645,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
// 没有订单号 从redids里面查 // 没有订单号 从redids里面查
dto.setRefundCode(dataUtils.getOrderCode(msg.getString("cp_refundno"))); dto.setRefundCode(dataUtils.getOrderCode(msg.getString("cp_refundno")));
dto.setRefundPrice(msg.getBigDecimal("refund_amount").divide(BigDecimal.valueOf(100)).toString()); dto.setRefundPrice(msg.getBigDecimal("refund_amount").divide(BigDecimal.valueOf(100)).toString());
// SimpleDateFormat sdf = new SimpleDateFormat( " yyyy年MM月dd日 " ); // SimpleDateFormat sdf = new SimpleDateFormat( " yyyy年MM月dd日 " );
// 抖音没有传回时间 // 抖音没有传回时间
dto.setRefundAt(DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now())); dto.setRefundAt(DateUtil.Formatter.yyyyMMddHHmmss.format(LocalDateTime.now()));
//抖音回调没有写错误原因 //抖音回调没有写错误原因
...@@ -662,9 +666,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -662,9 +666,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
); );
return "{\"err_no\": 0, \"err_tips\": \"success\"}"; return "{\"err_no\": 0, \"err_tips\": \"success\"}";
} }
}catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("退款回调失败",e); log.error("退款回调失败", e);
} }
return ""; return "";
...@@ -672,21 +676,21 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -672,21 +676,21 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
/** /**
* @author zhangfuxin * @author zhangfuxin
* @Description: 查询退款 * @Description: 查询退款
* @date 2021/11/11 下午3:21 * @date 2021/11/11 下午3:21
*/ */
@Override @Override
public String douYinPayRefundCodeStatus(String outRefundNo) { public String douYinPayRefundCodeStatus(String outRefundNo) {
try { try {
//1、组织数据 //1、组织数据
Map<String,Object> map = CollectionUtil.mapStringObject(); Map<String, Object> map = CollectionUtil.mapStringObject();
map.put("app_id",PayDouYinpayUtils.getInstance().getAPP_ID()); map.put("app_id", PayDouYinpayUtils.getInstance().getAPP_ID());
map.put("out_refund_no",outRefundNo); map.put("out_refund_no", outRefundNo);
//2、加密 //2、加密
map.put("sign",PayDouYinpayUtils.getInstance().createSign(map)); map.put("sign", PayDouYinpayUtils.getInstance().createSign(map));
//3、请求 //3、请求
String data = JSON.toJSONString(map); String data = JSON.toJSONString(map);
log.info("查询退款请求抖音参数:{}",data); log.info("查询退款请求抖音参数:{}", data);
HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/query_refund"); HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/query_refund");
httpost.setEntity(new StringEntity(data, "UTF-8")); httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpClient httpClient = PayDouYinpayUtils.getInstance().getHttpClient(); CloseableHttpClient httpClient = PayDouYinpayUtils.getInstance().getHttpClient();
...@@ -695,16 +699,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -695,16 +699,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
//接受到返回信息 //接受到返回信息
String json = EntityUtils.toString(response.getEntity(), "UTF-8"); String json = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity); EntityUtils.consume(entity);
log.info("查询抖音退款查询返回值:{}",json); log.info("查询抖音退款查询返回值:{}", json);
//解析、如果成功,则更新 //解析、如果成功,则更新
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject = JSONObject.parseObject(json); JSONObject jsonObject = JSONObject.parseObject(json);
if(jsonObject.getInteger("err_no")==0){ if (jsonObject.getInteger("err_no") == 0) {
JSONObject refundInfo=jsonObject.getJSONObject("refundInfo"); JSONObject refundInfo = jsonObject.getJSONObject("refundInfo");
NotifyUrlDto dto = new NotifyUrlDto(); NotifyUrlDto dto = new NotifyUrlDto();
if(refundInfo.getString("refund_status").equals("SUCCESS")){ if (refundInfo.getString("refund_status").equals("SUCCESS")) {
dto.setStatus(1); dto.setStatus(1);
}else{ } else {
dto.setStatus(0); dto.setStatus(0);
} }
//开发者自定义的退款单号 //开发者自定义的退款单号
...@@ -730,12 +734,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -730,12 +734,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
new Object[]{nowTime, dto.getRefundAt(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), refundInfo.getString("refund_no")}, new Object[]{nowTime, dto.getRefundAt(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), refundInfo.getString("refund_no")},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode() DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
); );
}else{ } else {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getCode(),DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getMessage()); throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getCode(), DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getMessage());
} }
return json; return json;
}catch (Exception e){ } catch (Exception e) {
log.info("查询退款报错:{}",e); log.info("查询退款报错:{}", e);
} }
return ""; return "";
...@@ -750,19 +754,19 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -750,19 +754,19 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
try { try {
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
String encoding = request.getParameter(SDKConstants.param_encoding); String encoding = request.getParameter(SDKConstants.param_encoding);
Map<String , String> notifyMap = unionpayBiz.parseNotifyMsg(request); Map<String, String> notifyMap = unionpayBiz.parseNotifyMsg(request);
log.info("银联退款回调{}",JSON.toJSONString(notifyMap)); log.info("银联退款回调{}", JSON.toJSONString(notifyMap));
if (!acpService.validate(notifyMap, encoding)) { if (!acpService.validate(notifyMap, encoding)) {
//验签失败,需解决验签问题 //验签失败,需解决验签问题
log.error("银联回调,验签失败。{}",JSON.toJSONString(notifyMap)); log.error("银联回调,验签失败。{}", JSON.toJSONString(notifyMap));
} else { } else {
String orderId =notifyMap.get("orderId"); //获取后台通知的数据,其他字段也可用类似方式获取 String orderId = notifyMap.get("orderId"); //获取后台通知的数据,其他字段也可用类似方式获取
String respCode = notifyMap.get("respCode"); String respCode = notifyMap.get("respCode");
NotifyUrlDto dto = new NotifyUrlDto(); NotifyUrlDto dto = new NotifyUrlDto();
//成功 //成功
if(respCode.equals("00")||respCode.equals("A6")){ if (respCode.equals("00") || respCode.equals("A6")) {
dto.setStatus(1); dto.setStatus(1);
}else{ } else {
dto.setStatus(0); dto.setStatus(0);
} }
//商户订单号 商户退款单号 //商户订单号 商户退款单号
...@@ -786,11 +790,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService ...@@ -786,11 +790,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode() DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
); );
} }
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return "ok"; return "ok";
} }
@Override @Override
public String wePayRefundCallBack(HttpServletRequest request, HttpServletResponse response) { public String wePayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
InputStream inStream; InputStream inStream;
......
package com.liquidnet.service.dragon.service.impl; package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.common.exception.LiquidnetServiceException; import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil; import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.biz.DragonServiceCommonBiz;
import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext; import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz; import com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz;
import com.liquidnet.service.dragon.channel.strategy.impl.ApplepayImpl;
import com.liquidnet.service.dragon.constant.DragonConstant; import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum; import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum;
import com.liquidnet.service.dragon.dto.DragonOrdersDto; import com.liquidnet.service.dragon.dto.DragonOrdersDto;
...@@ -13,17 +17,29 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; ...@@ -13,17 +17,29 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto; import com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto;
import com.liquidnet.service.dragon.service.IDragonOrdersService; import com.liquidnet.service.dragon.service.IDragonOrdersService;
import com.liquidnet.service.dragon.utils.ApplepayUtils;
import com.liquidnet.service.dragon.utils.DataUtils; import com.liquidnet.service.dragon.utils.DataUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.SortedMap;
import java.util.TreeMap;
@Slf4j @Slf4j
@Service @Service
public class DragonOrdersServiceImpl implements IDragonOrdersService { public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Value("${apple.urlVerify}")
private String appleUrl;
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
...@@ -35,6 +51,10 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService { ...@@ -35,6 +51,10 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Autowired @Autowired
private DragonPayBiz dragonPayBiz; private DragonPayBiz dragonPayBiz;
@Autowired
private DragonServiceCommonBiz dragonServiceCommonBiz;
@Autowired
private ApplepayImpl applepay;
@Override @Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) { public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
...@@ -75,8 +95,91 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService { ...@@ -75,8 +95,91 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(ordersDto)); return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(ordersDto));
} }
/**
* 苹果支付
* @param dragonPayBaseReqDto
*/
@Override @Override
public DragonPayBaseRespDto dragonNotifyApple(DragonPayBaseReqDto dragonPayBaseReqDto) { public DragonPayBaseRespDto dragonNotifyApple(DragonPayBaseReqDto dragonPayBaseReqDto) {
//1 调用苹果查询结果
String verifyResult = buyAppVerify(dragonPayBaseReqDto.getReceiptData());
if (verifyResult == null) {
// 苹果服务器没有返回验证结果
log.info("苹果支付,app调用,查不到订单信息");
return null;
} else {
JSONObject job = JSONObject.parseObject(verifyResult);
String states = job.getString("status");
if (states.equals("0")){ // 前端所提供的收据是有效的 验证成功
String r_receipt = job.getString("receipt");
JSONObject returnJson = JSONObject.parseObject(r_receipt);
String in_app = returnJson.getString("in_app");
JSONObject in_appJson = JSONObject.parseObject(in_app.substring(1, in_app.length() - 1));
/* ApplePayRefundDto applePayRefundDto=ApplePayRefundDto.getNew();*/
String product_id = in_appJson.getString("product_id");
/*applePayRefundDto.setProductId(product_id);*/
String transaction_id = in_appJson.getString("transaction_id"); // 订单号
//如果单号一致 则开始处理逻辑
if(dragonPayBaseReqDto.getTransactionId().equals(transaction_id)){
//判断是已经查过了。
DragonPayBaseRespDto dragonPayBaseRespDto=dataUtils.getDragonPayBaseRespDto(dragonPayBaseReqDto.getOrderCode());
if(null!=dragonPayBaseRespDto){
return dragonPayBaseRespDto;
}
/*String[] moneys = product_id.split("\\.");//实际支付金额*/
//此处开始业务逻辑
//2 插入支付该支付的东西(预支付的东西)//dragon_orders
dragonServiceCommonBiz.buildPayOrders(dragonPayBaseReqDto,null);
//第二部
//持久化通知记录
dragonServiceCommonBiz.createDragonOrderLogs(dragonPayBaseReqDto.getCode(),dragonPayBiz.getPaymentType(dragonPayBaseReqDto.getPayType(),dragonPayBaseReqDto.getDeviceFrom()),verifyResult);
//修改状态
applepay.completeSuccessOrder(dataUtils.getPayOrderByCode(dragonPayBaseReqDto.getCode()),transaction_id,verifyResult);
//
DragonPayBaseRespDto respDto = buildCommonRespDto(dragonPayBaseReqDto);
respDto.setProductId(product_id);
dataUtils.createAPPLePayOrder(dragonPayBaseReqDto.getOrderCode(),respDto);
return respDto;
}
} else {
return null;
}
}
return null;
}
public String buyAppVerify(String receipt) {
try{
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("receipt-data",receipt);
String data = JSON.toJSONString(parameters);
HttpPost httpost = new HttpPost(appleUrl);
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = ApplepayUtils.getInstance().getHttpClient().execute(httpost);
HttpEntity entity = response.getEntity();
//接受到返回信息
String returnDate = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
log.info("苹果支付完成后查询{} ",returnDate);
return returnDate;
}catch (Exception e){
log.error(e.getMessage());
}
return null; return null;
} }
/**
* 构造公共返回参数
* @param dragonPayBaseReqDto
* @return
*/
protected DragonPayBaseRespDto buildCommonRespDto(DragonPayBaseReqDto dragonPayBaseReqDto){
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setPayType(dragonPayBaseReqDto.getPayType());
respDto.setCode(dragonPayBaseReqDto.getCode());
respDto.setOrderCode(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
respDto.setPayData(payData);
return respDto;
}
} }
package com.liquidnet.service.dragon.utils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class ApplepayUtils {
private static class TrustAnyTrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
}
private CloseableHttpClient httpClient;
private static ApplepayUtils instance = new ApplepayUtils();
// 池化管理
private static PoolingHttpClientConnectionManager poolConnManager =null;
public ApplepayUtils() {
}
public static ApplepayUtils getInstance() {
return instance;
}
public CloseableHttpClient getHttpClient() {
try {
if (httpClient == null) {
/* SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(keyStore, merchantId.toCharArray())
.build();
*/
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
// 配置同时支持 HTTP 和 HTPPS
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
// 初始化连接管理器
poolConnManager =new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolConnManager.setMaxTotal(4000);// 同时最多连接数
// 设置最大路由
poolConnManager.setDefaultMaxPerRoute(2000);
// 初始化httpClient
httpClient = getConnection();
}
} catch (Exception e) {
e.printStackTrace();
}
return httpClient;
}
public static CloseableHttpClient getConnection() {
RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(5000).build();
CloseableHttpClient httpClient = HttpClients.custom()
// 设置连接池管理
.setConnectionManager(poolConnManager)
.setDefaultRequestConfig(config)
// 设置重试次数
.setRetryHandler(new DefaultHttpRequestRetryHandler(2,false)).build();
return httpClient;
}
public static void main(String[] args) {
}
}
...@@ -3,6 +3,7 @@ package com.liquidnet.service.dragon.utils; ...@@ -3,6 +3,7 @@ package com.liquidnet.service.dragon.utils;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.dragon.constant.DragonConstant; import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonOrdersDto; import com.liquidnet.service.dragon.dto.DragonOrdersDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -16,6 +17,13 @@ public class DataUtils { ...@@ -16,6 +17,13 @@ public class DataUtils {
public void createPayOrder(String code, DragonOrdersDto ordersDto) { public void createPayOrder(String code, DragonOrdersDto ordersDto) {
redisUtil.set(DragonConstant.REDIS_KET_PAY_CODE + code, ordersDto,keyExpireTime); redisUtil.set(DragonConstant.REDIS_KET_PAY_CODE + code, ordersDto,keyExpireTime);
} }
public void createAPPLePayOrder(String orderCode, DragonPayBaseRespDto dragonPayBaseRespDto) {
redisUtil.set(DragonConstant.REDIS_KET_ORDERCODE_PAY_CODE + orderCode, dragonPayBaseRespDto,keyExpireTime);
}
public DragonPayBaseRespDto getDragonPayBaseRespDto(String orderCode){
return (DragonPayBaseRespDto) redisUtil.get(DragonConstant.REDIS_KET_ORDERCODE_PAY_CODE+orderCode);
}
public DragonOrdersDto getPayOrderByCode(String code) { public DragonOrdersDto getPayOrderByCode(String code) {
Object obj = redisUtil.get(DragonConstant.REDIS_KET_PAY_CODE + code); Object obj = redisUtil.get(DragonConstant.REDIS_KET_PAY_CODE + code);
......
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