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

Commit ef4d2d6a authored by anjiabin's avatar anjiabin

提交微信支付

parent e09be40d
package com.liquidnet.service.dragon.dto; package com.liquidnet.service.dragon.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
...@@ -30,4 +28,7 @@ public class DragonPayBaseReqDto { ...@@ -30,4 +28,7 @@ public class DragonPayBaseReqDto {
private String code; private String code;
private String createDate; private String createDate;
private String expireTime; private String expireTime;
private String quitUrl;
private String showUrl;
private String returnUrl;
} }
...@@ -4,7 +4,6 @@ import com.liquidnet.service.base.ResponseDto; ...@@ -4,7 +4,6 @@ import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz; import com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq; import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy; import com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -45,7 +44,8 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy { ...@@ -45,7 +44,8 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy {
alipayTradePayReq.setNotifyUrl(this.getNotifyUrl()); alipayTradePayReq.setNotifyUrl(this.getNotifyUrl());
alipayTradePayReq.setTimestamp(dragonPayBaseReqDto.getCreateDate()); alipayTradePayReq.setTimestamp(dragonPayBaseReqDto.getCreateDate());
//调用支付 //调用支付
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq); Map<String, Object> result = this.executePay(alipayTradePayReq);
//拼接返回参数 //拼接返回参数
DragonPayBaseRespDto respDto = buildCommonRespDto(dragonPayBaseReqDto); DragonPayBaseRespDto respDto = buildCommonRespDto(dragonPayBaseReqDto);
respDto = this.buildResponseDto(respDto,result); respDto = this.buildResponseDto(respDto,result);
...@@ -55,6 +55,13 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy { ...@@ -55,6 +55,13 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy {
return ResponseDto.success(respDto); return ResponseDto.success(respDto);
} }
/**
* 支付请求
* @param alipayTradePayReq
* @return
*/
protected abstract Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq);
/** /**
* 设置productCode * 设置productCode
*/ */
......
package com.liquidnet.service.dragon.channel.alipay.strategy.impl; package com.liquidnet.service.dragon.channel.alipay.strategy.impl;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler; import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant; import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
...@@ -19,6 +22,7 @@ import java.util.Map; ...@@ -19,6 +22,7 @@ import java.util.Map;
* @Copyright: LightNet @ Copyright (c) 2021 * @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34 * @date 2021/7/10 14:34
*/ */
@Slf4j
@Component @Component
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.APP) @StrategyAlipayHandler(DragonConstant.DeviceFromEnum.APP)
public class AlipayStrategyAppImpl extends AbstractAlipayStrategy { public class AlipayStrategyAppImpl extends AbstractAlipayStrategy {
...@@ -31,6 +35,11 @@ public class AlipayStrategyAppImpl extends AbstractAlipayStrategy { ...@@ -31,6 +35,11 @@ public class AlipayStrategyAppImpl extends AbstractAlipayStrategy {
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
@Override
protected Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq) {
return AlipayUtil.tradeWapPay(alipayTradePayReq);
}
protected void setProductCode() { protected void setProductCode() {
this.productCode = "QUICK_MSECURITY_PAY"; this.productCode = "QUICK_MSECURITY_PAY";
} }
......
package com.liquidnet.service.dragon.channel.alipay.strategy.impl; package com.liquidnet.service.dragon.channel.alipay.strategy.impl;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler; import com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler;
import com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant; import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto; import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
...@@ -19,6 +22,7 @@ import java.util.Map; ...@@ -19,6 +22,7 @@ import java.util.Map;
* @Copyright: LightNet @ Copyright (c) 2021 * @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34 * @date 2021/7/10 14:34
*/ */
@Slf4j
@Service @Service
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.WAP) @StrategyAlipayHandler(DragonConstant.DeviceFromEnum.WAP)
public class AlipayStrategyWapImpl extends AbstractAlipayStrategy { public class AlipayStrategyWapImpl extends AbstractAlipayStrategy {
...@@ -31,6 +35,11 @@ public class AlipayStrategyWapImpl extends AbstractAlipayStrategy { ...@@ -31,6 +35,11 @@ public class AlipayStrategyWapImpl extends AbstractAlipayStrategy {
@Autowired @Autowired
StringRedisTemplate stringRedisTemplate; StringRedisTemplate stringRedisTemplate;
@Override
protected Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq) {
return AlipayUtil.tradeAppPay(alipayTradePayReq);
}
protected void setProductCode() { protected void setProductCode() {
this.productCode = "QUICK_WAP_PAY"; this.productCode = "QUICK_WAP_PAY";
} }
......
...@@ -14,43 +14,73 @@ import com.alibaba.fastjson.JSONObject; ...@@ -14,43 +14,73 @@ import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient; import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest; import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest; import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradePayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse; import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeWapPayResponse; import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.StringUtil; import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.dragon.channel.alipay.config.AlipayConfigUtil; import com.liquidnet.service.dragon.channel.alipay.config.AlipayConfigUtil;
import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq; import com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq;
import com.liquidnet.service.dragon.channel.alipay.sign.MD5; import com.liquidnet.service.dragon.channel.alipay.sign.MD5;
import com.liquidnet.service.dragon.utils.PayAlipayUtils; import com.liquidnet.service.dragon.utils.PayAlipayUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal; import java.util.Map;
import java.util.*; import java.util.SortedMap;
import java.util.TreeMap;
@Slf4j @Slf4j
public class AlipayUtil { public class AlipayUtil {
/**
* 支付宝支付
* @param alipayTradePayReq
* @return
*/
public static Map<String, Object> tradeWapPay(AlipayTradePayReq alipayTradePayReq) {
log.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString());
String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟
AlipayClient alipayClient = PayAlipayUtils.getInstance().getHttpClient();
private static final Logger logger = LoggerFactory.getLogger(AlipayUtil.class); SortedMap<String, Object> paramMap = new TreeMap<>();
paramMap.put("product_code", alipayTradePayReq.getProductCode());
paramMap.put("total_amount", alipayTradePayReq.getTotalAmount().toString());
paramMap.put("subject", alipayTradePayReq.getSubject());
paramMap.put("body", alipayTradePayReq.getBody());
paramMap.put("out_trade_no", alipayTradePayReq.getOutTradeNo());
paramMap.put("timeout_express", timeExpress);
private AlipayUtil() {
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setNotifyUrl("https://testpay.zhengzai.tv");
// request.setTimestamp(DateUtil.now());
log.info("bizContent :{}",JSONObject.toJSONString(paramMap));
request.setBizContent(JSONObject.toJSONString(paramMap));
try {
AlipayTradeWapPayResponse response = alipayClient.sdkExecute(request);
if(response.isSuccess()){
} }
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
log.info("支付宝返回结果:{}", responseJSON);
return responseJSON;
} catch (AlipayApiException e) {
log.error("支付宝支付异常:{}", e);
JSONObject resultJSON = new JSONObject();
resultJSON.put("outTradeNo", alipayTradePayReq.getOutTradeNo());
resultJSON.put("totalAmount", alipayTradePayReq.getTotalAmount().toString());
resultJSON.put("errorCode", "9999");
return resultJSON;
}
}
/** /**
* 支付宝支付 * 支付宝支付
* @param alipayTradePayReq * @param alipayTradePayReq
* @return * @return
*/ */
public static Map<String, Object> tradeWapPay(AlipayTradePayReq alipayTradePayReq) { public static Map<String, Object> tradeAppPay(AlipayTradePayReq alipayTradePayReq) {
logger.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString()); log.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString());
String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟 String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟
AlipayClient alipayClient = PayAlipayUtils.getInstance().getHttpClient(); AlipayClient alipayClient = PayAlipayUtils.getInstance().getHttpClient();
...@@ -67,7 +97,7 @@ public class AlipayUtil { ...@@ -67,7 +97,7 @@ public class AlipayUtil {
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setNotifyUrl("https://testpay.zhengzai.tv"); request.setNotifyUrl("https://testpay.zhengzai.tv");
// request.setTimestamp(DateUtil.now()); // request.setTimestamp(DateUtil.now());
logger.info("bizContent :{}",JSONObject.toJSONString(paramMap)); log.info("bizContent :{}",JSONObject.toJSONString(paramMap));
request.setBizContent(JSONObject.toJSONString(paramMap)); request.setBizContent(JSONObject.toJSONString(paramMap));
try { try {
AlipayTradeWapPayResponse response = alipayClient.sdkExecute(request); AlipayTradeWapPayResponse response = alipayClient.sdkExecute(request);
...@@ -75,10 +105,10 @@ public class AlipayUtil { ...@@ -75,10 +105,10 @@ public class AlipayUtil {
} }
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response)); JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
logger.info("支付宝返回结果:{}", responseJSON); log.info("支付宝返回结果:{}", responseJSON);
return responseJSON; return responseJSON;
} catch (AlipayApiException e) { } catch (AlipayApiException e) {
logger.error("支付宝支付异常:{}", e); log.error("支付宝支付异常:{}", e);
JSONObject resultJSON = new JSONObject(); JSONObject resultJSON = new JSONObject();
resultJSON.put("outTradeNo", alipayTradePayReq.getOutTradeNo()); resultJSON.put("outTradeNo", alipayTradePayReq.getOutTradeNo());
resultJSON.put("totalAmount", alipayTradePayReq.getTotalAmount().toString()); resultJSON.put("totalAmount", alipayTradePayReq.getTotalAmount().toString());
...@@ -94,7 +124,7 @@ public class AlipayUtil { ...@@ -94,7 +124,7 @@ public class AlipayUtil {
* @return * @return
*/ */
public static Map<String, Object> tradeQuery(String outTradeNo) { public static Map<String, Object> tradeQuery(String outTradeNo) {
logger.info("======>支付宝交易查询"); log.info("======>支付宝交易查询");
String charset = "UTF-8"; String charset = "UTF-8";
String format = "json"; String format = "json";
String signType = "RSA2"; String signType = "RSA2";
...@@ -107,10 +137,10 @@ public class AlipayUtil { ...@@ -107,10 +137,10 @@ public class AlipayUtil {
try { try {
AlipayTradeQueryResponse response = alipayClient.execute(request); AlipayTradeQueryResponse response = alipayClient.execute(request);
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response)); JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
logger.info("支付宝订单查询返回结果:{}", responseJSON); log.info("支付宝订单查询返回结果:{}", responseJSON);
return responseJSON; return responseJSON;
} catch (AlipayApiException e) { } catch (AlipayApiException e) {
logger.error("支付宝交易查询异常:{}", e); log.error("支付宝交易查询异常:{}", e);
return null; return null;
} }
} }
......
package com.liquidnet.service.dragon.channel.strategy.impl; package com.liquidnet.service.dragon.channel.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext; import com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy; import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
...@@ -28,7 +27,6 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy { ...@@ -28,7 +27,6 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy {
@Override @Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) { public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
return alipayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto); return alipayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto);
} }
} }
package com.liquidnet.service.dragon.channel.strategy.impl; package com.liquidnet.service.dragon.channel.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy; import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler; import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler;
...@@ -28,7 +27,6 @@ public class PayChannelStrategyWepayImpl implements IPayChannelStrategy { ...@@ -28,7 +27,6 @@ public class PayChannelStrategyWepayImpl implements IPayChannelStrategy {
@Override @Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) { public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
return wepayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto); return wepayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto);
} }
} }
...@@ -62,9 +62,9 @@ public class PayController { ...@@ -62,9 +62,9 @@ public class PayController {
@RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp, @RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp,
@RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl, @RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl,
@RequestParam(value = "returnUrl",required = false) String returnUrl, @RequestParam(value = "returnUrl",required = false) String returnUrl,
@RequestParam(value = "quitUrl",required = false) String quitUrl, // @RequestParam(value = "quitUrl",required = false) String quitUrl,
@RequestParam(value = "showUrl",required = false) String showUrl, // @RequestParam(value = "showUrl",required = false) String showUrl,
@RequestParam(value = "code",required = false) String code, // @RequestParam(value = "code",required = false) String code,
@RequestParam(value = "createDate",required = false) String createDate, @RequestParam(value = "createDate",required = false) String createDate,
@RequestParam(value = "expireTime",required = false) String expireTime){ @RequestParam(value = "expireTime",required = false) String expireTime){
if(payType.equalsIgnoreCase(DragonConstant.PayChannelEnum.WEPAY.getCode())){ if(payType.equalsIgnoreCase(DragonConstant.PayChannelEnum.WEPAY.getCode())){
...@@ -83,6 +83,12 @@ public class PayController { ...@@ -83,6 +83,12 @@ public class PayController {
dragonPayBaseReqDto.setOrderCode(orderCode); dragonPayBaseReqDto.setOrderCode(orderCode);
dragonPayBaseReqDto.setClientIp(clientIp); dragonPayBaseReqDto.setClientIp(clientIp);
dragonPayBaseReqDto.setNotifyUrl(notifyUrl); dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
dragonPayBaseReqDto.setReturnUrl(returnUrl);
// dragonPayBaseReqDto.setQuitUrl(quitUrl);
// dragonPayBaseReqDto.setShowUrl(showUrl);
// dragonPayBaseReqDto.setCode(code);
dragonPayBaseReqDto.setCreateDate(createDate);
dragonPayBaseReqDto.setExpireTime(expireTime);
return dragonOrdersService.dragonPay(dragonPayBaseReqDto); return dragonOrdersService.dragonPay(dragonPayBaseReqDto);
} }
} }
package com.liquidnet.service.dragon.service.impl; package com.liquidnet.service.dragon.service.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext; import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto; import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
...@@ -37,6 +38,8 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService { ...@@ -37,6 +38,8 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Override @Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) { public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
//设置支付编号
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
return payChannelStrategyContext.getStrategy(dragonPayBaseReqDto.getPayType()).dragonPay(dragonPayBaseReqDto); return payChannelStrategyContext.getStrategy(dragonPayBaseReqDto.getPayType()).dragonPay(dragonPayBaseReqDto);
} }
} }
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