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

Commit c2a6385e authored by zhengfuxin's avatar zhengfuxin

抖音查询订单。

parent 5c007492
...@@ -31,7 +31,7 @@ public enum DragonErrorCodeEnum { ...@@ -31,7 +31,7 @@ public enum DragonErrorCodeEnum {
TRADE_DOUYINPAY_SIGN_ERROR("PAY0030001","抖音签名异常!"), TRADE_DOUYINPAY_SIGN_ERROR("PAY0030001","抖音签名异常!"),
TRADE_DOUYINPAY_QUERY_ERROR("PAY0030002","抖音查询退款异常!"), TRADE_DOUYINPAY_QUERY_ERROR("PAY0030002","抖音查询支付订单异常!"),
TRADE_WEPAY_QUERY_ERROR("PAY0020002","微信订单查询失败!"); TRADE_WEPAY_QUERY_ERROR("PAY0020002","微信订单查询失败!");
......
package com.liquidnet.service.dragon.channel.douyinpay.biz;
import com.alibaba.fastjson.JSON;
import com.liquidnet.service.dragon.utils.PayDouYinpayUtils;
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;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
/**
* @author zhangfuxin
* @Description:
* @date 2021/11/12 上午11:15
*/
@Slf4j
@Component
public class DouYinPayBiz {
@Value("${liquidnet.dragon.wepay.merchantId}")
private String merchantId;
/**
* @author zhangfuxin
* @Description:抖音订单查询 实现
* @date 2021/11/12 上午11:27
*/
public Map<String, Object> tradeQuery(String outOrderNo, String appid) {
Map<String, Object> respMap = new HashMap<>();
log.info("DouYinPayBiz.tradeQuery-->> request out_order_no:{} appid:{} ",outOrderNo,appid);
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("app_id", appid);
parameters.put("out_order_no", outOrderNo);
//生成签名
String sign = PayDouYinpayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign);
//map转string
String data = JSON.toJSONString(parameters);
log.info("抖音订单查询请求参数:{}",data);
try {
HttpPost httpost = new HttpPost("https://developer.toutiao.com/api/apps/ecpay/v1/query_order");
httpost.setEntity(new StringEntity(data, "UTF-8"));
CloseableHttpClient httpClient = PayDouYinpayUtils.getInstance().getHttpClient();
CloseableHttpResponse response = httpClient.execute(httpost);
HttpEntity entity = response.getEntity();
//接受到返回信息
String json = EntityUtils.toString(response.getEntity(), "UTF-8");
log.info("抖音订单查询接口返回:{}",json);
EntityUtils.consume(entity);
respMap=JSON.parseObject(json, HashMap.class);
}catch (Exception e){
log.error(e.getMessage());
}
return respMap;
}
}
...@@ -5,6 +5,7 @@ import com.liquidnet.common.exception.LiquidnetServiceException; ...@@ -5,6 +5,7 @@ import com.liquidnet.common.exception.LiquidnetServiceException;
import com.liquidnet.commons.lang.util.DateUtil; import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.dragon.biz.DragonServiceCommonBiz; import com.liquidnet.service.dragon.biz.DragonServiceCommonBiz;
import com.liquidnet.service.dragon.channel.douyinpay.biz.DouYinPayBiz;
import com.liquidnet.service.dragon.channel.douyinpay.constant.DouYinpayConstant; import com.liquidnet.service.dragon.channel.douyinpay.constant.DouYinpayConstant;
import com.liquidnet.service.dragon.channel.douyinpay.strategy.IDouYinpayStrategy; import com.liquidnet.service.dragon.channel.douyinpay.strategy.IDouYinpayStrategy;
import com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz; import com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz;
...@@ -50,7 +51,7 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy { ...@@ -50,7 +51,7 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy {
// 订单过期时间(秒); 最小 15 分钟,最大两天 // 订单过期时间(秒); 最小 15 分钟,最大两天
private int valid_time=60*60*24*2; private int valid_time=60*60*24*2;
@Autowired @Autowired
private WepayBiz wepayBiz; private DouYinPayBiz douYinPayBiz;
@Autowired @Autowired
private DataUtils dataUtils; private DataUtils dataUtils;
...@@ -74,7 +75,7 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy { ...@@ -74,7 +75,7 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy {
String sign = PayDouYinpayUtils.getInstance().createSign(parameters); String sign = PayDouYinpayUtils.getInstance().createSign(parameters);
parameters.put("sign", sign); parameters.put("sign", sign);
//构造支付请求xml //map转string
String data = JSON.toJSONString(parameters); String data = JSON.toJSONString(parameters);
log.info("dragonPay:douYinPay:"+dragonPayBaseReqDto.getDeviceFrom()+" request jsondata: {} ",data); log.info("dragonPay:douYinPay:"+dragonPayBaseReqDto.getDeviceFrom()+" request jsondata: {} ",data);
...@@ -134,7 +135,6 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy { ...@@ -134,7 +135,6 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy {
* @return * @return
*/ */
protected SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto){ protected SortedMap<String, Object> buildRequestParamMap(DragonPayBaseReqDto dragonPayBaseReqDto){
String nonceStr = PayWepayUtils.getInstance().getNonceStr();
SortedMap<String, Object> parameters = new TreeMap<>(); SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("total_amount", dragonPayBaseReqDto.getPrice().multiply(BigDecimal.valueOf(100L)).intValue()); parameters.put("total_amount", dragonPayBaseReqDto.getPrice().multiply(BigDecimal.valueOf(100L)).intValue());
//商品描述; 长度限制 128 字节,不超过 42 个汉字 //商品描述; 长度限制 128 字节,不超过 42 个汉字
...@@ -175,13 +175,13 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy { ...@@ -175,13 +175,13 @@ public abstract class AbstractDouYinPayStrategy implements IDouYinpayStrategy {
@Override @Override
public DragonPayOrderQueryRespDto checkOrderStatus(String code) { public DragonPayOrderQueryRespDto checkOrderStatus(String code) {
DragonOrdersDto ordersDto = dataUtils.getPayOrderByCode(code); DragonOrdersDto ordersDto = dataUtils.getPayOrderByCode(code);
Map<String, Object> resultMap = wepayBiz.tradeQuery(code,this.getAppid()); Map<String, Object> resultMap = douYinPayBiz.tradeQuery(code,this.getAppid());
DragonPayOrderQueryRespDto respDto = dragonPayBiz.buildPayOrderQueryRespDto(ordersDto); DragonPayOrderQueryRespDto respDto = dragonPayBiz.buildPayOrderQueryRespDto(ordersDto);
Object returnCode = resultMap.get("return_code"); Object orderStatus = resultMap.get("order_status");
// 查询失败 // 查询失败
if (null == returnCode || "FAIL".equals(returnCode)) { if (null == orderStatus || "FAIL".equals(orderStatus)) {
throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_WEPAY_QUERY_ERROR.getCode(),DragonErrorCodeEnum.TRADE_WEPAY_QUERY_ERROR.getMessage()); throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getCode(),DragonErrorCodeEnum.TRADE_DOUYINPAY_QUERY_ERROR.getMessage());
} }
// 当trade_state为SUCCESS时才返回result_code // 当trade_state为SUCCESS时才返回result_code
if ("SUCCESS".equals(resultMap.get("trade_state"))) { if ("SUCCESS".equals(resultMap.get("trade_state"))) {
......
...@@ -56,6 +56,6 @@ public class DouYinPayStrategyAppletImpl extends AbstractDouYinPayStrategy { ...@@ -56,6 +56,6 @@ public class DouYinPayStrategyAppletImpl extends AbstractDouYinPayStrategy {
@Override @Override
protected String getAppid() { protected String getAppid() {
return PayWepayUtils.getInstance().getAPP_ID(); return PayDouYinpayUtils.getInstance().getAPP_ID();
} }
} }
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