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

Commit 9fb463ab authored by anjiabin's avatar anjiabin

修改通知逻辑

parent c8c39892
...@@ -56,9 +56,11 @@ public class DragonConstant { ...@@ -56,9 +56,11 @@ public class DragonConstant {
public enum PayStatusEnum{ public enum PayStatusEnum{
STATUS_UNPAID("0","未支付,或支付中"), STATUS_UNPAID("0","未支付,或支付中"),
STATUS_PAID("1","已支付"), STATUS_PAID("1","已支付"),
STATUS_SUCCESS("2","已支付,通知成功,交易结束"), STATUS_PAY_FAIL("2","支付失败"),
STATUS_FAIL("3","已支付,通知失败,交易结束"), STATUS_SUCCESS("3","已支付,通知成功,交易结束"),
STATUS_EXPIRE("4","已支付,通知超时,交易结束"); STATUS_FAIL("4","已支付,通知失败,交易结束"),
STATUS_EXPIRE("5","已支付,通知超时,交易结束");
private String code; private String code;
private String message; private String message;
......
...@@ -2,7 +2,6 @@ package com.liquidnet.service.dragon.channel.strategy.biz; ...@@ -2,7 +2,6 @@ package com.liquidnet.service.dragon.channel.strategy.biz;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.liquidnet.commons.lang.util.BeanUtil; import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.SqlMapping; import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.dragon.bo.PayNotifyReqBo; import com.liquidnet.service.dragon.bo.PayNotifyReqBo;
...@@ -15,12 +14,24 @@ import com.liquidnet.service.dragon.entity.DragonOrders; ...@@ -15,12 +14,24 @@ import com.liquidnet.service.dragon.entity.DragonOrders;
import com.liquidnet.service.dragon.utils.DataUtils; import com.liquidnet.service.dragon.utils.DataUtils;
import com.liquidnet.service.dragon.utils.MqHandleUtil; import com.liquidnet.service.dragon.utils.MqHandleUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author AnJiabin <anjiabin@zhengzai.tv> * @author AnJiabin <anjiabin@zhengzai.tv>
...@@ -218,26 +229,105 @@ public class DragonPayBiz { ...@@ -218,26 +229,105 @@ public class DragonPayBiz {
} }
// public void sendNotifyBackup(PayNotifyReqBo payNotifyReqBo){
// PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto();
// LocalDateTime nowTime = LocalDateTime.now();
// MultiValueMap<String, String> params = new LinkedMultiValueMap();
// params.add("status", payNotifyDto.getStatus().toString());
// params.add("type", payNotifyDto.getType());
// params.add("code", payNotifyDto.getCode());
// params.add("paymentId", payNotifyDto.getPaymentId());
// params.add("orderCode", payNotifyDto.getOrderCode());
// params.add("price", payNotifyDto.getPrice().toString());
// params.add("paymentType", payNotifyDto.getPaymentType());
// String jsonData = JSON.toJSONString(params);
// log.info("dragon:notify:post url:{}",payNotifyReqBo.getNotifyUrl());
// log.info("dragon:notify:post data:{}",jsonData);
// try {
// String response = HttpUtil.post(payNotifyReqBo.getNotifyUrl(), params);
// log.debug("PAY RESPONSE=" + response);
// if (response.equals("success")) {
// this.createDragonPayNotify(payNotifyReqBo,jsonData);
// //更新通知状态-通知成功
// this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_SUCCESS.getCode()));
// } else {
// this.createDragonPayNotifyFail(payNotifyReqBo,jsonData);
// //更新通知状态-通知失败
// this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_FAIL.getCode()));
// }
//
// if(true){
// throw new ConnectTimeoutException();
// }
// } catch (ConnectTimeoutException e) {
// System.out.println("请求超时");
//
// }catch (Exception e){
// e.printStackTrace();
// }
// }
public void sendNotify(PayNotifyReqBo payNotifyReqBo){ public void sendNotify(PayNotifyReqBo payNotifyReqBo){
PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto(); PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto();
LocalDateTime nowTime = LocalDateTime.now(); LocalDateTime nowTime = LocalDateTime.now();
MultiValueMap<String, String> params = new LinkedMultiValueMap(); CloseableHttpClient httpclient = HttpClients.createDefault();
params.add("status", payNotifyDto.getStatus().toString()); String jsonData = "";
params.add("type", payNotifyDto.getType()); try {
params.add("code", payNotifyDto.getCode()); HttpPost httpPost = new HttpPost(payNotifyReqBo.getNotifyUrl());
params.add("paymentId", payNotifyDto.getPaymentId()); //配置超时
params.add("orderCode", payNotifyDto.getOrderCode()); RequestConfig requestConfig = RequestConfig.custom()
params.add("price", payNotifyDto.getPrice().toString()); .setConnectTimeout(5000).setConnectionRequestTimeout(5000)
params.add("paymentType", payNotifyDto.getPaymentType()); .setSocketTimeout(5000).build();
String jsonData = JSON.toJSONString(params); httpPost.setConfig(requestConfig);
//设置post请求参数
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("status", payNotifyDto.getStatus().toString()));
nvps.add(new BasicNameValuePair("type", payNotifyDto.getType()));
nvps.add(new BasicNameValuePair("code", payNotifyDto.getCode()));
nvps.add(new BasicNameValuePair("paymentId", payNotifyDto.getPaymentId()));
nvps.add(new BasicNameValuePair("orderCode", payNotifyDto.getOrderCode()));
nvps.add(new BasicNameValuePair("price", payNotifyDto.getPrice().toString()));
nvps.add(new BasicNameValuePair("paymentType", payNotifyDto.getPaymentType()));
jsonData = JSON.toJSONString(nvps);
log.info("dragon:notify:post url:{}",payNotifyReqBo.getNotifyUrl()); log.info("dragon:notify:post url:{}",payNotifyReqBo.getNotifyUrl());
log.info("dragon:notify:post data:{}",jsonData); log.info("dragon:notify:post data:{}",jsonData);
String response = HttpUtil.post(payNotifyReqBo.getNotifyUrl(), params); httpPost.setEntity(new UrlEncodedFormEntity(nvps));
//执行post请求
CloseableHttpResponse responseObj = httpclient.execute(httpPost);
String response = EntityUtils.toString(responseObj.getEntity(), "utf-8");
log.debug("PAY RESPONSE=" + response); log.debug("PAY RESPONSE=" + response);
if (response.equals("success")) { if (response.equals("success")) {
this.createDragonPayNotify(payNotifyReqBo,jsonData); this.createDragonPayNotify(payNotifyReqBo,jsonData);
//更新通知状态-通知成功
this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_SUCCESS.getCode()));
} else { } else {
this.createDragonPayNotifyFail(payNotifyReqBo,jsonData); this.createDragonPayNotifyFail(payNotifyReqBo,jsonData);
//更新通知状态-通知失败
this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_FAIL.getCode()));
}
} catch (ConnectTimeoutException e) {
log.error("dragon:sendNotify 请求超时",e);
this.createDragonPayNotifyFail(payNotifyReqBo,jsonData);
//更新通知状态-通知失败
this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_EXPIRE.getCode()));
} catch (Exception e) {
log.error("dragon:sendNotify 请求失败",e);
this.createDragonPayNotifyFail(payNotifyReqBo,jsonData);
//更新通知状态-通知失败
this.updateNotifyStatus(payNotifyDto.getCode(),Integer.valueOf(DragonConstant.PayStatusEnum.STATUS_FAIL.getCode()));
}finally {
//释放连接
try {
if (httpclient != null) {
httpclient.close();
}
} catch (IOException e) {
log.error("连接无法关闭",e);
}
} }
} }
......
...@@ -66,11 +66,12 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat ...@@ -66,11 +66,12 @@ public abstract class AbstractPayChannelStrategyImpl implements IPayChannelStrat
*/ */
protected void completeFailOrder(DragonOrdersDto dragonOrdersDto, String bankReturnMsg) { protected void completeFailOrder(DragonOrdersDto dragonOrdersDto, String bankReturnMsg) {
log.info("订单支付失败!"); log.info("订单支付失败!");
// DragonOrdersDto.(bankReturnMsg); // dragonOrdersDto.setPaymentAt(timeEnd);
dragonOrdersDto.setStatus(Integer.parseInt(DragonConstant.PayStatusEnum.STATUS_PAID.getCode())); // dragonOrdersDto.setPaymentId(bankTrxNo);// 设置银行流水号
dragonOrdersDto.setStatus(Integer.parseInt(DragonConstant.PayStatusEnum.STATUS_UNPAID.getCode()));
dataUtils.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto); dataUtils.updateOrderStatus(dragonOrdersDto.getCode(),dragonOrdersDto);
//通知商户
String notifyUrl = dragonOrdersDto.getNotifyUrl(); dragonPayBiz.sendNotify(dragonPayBiz.buildPayNotifyReqBo(dragonOrdersDto));
} }
} }
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