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

Commit 424b7b69 authored by zhengfuxin's avatar zhengfuxin

修改 notify dragon

parent dbd81a91
......@@ -40,3 +40,5 @@ liquidnet:
certs-path: /data/certs/dragon/unionpay/test
certs-prefix: acp_prod
pfx-pwd: '520360'
apple:
urlVerify: https://sandbox.itunes.apple.com/verifyReceipt
......@@ -40,3 +40,5 @@ liquidnet:
certs-path: /data/certs/dragon/unionpay/test
certs-prefix: acp_test
pfx-pwd: '520360'
apple:
urlVerify: https://sandbox.itunes.apple.com/verifyReceipt
\ No newline at end of file
......@@ -56,6 +56,7 @@ public class DragonServiceCommonBiz {
// orders.setFinishedAt();
orders.setCreatedAt(LocalDateTime.now());
// orders.setUpdatedAt();
orders.setReceiptData(dragonPayBaseReqDto.getReceiptData());
long startTime = System.currentTimeMillis();
......@@ -72,7 +73,7 @@ public class DragonServiceCommonBiz {
, orders.getNotifyUrl(), orders.getNotifyStatus(),orders.getPaymentType(),
orders.getPaymentId(), orders.getPaymentAt()
, orders.getFinishedAt(), orders.getCreatedAt()
, orders.getUpdatedAt(),orders.getDeletedAt()}
, orders.getUpdatedAt(),orders.getDeletedAt(),orders.getReceiptData()}
,DragonConstant.MysqlRedisQueueEnum.DRAGON_PAY_KEY.getCode()
);
log.info("redis-queue-sendMySqlRedis->耗时:{}",(System.currentTimeMillis() - startTime)+"毫秒");
......
......@@ -65,6 +65,17 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
//通知商户
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;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
......@@ -13,11 +9,11 @@ import org.springframework.web.bind.annotation.RestController;
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/9 12:29
*/
@Slf4j
/*@Slf4j
@RestController
@RequestMapping("pay")
public class PayController {
/* @Autowired
@Autowired
private IDragonOrdersService dragonOrdersService;
*//**
......@@ -79,10 +75,10 @@ public class PayController {
dragonPayBaseReqDto.setType(type);
dragonPayBaseReqDto.setPrice(price);
dragonPayBaseReqDto.setAuthCode(authCode);
// if(StringUtil.isNotNull(name)&&name.length()>=32){
// name = name.substring(0,32);
// }
dragonPayBaseReqDto.setName("正在现场");
if(StringUtil.isNotNull(name)&&name.length()>=32){
name = name.substring(0,32);
}
dragonPayBaseReqDto.setName(name);
// if(StringUtil.isNotNull(detail)&&detail.length()>=64){
// detail = detail.substring(0,64);
// }
......@@ -141,5 +137,5 @@ public class PayController {
rs.put("code", code);
rs.put("result", "" + respDto);
return ResponseDto.success(rs);
}*/
}
}
}*/
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 io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
......@@ -41,4 +45,72 @@ public class PayNotifyController {
public String dragonNotify(@PathVariable("payType") String payType,@PathVariable("deviceFrom") String deviceFrom,HttpServletRequest request, HttpServletResponse respone) throws Exception {
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
private String unionMerchantId;
@Autowired
private UnionpayBiz unionpayBiz;
@Override
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) {
try {
......@@ -88,7 +89,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonRefundChannelDto dto = null;
String localWePayCallBackUrl = url + "/refund/callBack/wepay";
String localDouYinCallBackUrl = url + "/refund/callBack/douyinpay";
String localUnionPayCallBackUrl= url+"/refund/callBack/union";
String localUnionPayCallBackUrl = url + "/refund/callBack/union";
if (insertResult) {
switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY:
......@@ -122,16 +123,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
dto = weyPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localWePayCallBackUrl, nowTime);
break;
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);
break;
case DragonConstant.REFUND_TYPE_WAP_UNION:
dataUtils.setOrderCode(orderRefundCode,orderCode);
dto =UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
dataUtils.setOrderCode(orderRefundCode, orderCode);
dto = UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_APP_UNION:
dataUtils.setOrderCode(orderRefundCode,orderCode);
dto =UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
dataUtils.setOrderCode(orderRefundCode, orderCode);
dto = UnionWapPayRefund(code, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, localUnionPayCallBackUrl, nowTime);
break;
}
......@@ -164,6 +165,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return ResponseDto.failure("退款失败:" + e.getMessage());
}
}
/**
* @author zhangfuxin
* @Description: 抖音退款接口
......@@ -175,18 +177,18 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
RefundContentDto contentDto = new RefundContentDto();
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("app_id",PayDouYinpayUtils.getInstance().getAPP_ID());
parameters.put("out_order_no",code);
parameters.put("out_refund_no",refundCode);
parameters.put("refund_amount",(int) (price.doubleValue() * 100));
parameters.put("reason",reason);
parameters.put("notify_url",notifyUrl);
parameters.put("app_id", PayDouYinpayUtils.getInstance().getAPP_ID());
parameters.put("out_order_no", code);
parameters.put("out_refund_no", refundCode);
parameters.put("refund_amount", price.multiply(new BigDecimal(100)).intValue()+"");
parameters.put("reason", reason);
parameters.put("notify_url", notifyUrl);
String sign = PayDouYinpayUtils.getInstance().createSign(parameters);
parameters.put("sign",sign);
parameters.put("sign", sign);
String data = JSON.toJSONString(parameters);
String refundError = "";
try {
log.info("调用抖音退款:{}",data);
log.info("调用抖音退款:{}", data);
HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/create_refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayDouYinpayUtils.getInstance().getHttpClient().execute(httpost);
......@@ -195,9 +197,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
entity.getContent();
String jsonStr = EntityUtils.toString(entity, "UTF-8");
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 {
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
refundError = result.get("err_tips").toString();
......@@ -263,19 +265,20 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
} finally {
// PayWepayUtils.getInstance().getHttpClient().close();
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
log.error("退款发生错误",e);
log.error("退款发生错误", e);
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) {
try {
RefundContentDto contentDto = new RefundContentDto();
DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
String txnTime = DateUtil.format(LocalDateTime.now(),DateUtil.Formatter.yyyyMMddHHmmssTrim);
Map<String, String> data=ObjectUtil.cloneHashMapStringAndString();
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两种方式
......@@ -306,16 +309,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
// 查询、通知等接口解析时使用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方法中获取并自动赋值的,只要证书配置正确即可。
Map<String, String> rspData = acpService.post(reqData, sdkConfig.getBackTransUrl(),UnionpayConstant.encoding);//这里调用signData之后,调用submitUrl之前不能对submitFromData中的键值对做任何修改,如果修改会导致验签不通过
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中的键值对做任何修改,如果修改会导致验签不通过
String refundError = "";
/**对应答码的处理,请根据您的业务逻辑来编写程序,以下应答码处理逻辑仅供参考------------->**/
//应答码规范参考open.unionpay.com帮助中心 下载 产品接口规范 《平台接入接口规范-第5部分-附录》
if(!rspData.isEmpty()){
if(acpService.validate(rspData, UnionpayConstant.encoding)){
if (!rspData.isEmpty()) {
if (acpService.validate(rspData, UnionpayConstant.encoding)) {
log.info("验证签名成功");
String respCode = rspData.get("respCode") ;
if(("00").equals(respCode)){
String respCode = rspData.get("respCode");
if (("00").equals(respCode)) {
//交易已受理(不代表交易已成功),等待接收后台通知更新订单状态,也可以主动发起 查询交易确定交易状态。
// 创建退款日志
mqHandleUtil.sendMySqlRedis(
......@@ -331,7 +334,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
);
} catch (Exception e) {
e.printStackTrace();
log.error("异常信息",e);
log.error("异常信息", e);
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(JSON.toJSONString(reqData));
......@@ -339,14 +342,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
channelDto.setContent(contentDto);
return channelDto;
}
}else{
} 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();
if (("03").equals(respCode) || ("04").equals(respCode) || ("05").equals(respCode)) {
refundError = "银联返回状态" + respCode + "请稍后确认。";
} else {
refundError = rspData.get("respMsg") == null ? "退款失败,原因未知" : rspData.get("respMsg").toString();
}
// 修改退款订单
mqHandleUtil.sendMySqlRedis(
......@@ -372,11 +375,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
channelDto.setContent(contentDto);
return channelDto;
}
}else{
} else {
log.error("银联退款,验证签名失败");
return null;
}
}else{
} else {
//未返回正确的http状态
log.error("银联退款,未获取到返回报文或返回http状态码非200");
return null;
......@@ -387,9 +390,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
contentDto.setResponse(JSON.toJSONString(rspData));
channelDto.setContent(contentDto);
return channelDto;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
log.error("异常信息",e);
log.error("异常信息", e);
return null;
}
}
......@@ -413,14 +416,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
parameters.put("appid", PayWepayUtils.getInstance().getAPPLET_APP_ID());
} else if (paymentType.equalsIgnoreCase(DragonConstant.PayTypeEnum.PAYMENT_TYPE_WAP_WEPAY.getCode())) {
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("nonce_str", nonceStr);
parameters.put("out_refund_no", refundCode);
parameters.put("out_trade_no", code);
parameters.put("refund_fee", (int) (price.doubleValue() * 100) + "");
parameters.put("total_fee", (int) (priceTotal.doubleValue() * 100) + "");
parameters.put("refund_fee", (price.multiply(new BigDecimal(100)).intValue())+"");
parameters.put("total_fee", (priceTotal.multiply(new BigDecimal(100)).intValue())+"");
parameters.put("notify_url", notifyUrl);
parameters.put("refund_desc", reason);
parameters.put("refund_account", "REFUND_SOURCE_RECHARGE_FUNDS");
......@@ -612,28 +615,29 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return null;
}
}
/**
* @author zhangfuxin
* @Description: 抖音退款回调
* @date 2021/11/11 上午10:55
*/
public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response){
public String douYinPayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
try {
LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject=PayDouYinpayUtils.getJsonObject(request);
log.info("接收到的抖音退款回调请求参数{}",JSON.toJSONString(jsonObject));
JSONObject jsonObject = PayDouYinpayUtils.getJsonObject(request);
log.info("接收到的抖音退款回调请求参数{}", JSON.toJSONString(jsonObject));
//再次验证是退款的回调
if(!jsonObject.getString("type").equals("refund")){
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_PARAM_ERROR.getCode(),DragonErrorCodeEnum.TRADE_PARAM_ERROR.getMessage());
if (!jsonObject.getString("type").equals("refund")) {
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();
// 验签
if (PayDouYinpayUtils.getInstance().notifySign(jsonObject.get("msg_signature").toString(),jsonObject)) {// 根据配置信息验证签名
if (PayDouYinpayUtils.getInstance().notifySign(jsonObject.get("msg_signature").toString(), jsonObject)) {// 根据配置信息验证签名
//查看退款状态 (退款状态 PROCESSING-处理中|SUCCESS-成功|FAIL-失败)
if(msg.getString("status").equals("SUCCESS")){
if (msg.getString("status").equals("SUCCESS")) {
dto.setStatus(1);
}else{
} else {
dto.setStatus(0);
}
//开发者自定义的退款单号
......@@ -662,9 +666,9 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
);
return "{\"err_no\": 0, \"err_tips\": \"success\"}";
}
}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
log.error("退款回调失败",e);
log.error("退款回调失败", e);
}
return "";
......@@ -679,14 +683,14 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
public String douYinPayRefundCodeStatus(String outRefundNo) {
try {
//1、组织数据
Map<String,Object> map = CollectionUtil.mapStringObject();
map.put("app_id",PayDouYinpayUtils.getInstance().getAPP_ID());
map.put("out_refund_no",outRefundNo);
Map<String, Object> map = CollectionUtil.mapStringObject();
map.put("app_id", PayDouYinpayUtils.getInstance().getAPP_ID());
map.put("out_refund_no", outRefundNo);
//2、加密
map.put("sign",PayDouYinpayUtils.getInstance().createSign(map));
map.put("sign", PayDouYinpayUtils.getInstance().createSign(map));
//3、请求
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");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpClient httpClient = PayDouYinpayUtils.getInstance().getHttpClient();
......@@ -695,16 +699,16 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
//接受到返回信息
String json = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
log.info("查询抖音退款查询返回值:{}",json);
log.info("查询抖音退款查询返回值:{}", json);
//解析、如果成功,则更新
LocalDateTime nowTime = LocalDateTime.now();
JSONObject jsonObject = JSONObject.parseObject(json);
if(jsonObject.getInteger("err_no")==0){
JSONObject refundInfo=jsonObject.getJSONObject("refundInfo");
if (jsonObject.getInteger("err_no") == 0) {
JSONObject refundInfo = jsonObject.getJSONObject("refundInfo");
NotifyUrlDto dto = new NotifyUrlDto();
if(refundInfo.getString("refund_status").equals("SUCCESS")){
if (refundInfo.getString("refund_status").equals("SUCCESS")) {
dto.setStatus(1);
}else{
} else {
dto.setStatus(0);
}
//开发者自定义的退款单号
......@@ -730,12 +734,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
new Object[]{nowTime, dto.getRefundAt(), DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode(), refundInfo.getString("refund_no")},
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
}else{
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getCode(),DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getMessage());
} else {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getCode(), DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getMessage());
}
return json;
}catch (Exception e){
log.info("查询退款报错:{}",e);
} catch (Exception e) {
log.info("查询退款报错:{}", e);
}
return "";
......@@ -750,19 +754,19 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
try {
LocalDateTime nowTime = LocalDateTime.now();
String encoding = request.getParameter(SDKConstants.param_encoding);
Map<String , String> notifyMap = unionpayBiz.parseNotifyMsg(request);
log.info("银联退款回调{}",JSON.toJSONString(notifyMap));
Map<String, String> notifyMap = unionpayBiz.parseNotifyMsg(request);
log.info("银联退款回调{}", JSON.toJSONString(notifyMap));
if (!acpService.validate(notifyMap, encoding)) {
//验签失败,需解决验签问题
log.error("银联回调,验签失败。{}",JSON.toJSONString(notifyMap));
log.error("银联回调,验签失败。{}", JSON.toJSONString(notifyMap));
} else {
String orderId =notifyMap.get("orderId"); //获取后台通知的数据,其他字段也可用类似方式获取
String orderId = notifyMap.get("orderId"); //获取后台通知的数据,其他字段也可用类似方式获取
String respCode = notifyMap.get("respCode");
NotifyUrlDto dto = new NotifyUrlDto();
//成功
if(respCode.equals("00")||respCode.equals("A6")){
if (respCode.equals("00") || respCode.equals("A6")) {
dto.setStatus(1);
}else{
} else {
dto.setStatus(0);
}
//商户订单号 商户退款单号
......@@ -786,11 +790,12 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
DragonConstant.MysqlRedisQueueEnum.DRAGON_REFUND_KEY.getCode()
);
}
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
return "ok";
}
@Override
public String wePayRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
InputStream inStream;
......
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.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil;
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.biz.DragonPayBiz;
import com.liquidnet.service.dragon.channel.strategy.impl.ApplepayImpl;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.constant.DragonErrorCodeEnum;
import com.liquidnet.service.dragon.dto.DragonOrdersDto;
......@@ -13,17 +17,29 @@ 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.IDragonOrdersService;
import com.liquidnet.service.dragon.utils.ApplepayUtils;
import com.liquidnet.service.dragon.utils.DataUtils;
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.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.SortedMap;
import java.util.TreeMap;
@Slf4j
@Service
public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Value("${apple.urlVerify}")
private String appleUrl;
@Autowired
StringRedisTemplate stringRedisTemplate;
......@@ -35,6 +51,10 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Autowired
private DragonPayBiz dragonPayBiz;
@Autowired
private DragonServiceCommonBiz dragonServiceCommonBiz;
@Autowired
private ApplepayImpl applepay;
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
......@@ -75,8 +95,91 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
return dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(ordersDto));
}
/**
* 苹果支付
* @param dragonPayBaseReqDto
*/
@Override
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;
}
/**
* 构造公共返回参数
* @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;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonOrdersDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -16,6 +17,13 @@ public class DataUtils {
public void createPayOrder(String code, DragonOrdersDto ordersDto) {
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) {
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