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

Commit 0de8e961 authored by jiangxiulong's avatar jiangxiulong

Merge remote-tracking branch 'origin/dev' into dev

parents 5dc246c7 7f96996d
package com.liquidnet.service.dragon.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
......@@ -30,4 +28,7 @@ public class DragonPayBaseReqDto {
private String code;
private String createDate;
private String expireTime;
private String quitUrl;
private String showUrl;
private String returnUrl;
}
......@@ -37,13 +37,10 @@ public class DragonPayBaseRespDto {
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class PayData{
@JsonProperty("appId")
private String appId;
@JsonProperty("nonceStr")
private String nonceStr;
@JsonProperty("timeStamp")
private String timeStamp;
@JsonProperty("package")
......
......@@ -18,6 +18,9 @@ public interface IDragonOrderRefundsService {
* @param price 退款金额
* @param paymentType 支付类型
*/
ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String tradeNo, String outTradeNo, String reason, String returnUrl, BigDecimal price, String paymentType,String paymentId);
ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String tradeNo, String outTradeNo, String reason, String returnUrl, BigDecimal price, String paymentType,String paymentId,BigDecimal priceTotal);
ResponseDto<DragonRefundAppDto> wePayRefundCallBack();
}
......@@ -4,10 +4,10 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
public class IdentityUtils {
private String aliThirdUrl = "https://1.api.apistore.cn/idcard3";
private String aliThirdAppCode = "cc29fa8cb494468289dec09df46922b5";
private static String aliThirdUrl = "https://1.api.apistore.cn/idcard3";
private static String aliThirdAppCode = "cc29fa8cb494468289dec09df46922b5";
public String aliThird(String realName,String cardNo){
public static String aliThird(String realName,String cardNo){
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("realName",realName);
params.add("cardNo",cardNo);
......
......@@ -51,7 +51,13 @@ public class SmsProcessor {
SendSmsResponseBody smsResponseBody = smsResponse.getBody();
return null != smsResponseBody && smsResponseBody.getCode().equalsIgnoreCase("OK");
boolean isSucc = null != smsResponseBody && "OK".equalsIgnoreCase(smsResponseBody.getCode());
if (!isSucc) {
log.warn("###短信服务发送失败[{}]", JsonUtils.toJson(smsResponse));
}
return isSucc;
} catch (Exception e) {
log.error("API处理异常", e);
}
......@@ -81,7 +87,13 @@ public class SmsProcessor {
SendBatchSmsResponseBody batchSmsResponseBody = batchSmsResponse.getBody();
return null != batchSmsResponseBody && batchSmsResponseBody.getCode().equalsIgnoreCase("OK");
boolean isSucc = null != batchSmsResponseBody && "OK".equalsIgnoreCase(batchSmsResponseBody.getCode());
if (!isSucc) {
log.warn("###短信服务发送失败[{}]", JsonUtils.toJson(batchSmsResponse));
}
return isSucc;
} catch (Exception e) {
log.error("API处理异常", e);
}
......
......@@ -25,10 +25,10 @@ liquidnet:
dragon:
alipay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/alipay
notify-url: https://testdragon.zhengzai.tv/dragon/notify/alipay
wepay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/wepay
notify-url: https://testdragon.zhengzai.tv/dragon/notify/wepay
merchantId: 1551961491
appId: wx3498304dda39c5a1
parentKey: itIuO65O9yKmemOu3S8g1S4orqvCGwXK
......
......@@ -25,10 +25,10 @@ liquidnet:
dragon:
alipay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/alipay
notify-url: https://testdragon.zhengzai.tv/dragon/notify/alipay
wepay:
gataway-url: https://openapi.alipay.com/gateway.do
notify-url: https://testpay.zhengzai.tv/wepay
notify-url: https://testdragon.zhengzai.tv/dragon/notify/wepay
merchantId: 1551961491
appId: wx3498304dda39c5a1
parentKey: itIuO65O9yKmemOu3S8g1S4orqvCGwXK
\ No newline at end of file
package com.liquidnet.service.adam.service.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.commons.lang.util.*;
......@@ -270,24 +271,31 @@ public class AdamEntersServiceImpl implements IAdamEntersService {
}
private void identityHandler(String currentUid, String name, String idCard) {
String respStr = null;
try {
LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("realName", name);
paramsMap.add("cardNo", idCard);
long s = System.currentTimeMillis();
respStr = HttpUtil.postToPhpApi(env.getProperty("liquidnet.url-service.url") + PHP_API_REAL_NAME, paramsMap);
log.debug("#PHP.API耗时:{}ms", System.currentTimeMillis() - s);
log.debug("###PHP.API[{}].RESP:{}", PHP_API_REAL_NAME, respStr);
Map respMap = JsonUtils.fromJson(respStr, Map.class);
if (CollectionUtils.isEmpty(respMap) || !StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"))) {
log.warn("PHP.API实名认证失败[uid:{},name:{},idCard:{},respStr:{}]", currentUid, name, idCard, respStr);
ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
}
} catch (Exception e) {
log.error("PHP.API实名认证异常[uid:{},name:{},idCard:{},respStr:{}]", currentUid, name, idCard, respStr, e);
// String respStr = null;
// try {
// LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
// paramsMap.add("realName", name);
// paramsMap.add("cardNo", idCard);
//
// long s = System.currentTimeMillis();
// respStr = HttpUtil.postToPhpApi(env.getProperty("liquidnet.url-service.url") + PHP_API_REAL_NAME, paramsMap);
// log.debug("#PHP.API耗时:{}ms", System.currentTimeMillis() - s);
// log.debug("###PHP.API[{}].RESP:{}", PHP_API_REAL_NAME, respStr);
// Map respMap = JsonUtils.fromJson(respStr, Map.class);
// if (CollectionUtils.isEmpty(respMap) || !StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"))) {
// log.warn("PHP.API实名认证失败[uid:{},name:{},idCard:{},respStr:{}]", currentUid, name, idCard, respStr);
// ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
// throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
// }
// } catch (Exception e) {
// log.error("PHP.API实名认证异常[uid:{},name:{},idCard:{},respStr:{}]", currentUid, name, idCard, respStr, e);
// ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
// throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
// }
String respStr = IdentityUtils.aliThird(name, idCard);
JsonNode respJNode = JsonUtils.fromJson(respStr, JsonNode.class);
if (null == respJNode || !"0".equals(respJNode.get("error_code").asText())) {
log.info("###实名认证失败[{}]", respStr);
ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
}
......
package com.liquidnet.service.adam.service.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.liquidnet.common.cache.redisson.util.RedisLockUtil;
import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.SensitizeUtil;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.adam.constant.AdamRedisConst;
import com.liquidnet.service.adam.dto.AdamThirdPartParam;
import com.liquidnet.service.adam.dto.vo.*;
......@@ -367,23 +365,30 @@ public class AdamUserServiceImpl implements IAdamUserService {
vo = adamRdmService.getRealInfoVoByUid(uid);
if (null == vo) {
if (!adamRdmService.isCertification(1, idCard, name)) {
String respStr = null;
try {
LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("realName", name);
paramsMap.add("cardNo", idCard);
long s = System.currentTimeMillis();
respStr = HttpUtil.postToPhpApi(env.getProperty("liquidnet.url-service.url") + PHP_API_REAL_NAME, paramsMap);
log.debug("#PHP.API耗时:{}ms", System.currentTimeMillis() - s);
log.debug("###PHP.API[{}].RESP:{}", PHP_API_REAL_NAME, respStr);
Map respMap = JsonUtils.fromJson(respStr, Map.class);
if (CollectionUtils.isEmpty(respMap) || !StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"))) {
log.warn("PHP.API实名认证失败[uid:{},name:{},idCard:{},respStr:{}]", uid, name, idCard, respStr);
ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
}
} catch (Exception e) {
log.error("PHP.API实名认证异常[uid:{},name:{},idCard:{},respStr:{}]", uid, name, idCard, respStr, e);
// String respStr = null;
// try {
// LinkedMultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
// paramsMap.add("realName", name);
// paramsMap.add("cardNo", idCard);
// long s = System.currentTimeMillis();
// respStr = HttpUtil.postToPhpApi(env.getProperty("liquidnet.url-service.url") + PHP_API_REAL_NAME, paramsMap);
// log.debug("#PHP.API耗时:{}ms", System.currentTimeMillis() - s);
// log.debug("###PHP.API[{}].RESP:{}", PHP_API_REAL_NAME, respStr);
// Map respMap = JsonUtils.fromJson(respStr, Map.class);
// if (CollectionUtils.isEmpty(respMap) || !StringUtils.equalsIgnoreCase("OK", (String) respMap.get("message"))) {
// log.warn("PHP.API实名认证失败[uid:{},name:{},idCard:{},respStr:{}]", uid, name, idCard, respStr);
// ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
// throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
// }
// } catch (Exception e) {
// log.error("PHP.API实名认证异常[uid:{},name:{},idCard:{},respStr:{}]", uid, name, idCard, respStr, e);
// ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
// throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
// }
String respStr = IdentityUtils.aliThird(name, idCard);
JsonNode respJNode = JsonUtils.fromJson(respStr, JsonNode.class);
if (null == respJNode || !"0".equals(respJNode.get("error_code").asText())) {
log.info("###实名认证失败[{}]", respStr);
ErrorMapping.ErrorMessage errorMessage = ErrorMapping.get("10102");
throw new LiquidnetServiceException(errorMessage.getCode(), errorMessage.getMessage());
}
......
package com.liquidnet.service.consumer.adam.service.processor;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.common.sms.processor.SmsProcessor;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SmsMessage;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
/**
* ConsumerAdamSmsProcessor.class
*
* @author zhanggb
* Created by IntelliJ IDEA at 2021/7/13
*/
@Slf4j
@Component
public class ConsumerAdamSmsProcessor {
@Resource
SmsProcessor smsProcessor;
private void consumerSmsSendHandler(Message msg, Channel channel) {
MessageProperties properties = msg.getMessageProperties();
String consumerQueue = properties.getConsumerQueue();
long deliveryTag = properties.getDeliveryTag();
log.info("CONSUMER SMS ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
String msgBody = new String(msg.getBody());
log.debug("CONSUMER SMS ==> Preparing:{}", msgBody);
try {
SmsMessage smsMessage = JsonUtils.fromJson(msgBody, SmsMessage.class);
boolean result = smsProcessor.aliyunDysmsSend(smsMessage.getPhone(), smsMessage.getSignName(), smsMessage.getTemplateCode(), smsMessage.getTemplateParam().toString());
log.debug("CONSUMER SMS result of execution:{}", result);
if (result) {
channel.basicAck(deliveryTag, false);
} else {
log.warn("###CONSUMER SMS[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody);
channel.basicAck(deliveryTag, false);
}
} catch (IOException e) {
log.error("CONSUMER SMS[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody, e);
}
}
/* ================================================================== | 短信验证码 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_CODE,
value = @Queue(MQConst.QUEUES_SMS_CODE)
),
concurrency = "25"
)
public void consumerSqlForSmsCode(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | 短信通知 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_NOTICE,
value = @Queue(MQConst.QUEUES_SMS_NOTICE)
),
concurrency = "10"
)
public void consumerSqlForSmsNotice(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | */
}
package com.liquidnet.service.consumer.adam.service.processor;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.common.sms.processor.SmsProcessor;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SmsMessage;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.consumer.adam.service.IBaseDao;
import com.rabbitmq.client.Channel;
......@@ -30,8 +28,6 @@ import java.io.IOException;
public class ConsumerAdamUCenterProcessor {
@Resource
IBaseDao baseDao;
@Resource
SmsProcessor smsProcessor;
// @RabbitListener(bindings = @QueueBinding(
// exchange = @Exchange(MQConst.EXCHANGES_LIQUIDNET_SQL), key = MQConst.ROUTING_KEY_SQL,
......@@ -83,28 +79,6 @@ public class ConsumerAdamUCenterProcessor {
}
}
private void consumerSmsSendHandler(Message msg, Channel channel) {
MessageProperties properties = msg.getMessageProperties();
String consumerQueue = properties.getConsumerQueue();
long deliveryTag = properties.getDeliveryTag();
log.info("CONSUMER SMS ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
String msgBody = new String(msg.getBody());
log.debug("CONSUMER SMS ==> Preparing:{}", msgBody);
try {
SmsMessage smsMessage = JsonUtils.fromJson(msgBody, SmsMessage.class);
boolean result = smsProcessor.aliyunDysmsSend(smsMessage.getPhone(), smsMessage.getSignName(), smsMessage.getTemplateCode(), smsMessage.getTemplateParam().toString());
log.debug("CONSUMER SMS result of execution:{}", result);
if (result) {
channel.basicAck(deliveryTag, false);
} else {
log.warn("###CONSUMER SMS[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody);
channel.basicAck(deliveryTag, false);
}
} catch (IOException e) {
log.error("CONSUMER SMS[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody, e);
}
}
/* ================================================================== | 用户注册 */
@RabbitListener(
......@@ -146,35 +120,4 @@ public class ConsumerAdamUCenterProcessor {
public void consumerSqlForUMember(Message msg, Channel channel) {
this.consumerSqlDaoHandler(msg, channel);
}
/* ================================================================== | 短信验证码 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_CODE,
value = @Queue(MQConst.QUEUES_SMS_CODE)
),
concurrency = "10"
)
public void consumerSqlForSmsCode(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | 短信通知 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_NOTICE,
value = @Queue(MQConst.QUEUES_SMS_NOTICE)
),
concurrency = "5"
)
public void consumerSqlForSmsNotice(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | */
}
......@@ -31,6 +31,10 @@
<artifactId>liquidnet-common-cache-redisson</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-cache-redis</artifactId>
......@@ -42,8 +46,9 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<groupId>com.liquidnet</groupId>
<artifactId>liquidnet-common-sms</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
......
package com.liquidnet.service.consumer.kylin.service.processor;
import com.liquidnet.common.mq.constant.MQConst;
import com.liquidnet.common.sms.processor.SmsProcessor;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.service.base.SmsMessage;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
/**
* ConsumerAdamSmsProcessor.class
*
* @author zhanggb
* Created by IntelliJ IDEA at 2021/7/13
*/
@Slf4j
@Component
public class ConsumerKylinSmsProcessor {
@Resource
SmsProcessor smsProcessor;
private void consumerSmsSendHandler(Message msg, Channel channel) {
MessageProperties properties = msg.getMessageProperties();
String consumerQueue = properties.getConsumerQueue();
long deliveryTag = properties.getDeliveryTag();
log.info("CONSUMER SMS ==> [consumerQueue:{},deliveryTag:{}]", consumerQueue, deliveryTag);
String msgBody = new String(msg.getBody());
log.debug("CONSUMER SMS ==> Preparing:{}", msgBody);
try {
SmsMessage smsMessage = JsonUtils.fromJson(msgBody, SmsMessage.class);
boolean result = smsProcessor.aliyunDysmsSend(smsMessage.getPhone(), smsMessage.getSignName(), smsMessage.getTemplateCode(), smsMessage.getTemplateParam().toString());
log.debug("CONSUMER SMS result of execution:{}", result);
if (result) {
channel.basicAck(deliveryTag, false);
} else {
log.warn("###CONSUMER SMS[consumerQueue:{},deliveryTag={},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody);
channel.basicAck(deliveryTag, false);
}
} catch (IOException e) {
log.error("CONSUMER SMS[consumerQueue:{},deliveryTag:{},sqlMessage:{}]", consumerQueue, deliveryTag, msgBody, e);
}
}
/* ================================================================== | 短信验证码 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_CODE,
value = @Queue(MQConst.QUEUES_SMS_CODE)
),
concurrency = "25"
)
public void consumerSqlForSmsCode(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | 短信通知 */
@RabbitListener(
bindings = @QueueBinding(
exchange = @Exchange(MQConst.EX_LNS_SMS_SENDER),
key = MQConst.RK_SMS_NOTICE,
value = @Queue(MQConst.QUEUES_SMS_NOTICE)
),
concurrency = "10"
)
public void consumerSqlForSmsNotice(Message msg, Channel channel) {
this.consumerSmsSendHandler(msg, channel);
}
/* ================================================================== | */
}
......@@ -22,6 +22,8 @@ public class AlipayTradePayReq {
private String body;
private String outTradeNo;
private String timeExpire;
private String notifyUrl;
private String timestamp;
@Override
public String toString(){
return JSON.toJSONString(this);
......
......@@ -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.req.AlipayTradePayReq;
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.DragonPayBaseRespDto;
import lombok.extern.slf4j.Slf4j;
......@@ -42,8 +41,11 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy {
//dragon中支付编号
alipayTradePayReq.setOutTradeNo(dragonPayBaseReqDto.getCode());
alipayTradePayReq.setTimeExpire(dragonPayBaseReqDto.getExpireTime());
alipayTradePayReq.setNotifyUrl(this.getNotifyUrl());
alipayTradePayReq.setTimestamp(dragonPayBaseReqDto.getCreateDate());
//调用支付
Map<String, Object> result = AlipayUtil.tradeWapPay(alipayTradePayReq);
Map<String, Object> result = this.executePay(alipayTradePayReq);
//拼接返回参数
DragonPayBaseRespDto respDto = buildCommonRespDto(dragonPayBaseReqDto);
respDto = this.buildResponseDto(respDto,result);
......@@ -53,11 +55,23 @@ public abstract class AbstractAlipayStrategy implements IAlipayStrategy {
return ResponseDto.success(respDto);
}
/**
* 支付请求
* @param alipayTradePayReq
* @return
*/
protected abstract Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq);
/**
* 设置productCode
*/
protected abstract void setProductCode();
/**
* 设置notifyUrl
*/
protected abstract String getNotifyUrl();
/**
* 构造公共返回参数
* @param dragonPayBaseReqDto
......
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.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
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.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
......@@ -19,22 +22,37 @@ import java.util.Map;
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Component
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.APP)
public class AlipayStrategyAppImpl extends AbstractAlipayStrategy {
@Value("${liquidnet.dragon.alipay.gataway-url}")
private String alipayGatewayUrl;
@Value("${liquidnet.dragon.alipay.notify-url}")
private String notifyUrl;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Override
protected Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq) {
return AlipayUtil.tradeAppPay(alipayTradePayReq);
}
protected void setProductCode() {
this.productCode = "QUICK_MSECURITY_PAY";
}
@Override
protected String getNotifyUrl() {
// notifyUrl = "/notify/app/alipay/1";
return notifyUrl + "/app";
}
@Override
DragonPayBaseRespDto buildResponseDto(DragonPayBaseRespDto payBaseRespDto, Map<String, Object> respResult) {
payBaseRespDto.getPayData().setRedirectUrl(alipayGatewayUrl + "?" + respResult.get("body"));
payBaseRespDto.getPayData().setOrderStr(alipayGatewayUrl + "?" + respResult.get("body"));
return payBaseRespDto;
}
}
\ No newline at end of file
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.util.AlipayUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
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.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
......@@ -19,19 +22,34 @@ import java.util.Map;
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Service
@StrategyAlipayHandler(DragonConstant.DeviceFromEnum.WAP)
public class AlipayStrategyWapImpl extends AbstractAlipayStrategy {
@Value("${liquidnet.dragon.alipay.gataway-url}")
private String alipayGatewayUrl;
@Value("${liquidnet.dragon.alipay.notify-url}")
private String notifyUrl;
@Autowired
StringRedisTemplate stringRedisTemplate;
@Override
protected Map<String, Object> executePay(AlipayTradePayReq alipayTradePayReq) {
return AlipayUtil.tradeWapPay(alipayTradePayReq);
}
protected void setProductCode() {
this.productCode = "QUICK_WAP_PAY";
}
@Override
protected String getNotifyUrl() {
// notifyUrl = "/notify/wap/alipay/1";
return notifyUrl + "/wap";
}
@Override
DragonPayBaseRespDto buildResponseDto(DragonPayBaseRespDto payBaseRespDto, Map<String, Object> respResult) {
payBaseRespDto.getPayData().setRedirectUrl(alipayGatewayUrl + "?" + respResult.get("body"));
......
......@@ -14,34 +14,63 @@ import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradePayResponse;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.StringUtil;
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.sign.MD5;
import com.liquidnet.service.dragon.utils.PayAlipayUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.util.*;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@Slf4j
public class AlipayUtil {
/**
* 支付宝支付
* @param alipayTradePayReq
* @return
*/
public static Map<String, Object> tradeWapPay(AlipayTradePayReq alipayTradePayReq) {
log.info("AlipayUtil.tradeWapPay-->> 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(alipayTradePayReq.getNotifyUrl());
// request.setTimestamp(DateUtil.now());
log.info("bizContent :{}",JSONObject.toJSONString(paramMap));
request.setBizContent(JSONObject.toJSONString(paramMap));
try {
AlipayTradeWapPayResponse response = alipayClient.sdkExecute(request);
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
log.info("AlipayUtil-->tradeWapPay-->支付宝返回结果:{}", 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;
}
}
/**
......@@ -49,8 +78,8 @@ public class AlipayUtil {
* @param alipayTradePayReq
* @return
*/
public static Map<String, Object> tradeWapPay(AlipayTradePayReq alipayTradePayReq) {
logger.info("AlipayUtil.tradePay-->> req : {}",alipayTradePayReq.toString());
public static Map<String, Object> tradeAppPay(AlipayTradePayReq alipayTradePayReq) {
log.info("AlipayUtil.tradeAppPay-->> req : {}",alipayTradePayReq.toString());
String timeExpress = "5m";// 支付超时,线下扫码交易定义为5分钟
AlipayClient alipayClient = PayAlipayUtils.getInstance().getHttpClient();
......@@ -64,21 +93,18 @@ public class AlipayUtil {
paramMap.put("timeout_express", timeExpress);
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setNotifyUrl("https://testpay.zhengzai.tv");
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
request.setNotifyUrl(alipayTradePayReq.getNotifyUrl());
// request.setTimestamp(DateUtil.now());
logger.info("bizContent :{}",JSONObject.toJSONString(paramMap));
log.info("bizContent :{}",JSONObject.toJSONString(paramMap));
request.setBizContent(JSONObject.toJSONString(paramMap));
try {
AlipayTradeWapPayResponse response = alipayClient.sdkExecute(request);
if(response.isSuccess()){
}
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
logger.info("支付宝返回结果:{}", responseJSON);
log.info("AlipayUtil-->tradeAppPay-->支付宝返回结果:{}", responseJSON);
return responseJSON;
} catch (AlipayApiException e) {
logger.error("支付宝支付异常:{}", e);
log.error("支付宝支付异常:{}", e);
JSONObject resultJSON = new JSONObject();
resultJSON.put("outTradeNo", alipayTradePayReq.getOutTradeNo());
resultJSON.put("totalAmount", alipayTradePayReq.getTotalAmount().toString());
......@@ -94,7 +120,7 @@ public class AlipayUtil {
* @return
*/
public static Map<String, Object> tradeQuery(String outTradeNo) {
logger.info("======>支付宝交易查询");
log.info("======>支付宝交易查询");
String charset = "UTF-8";
String format = "json";
String signType = "RSA2";
......@@ -107,10 +133,10 @@ public class AlipayUtil {
try {
AlipayTradeQueryResponse response = alipayClient.execute(request);
JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
logger.info("支付宝订单查询返回结果:{}", responseJSON);
log.info("支付宝订单查询返回结果:{}", responseJSON);
return responseJSON;
} catch (AlipayApiException e) {
logger.error("支付宝交易查询异常:{}", e);
log.error("支付宝交易查询异常:{}", e);
return null;
}
}
......
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.dragon.channel.alipay.strategy.AlipayStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
......@@ -28,7 +27,6 @@ public class PayChannelStrategyAlipayImpl implements IPayChannelStrategy {
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
return alipayStrategyContext.getStrategy(dragonPayBaseReqDto.getDeviceFrom()).dragonPay(dragonPayBaseReqDto);
}
}
package com.liquidnet.service.dragon.channel.strategy.impl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext;
import com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy;
import com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler;
import com.liquidnet.service.dragon.channel.wepay.strategy.WepayStrategyContext;
......@@ -11,9 +10,6 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseRespDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
......
package com.liquidnet.service.dragon.channel.wepay.resp;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
@Data
@XStreamAlias("xml")
public class WePayRefundReturnDto {
@XStreamAlias("return_code")
private String returnCode;
@XStreamAlias("return_msg")
private String returnMsg;
@XStreamAlias("appid")
private String appId;
@XStreamAlias("mch_id")
private String mchId;
@XStreamAlias("nonce_str")
private String nonceStr;
@XStreamAlias("sign")
private String sign;
@XStreamAlias("result_code")
private String resultCode;
@XStreamAlias("transaction_id")
private String transactionId;
@XStreamAlias("out_trade_no")
private String outTradeNo;
@XStreamAlias("out_refund_no")
private String outRefundNo;
@XStreamAlias("refund_id")
private String refundId;
@XStreamAlias("refund_channel")
private String refundChannel;
@XStreamAlias("refund_fee")
private String refundFee;
@XStreamAlias("coupon_refund_fee")
private String couponRefundFee;
@XStreamAlias("total_fee")
private String totalFee;
@XStreamAlias("cash_fee")
private String cashFee;
@XStreamAlias("coupon_refund_count")
private String couponRefundCount;
@XStreamAlias("cash_refund_fee")
private String cashRefundFee;
}
package com.liquidnet.service.dragon.channel.wepay.strategy.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WepayPayRespDto;
import com.liquidnet.service.dragon.channel.wepay.strategy.IWepayStrategy;
......@@ -60,7 +60,7 @@ public abstract class AbstractWepayStrategy implements IWepayStrategy {
WepayPayRespDto respWepayDto= XmlUtil.toBean(xmlStr, WepayPayRespDto.class);
//构造公共返回参数
DragonPayBaseRespDto respPayDto = this.buildCommonRespDto(dragonPayBaseReqDto);
DragonPayBaseRespDto respPayDto = this.buildCommonRespDto(dragonPayBaseReqDto,respWepayDto);
//构造自定义返回参数
this.buildResponseDto(respPayDto,respWepayDto);
......@@ -76,11 +76,17 @@ public abstract class AbstractWepayStrategy implements IWepayStrategy {
* @param dragonPayBaseReqDto
* @return
*/
protected DragonPayBaseRespDto buildCommonRespDto(DragonPayBaseReqDto dragonPayBaseReqDto){
protected DragonPayBaseRespDto buildCommonRespDto(DragonPayBaseReqDto dragonPayBaseReqDto,WepayPayRespDto respWepayDto){
DragonPayBaseRespDto respDto = new DragonPayBaseRespDto();
respDto.setCode(dragonPayBaseReqDto.getCode());
respDto.setOrderCode(dragonPayBaseReqDto.getOrderCode());
DragonPayBaseRespDto.PayData payData = new DragonPayBaseRespDto.PayData();
payData.setAppId(respWepayDto.getAppid());
payData.setNonceStr(respWepayDto.getNonceStr());
payData.setPackages("prepay_id="+respWepayDto.getPrepayId());
payData.setPaySign(respWepayDto.getSign());
payData.setSignType("MD5");
payData.setTimeStamp(Long.valueOf(DateUtil.now().getTime()).toString());
respDto.setPayData(payData);
return respDto;
}
......@@ -99,10 +105,9 @@ public abstract class AbstractWepayStrategy implements IWepayStrategy {
parameters.put("total_fee", dragonPayBaseReqDto.getPrice().multiply(BigDecimal.valueOf(100L)).intValue());
parameters.put("body", dragonPayBaseReqDto.getName());
parameters.put("detail", dragonPayBaseReqDto.getDetail());
parameters.put("out_trade_no", IDGenerator.payCode());
parameters.put("out_trade_no", dragonPayBaseReqDto.getCode());
parameters.put("time_expire", "20210908103456");
parameters.put("notify_url", "https://www.baidu.com");
parameters.put("trade_type", "MWEB");
parameters.put("notify_url", dragonPayBaseReqDto.getNotifyUrl());
return parameters;
};
......
......@@ -24,6 +24,7 @@ import java.util.SortedMap;
public class WepayStrategyAppImpl extends AbstractWepayStrategy {
@Override
SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap) {
requestMap.put("trade_type", "APP");
return requestMap;
}
......
......@@ -24,6 +24,8 @@ import java.util.SortedMap;
public class WepayStrategyAppletImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap) {
requestMap.put("trade_type", "JSAPI");
requestMap.put("openid", requestMap.get("openId"));
return requestMap;
}
......
......@@ -24,6 +24,8 @@ import java.util.SortedMap;
public class WepayStrategyJsImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap) {
requestMap.put("trade_type", "JSAPI");
requestMap.put("openid", requestMap.get("openId"));
return requestMap;
}
......
......@@ -24,6 +24,7 @@ import java.util.SortedMap;
public class WepayStrategyWapImpl extends AbstractWepayStrategy{
@Override
SortedMap<String, Object> appendRequestParam(SortedMap<String, Object> requestMap) {
requestMap.put("trade_type", "MWEB");
return requestMap;
}
......
......@@ -47,13 +47,13 @@ public class PayController {
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "detail", value = "订单描述", example = "测试订单001"),
@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 = "pay.zhengzai.tv"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "testdragon.zhengzai.tv"),
})
@ResponseBody
public ResponseDto<DragonPayBaseRespDto> dragonPay(
@RequestParam(value = "payType") @NotNull(message = "支付类型不能为空") String payType,
@RequestParam(value = "deviceFrom") @NotNull(message = "设备来源不能为空") String deviceFrom,
@RequestParam(value = "openId") String openId,
@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,
......@@ -62,11 +62,12 @@ public class PayController {
@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 = "quitUrl",required = false) String quitUrl,
@RequestParam(value = "showUrl",required = false) String showUrl,
@RequestParam(value = "code",required = false) String code,
// @RequestParam(value = "quitUrl",required = false) String quitUrl,
// @RequestParam(value = "showUrl",required = false) String showUrl,
// @RequestParam(value = "code",required = false) String code,
@RequestParam(value = "createDate",required = false) String createDate,
@RequestParam(value = "expireTime",required = false) String expireTime){
//为什么在js和applet中才需要判断open_id?
if(payType.equalsIgnoreCase(DragonConstant.PayChannelEnum.WEPAY.getCode())){
if(StringUtil.isEmpty(openId)){
return ResponseDto.failure("微信支付openId不能为空!");
......@@ -83,6 +84,12 @@ public class PayController {
dragonPayBaseReqDto.setOrderCode(orderCode);
dragonPayBaseReqDto.setClientIp(clientIp);
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);
}
}
......@@ -41,9 +41,10 @@ public class RefundController {
@RequestParam(value = "orderRefundCode") @NotNull(message = "退款单号不能为空") String orderRefundCode,
@RequestParam(value = "reason") @NotNull(message = "退款原因不能为空") String reason,
@RequestParam(value = "notifyUrl") @NotNull(message = "回调地址不能为空") String returnUrl,
@RequestParam(value = "price") @NotNull(message = "价格不能为空") BigDecimal price,
@RequestParam(value = "price") @NotNull(message = "退款价格不能为空") BigDecimal price,
@RequestParam(value = "priceTotal") @NotNull(message = "订单价格不能为空") BigDecimal priceTotal,
@RequestParam(value = "paymentType") @NotNull(message = "支付类型不能为空") String paymentType,
@RequestParam(value = "paymentId") @NotNull(message = "支付订单号不能为空") String paymentId) {
return orderRefundsService.dragonRefund(orderCode, code, orderRefundCode, reason, returnUrl, price, paymentType, paymentId);
return orderRefundsService.dragonRefund(orderCode, code, orderRefundCode, reason, returnUrl, price, paymentType, paymentId, priceTotal);
}
}
......@@ -3,8 +3,6 @@ package com.liquidnet.service.dragon.service.impl;
import com.alibaba.fastjson.JSON;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
......@@ -13,9 +11,11 @@ import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonRefundAppDto;
import com.liquidnet.service.dragon.dto.DragonRefundChannelDto;
import com.liquidnet.service.dragon.dto.RefundContentDto;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import com.liquidnet.service.dragon.service.IDragonOrderRefundsService;
import com.liquidnet.service.dragon.utils.PayAlipayUtils;
import com.liquidnet.service.dragon.utils.PayWepayUtils;
import com.liquidnet.service.dragon.utils.XmlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
......@@ -28,7 +28,6 @@ import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
......@@ -42,47 +41,11 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
@Override
public void sendRedisQueue() {
try {
// PayWepayUtils payWepayUtils = new PayWepayUtils();
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<Object, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
parameters.put("appid", PayWepayUtils.getInstance().getAppId());
parameters.put("nonce_str", nonceStr);
parameters.put("out_refund_no", "20210710140233163870197466289T");
parameters.put("out_trade_no", "20210710140233163870197466289P");
parameters.put("refund_fee", "1");
parameters.put("total_fee", "1");
parameters.put("notify_url", "https://www.baidu.com");
parameters.put("refund_desc", "测试退款");
String sign = PayWepayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign);
String data = PayWepayUtils.getInstance().getRequestXml(parameters);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
try {
HttpEntity entity = response.getEntity();
//接受到返回信息
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
EntityUtils.consume(entity);
System.out.println(jsonStr);
} finally {
response.close();
}
} finally {
PayWepayUtils.getInstance().getHttpClient().close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId) {
public ResponseDto<DragonRefundAppDto> dragonRefund(String orderCode, String code, String orderRefundCode, String reason, String notifyUrl, BigDecimal price, String paymentType, String paymentId, BigDecimal priceTotal) {
try {
LocalDateTime nowTime = LocalDateTime.now();
String refundCode = IDGenerator.refundCode();
String orderRefundId = IDGenerator.nextSnowId();
......@@ -91,18 +54,45 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
SqlMapping.get("dragon_order_refund.insert"),
new Object[]{orderRefundId, refundCode, orderRefundCode, price, reason, notifyUrl, paymentType, nowTime, nowTime}
);
DragonRefundChannelDto dto = null;
if (insertResult) {
switch (paymentType) {
case DragonConstant.REFUND_TYPE_APP_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break;
case DragonConstant.REFUND_TYPE_WAP_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break;
case DragonConstant.REFUND_TYPE_WEB_ALIPAY:
aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
dto = aliPayRefund(orderRefundId, orderRefundCode, code, reason, price, paymentId, paymentType, nowTime);
break;
case DragonConstant.REFUND_TYPE_APP_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_WAP_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_WEB_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
case DragonConstant.REFUND_TYPE_JS_WEPAY:
dto = weyPayRefund(orderRefundId, orderRefundCode, code, reason, price, priceTotal, paymentId, paymentType, notifyUrl, nowTime);
break;
}
if (dto.getResult().equalsIgnoreCase("refunding")) {
log.info("");
} else if (dto.getResult().equalsIgnoreCase("refunded")) {
//调用回调
log.info("");
} else if (dto.getResult().equalsIgnoreCase("error")) {
//调用回调
log.error("");
} else if (dto.getResult().equalsIgnoreCase("exception")) {
log.error("");
}
DragonRefundAppDto refundAppDto = new DragonRefundAppDto();
refundAppDto.setOrderCode(orderCode);
refundAppDto.setCode(code);
......@@ -112,12 +102,122 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
} else {
return ResponseDto.failure("退款失败");
}
} catch (Exception e) {
e.printStackTrace();
log.error("");
return ResponseDto.failure("退款失败:" + e.getMessage());
}
}
@Override
public ResponseDto<DragonRefundAppDto> wePayRefundCallBack() {
return null;
}
public void weyPayRefund() {
public DragonRefundChannelDto weyPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, BigDecimal priceTotal, String paymentId, String paymentType, String notifyUrl, LocalDateTime nowTime) {
try {
String refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
DragonRefundChannelDto channelDto = new DragonRefundChannelDto();
RefundContentDto contentDto = new RefundContentDto();
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<Object, Object> parameters = new TreeMap<>();
parameters.put("mch_id", PayWepayUtils.getInstance().getMerchantId());
parameters.put("appid", PayWepayUtils.getInstance().getAppId());
parameters.put("nonce_str", nonceStr);
parameters.put("out_refund_no", refundCode);
parameters.put("out_trade_no", code);
parameters.put("refund_fee", price.doubleValue() * 100);
parameters.put("total_fee", priceTotal.doubleValue() * 100);
parameters.put("notify_url", notifyUrl);
parameters.put("refund_desc", reason);
String sign = PayWepayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign);
String data = PayWepayUtils.getInstance().getRequestXml(parameters);
try {
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpResponse response = PayWepayUtils.getInstance().getHttpClient().execute(httpost);
try {
HttpEntity entity = response.getEntity();
entity.getContent();
String jsonStr = EntityUtils.toString(entity, "UTF-8");
WePayRefundReturnDto wePayRefundReturnDto = XmlUtil.toBean(jsonStr, WePayRefundReturnDto.class);
if (!wePayRefundReturnDto.getResultCode().equalsIgnoreCase("SUCCESS") || wePayRefundReturnDto.getResultCode() == null) {
try {
String refundError = "";
refundStatus = DragonConstant.RefundStatusEnum.STATUS_ERROR.getCode();
if (null == wePayRefundReturnDto.getReturnMsg()) {
refundError = "退款失败,原因未知";
} else {
refundError = wePayRefundReturnDto.getReturnMsg();
}
// 修改退款订单
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_error.update"),
new Object[]{nowTime, refundError, refundStatus, orderRefundId}
);
} catch (Exception e) {
e.printStackTrace();
//保存错误信息
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
channelDto.setResult("error");
channelDto.setMessage(paymentType + " refund error: ");
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
// 创建退款日志
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_log.insert"),
new Object[]{orderRefundId, paymentType, data, nowTime, nowTime}
);
try {
if (wePayRefundReturnDto.getResultCode().equalsIgnoreCase("SUCCESS")) {
refundStatus = DragonConstant.RefundStatusEnum.STATUS_REFUNDED.getCode();
}
sendMySqlRedis(
SqlMapping.get("dragon_order_refund_success.update"),
new Object[]{nowTime, null, refundStatus, orderRefundId}
);
} catch (Exception e) {
e.printStackTrace();
log.error("");
channelDto.setResult("exception");
channelDto.setMessage("update order refund with db error: " + e.getMessage());
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
return channelDto;
}
channelDto.setResult("refunded");
channelDto.setMessage(paymentType + " refund info: ");
contentDto.setRequest(data);
contentDto.setResponse(jsonStr);
channelDto.setContent(contentDto);
EntityUtils.consume(entity);
return channelDto;
} finally {
response.close();
}
} finally {
PayWepayUtils.getInstance().getHttpClient().close();
}
} catch (Exception e) {
e.printStackTrace();
log.error("");
return null;
}
}
public DragonRefundChannelDto aliPayRefund(String orderRefundId, String refundCode, String code, String reason, BigDecimal price, String paymentId, String paymentType, LocalDateTime nowTime) {
String refundStatus;
......@@ -131,8 +231,7 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
"\"out_request_no\":\"" + refundCode + "\"," +
"\"refund_reason\":\"" + reason + "\"," +
"\"refund_amount\":\"" + price.doubleValue() + "\"}"); //设置业务参数
AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);//通过alipayClient调用API,获得对应的response类
System.out.print(response.getBody());
AlipayTradeRefundResponse response = PayAlipayUtils.getInstance().getHttpClient().execute(request);
if (response.getFundChange().equals("N") || response.getFundChange() == null) {
try {
String refundError = "";
......@@ -232,8 +331,4 @@ public class DragonOrderRefundsServiceImpl implements IDragonOrderRefundsService
return false;
}
}
private void wePayRefundCallBack() {
}
}
package com.liquidnet.service.dragon.service.impl;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext;
import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
......@@ -37,6 +38,8 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Override
public ResponseDto<DragonPayBaseRespDto> dragonPay(DragonPayBaseReqDto dragonPayBaseReqDto) {
//设置支付编号
dragonPayBaseReqDto.setCode(IDGenerator.payCode());
return payChannelStrategyContext.getStrategy(dragonPayBaseReqDto.getPayType()).dragonPay(dragonPayBaseReqDto);
}
}
......@@ -2,10 +2,12 @@ package com.liquidnet.service.dragon.utils;
import com.alipay.api.internal.util.file.IOUtils;
import com.liquidnet.commons.lang.util.MD5Utils;
import com.liquidnet.service.dragon.channel.wepay.resp.WePayRefundReturnDto;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.dom4j.DocumentException;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayInputStream;
......
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