Commit deee24e5 authored by jmdhappy's avatar jmdhappy
Browse files

提交转账,退款接口;重构商户通知;修复已知Bug

parent d5333a0d
package org.xxpay.dubbo.service.mq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.xxpay.common.util.MyLog;
import org.xxpay.dubbo.service.BaseService4RefundOrder;
import javax.jms.Queue;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Description: 商户通知MQ统一处理
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-31
* @version V1.0
* @Copyright: www.xxpay.org
*/
@Component
public class Mq4MchRefundNotify extends Mq4MchNotify {
@Autowired
private Queue mchRefundNotifyQueue;
@Autowired
private BaseService4RefundOrder baseService4RefundOrder;
private static final MyLog _log = MyLog.getLog(Mq4MchRefundNotify.class);
public void send(String msg) {
super.send(mchRefundNotifyQueue, msg);
}
@JmsListener(destination = MqConfig.MCH_REFUND_NOTIFY_QUEUE_NAME)
public void receive(String msg) {
String logPrefix = "【商户退款通知】";
_log.info("{}接收消息:msg={}", logPrefix, msg);
JSONObject msgObj = JSON.parseObject(msg);
String respUrl = msgObj.getString("url");
String orderId = msgObj.getString("orderId");
int count = msgObj.getInteger("count");
if(StringUtils.isEmpty(respUrl)) {
_log.warn("{}商户通知URL为空,respUrl={}", logPrefix, respUrl);
return;
}
String httpResult = httpPost(respUrl);
int cnt = count + 1;
_log.info("{}notifyCount={}", logPrefix, cnt);
if("success".equalsIgnoreCase(httpResult)){
// 修改支付订单表
try {
int result = baseService4RefundOrder.baseUpdateStatus4Complete(orderId);
_log.info("{}修改payOrderId={},订单状态为处理完成->{}", logPrefix, orderId, result == 1 ? "成功" : "失败");
} catch (Exception e) {
_log.error(e, "修改订单状态为处理完成异常");
}
// 修改通知
try {
int result = super.baseUpdateMchNotifySuccess(orderId, httpResult, (byte) cnt);
_log.info("{}修改商户通知,orderId={},result={},notifyCount={},结果:{}", logPrefix, orderId, httpResult, cnt, result == 1 ? "成功" : "失败");
}catch (Exception e) {
_log.error(e, "修改商户支付通知异常");
}
return ; // 通知成功结束
}else {
// 修改通知次数
try {
int result = super.baseUpdateMchNotifyFail(orderId, httpResult, (byte) cnt);
_log.info("{}修改商户通知,orderId={},result={},notifyCount={},结果:{}", logPrefix, orderId, httpResult, cnt, result == 1 ? "成功" : "失败");
}catch (Exception e) {
_log.error(e, "修改商户支付通知异常");
}
if (cnt > 5) {
_log.info("{}通知次数notifyCount()>5,停止通知", respUrl, cnt);
return ;
}
// 通知失败,延时再通知
msgObj.put("count", cnt);
this.send(mchRefundNotifyQueue, msgObj.toJSONString(), cnt * 60 * 1000);
_log.info("{}发送延时通知完成,通知次数:{},{}秒后执行通知", respUrl, cnt, cnt * 60);
}
}
}
package org.xxpay.dubbo.service.mq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.xxpay.common.util.MyLog;
import org.xxpay.dubbo.service.BaseService4TransOrder;
import javax.jms.Queue;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Description: 商户通知MQ统一处理
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-31
* @version V1.0
* @Copyright: www.xxpay.org
*/
@Component
public class Mq4MchTransNotify extends Mq4MchNotify {
@Autowired
private Queue mchTransNotifyQueue;
@Autowired
private BaseService4TransOrder baseService4TransOrder;
private static final MyLog _log = MyLog.getLog(Mq4MchTransNotify.class);
public void send(String msg) {
super.send(mchTransNotifyQueue, msg);
}
@JmsListener(destination = MqConfig.MCH_TRANS_NOTIFY_QUEUE_NAME)
public void receive(String msg) {
String logPrefix = "【商户转账通知】";
_log.info("{}接收消息:msg={}", logPrefix, msg);
JSONObject msgObj = JSON.parseObject(msg);
String respUrl = msgObj.getString("url");
String orderId = msgObj.getString("orderId");
int count = msgObj.getInteger("count");
if(StringUtils.isEmpty(respUrl)) {
_log.warn("{}商户通知URL为空,respUrl={}", logPrefix, respUrl);
return;
}
String httpResult = httpPost(respUrl);
int cnt = count + 1;
_log.info("{}notifyCount={}", logPrefix, cnt);
if("success".equalsIgnoreCase(httpResult)){
// 修改支付订单表
try {
int result = baseService4TransOrder.baseUpdateStatus4Complete(orderId);
_log.info("{}修改payOrderId={},订单状态为处理完成->{}", logPrefix, orderId, result == 1 ? "成功" : "失败");
} catch (Exception e) {
_log.error(e, "修改订单状态为处理完成异常");
}
// 修改通知
try {
int result = super.baseUpdateMchNotifySuccess(orderId, httpResult, (byte) cnt);
_log.info("{}修改商户通知,orderId={},result={},notifyCount={},结果:{}", logPrefix, orderId, httpResult, cnt, result == 1 ? "成功" : "失败");
}catch (Exception e) {
_log.error(e, "修改商户支付通知异常");
}
return ; // 通知成功结束
}else {
// 修改通知次数
try {
int result = super.baseUpdateMchNotifyFail(orderId, httpResult, (byte) cnt);
_log.info("{}修改商户通知,orderId={},result={},notifyCount={},结果:{}", logPrefix, orderId, httpResult, cnt, result == 1 ? "成功" : "失败");
}catch (Exception e) {
_log.error(e, "修改商户支付通知异常");
}
if (cnt > 5) {
_log.info("{}通知次数notifyCount()>5,停止通知", respUrl, cnt);
return ;
}
// 通知失败,延时再通知
msgObj.put("count", cnt);
this.send(mchTransNotifyQueue, msgObj.toJSONString(), cnt * 60 * 1000);
_log.info("{}发送延时通知完成,通知次数:{},{}秒后执行通知", respUrl, cnt, cnt * 60);
}
}
}
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.xxpay.common.util.MyLog;
import org.xxpay.dubbo.service.BaseService;
import org.xxpay.dubbo.service.BaseService4PayOrder;
import javax.jms.*;
import javax.net.ssl.HttpsURLConnection;
......@@ -34,7 +35,7 @@ import java.util.Date;
* @Copyright: www.xxpay.org
*/
@Component
public class Mq4PayNotify extends BaseService {
public class Mq4PayNotify extends BaseService4PayOrder {
@Autowired
private Queue payNotifyQueue;
......
package org.xxpay.dubbo.service.mq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.activemq.ScheduledMessage;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.RpcUtil;
import org.xxpay.common.util.StrUtil;
import org.xxpay.dal.dao.model.RefundOrder;
import org.xxpay.dubbo.api.service.IPayChannel4AliService;
import org.xxpay.dubbo.api.service.IPayChannel4WxService;
import org.xxpay.dubbo.service.BaseNotify4MchRefund;
import org.xxpay.dubbo.service.BaseService4RefundOrder;
import javax.jms.*;
import java.util.HashMap;
import java.util.Map;
/**
* @Description: 业务通知MQ实现
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-30
* @version V1.0
* @Copyright: www.xxpay.org
*/
@Component
public class Mq4RefundNotify extends BaseService4RefundOrder {
@Autowired
private Queue refundNotifyQueue;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private IPayChannel4WxService payChannel4WxService;
@Autowired
private IPayChannel4AliService payChannel4AliService;
@Autowired
private BaseNotify4MchRefund baseNotify4MchRefund;
private static final MyLog _log = MyLog.getLog(Mq4RefundNotify.class);
public void send(String msg) {
_log.info("发送MQ消息:msg={}", msg);
this.jmsTemplate.convertAndSend(this.refundNotifyQueue, msg);
}
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(this.refundNotifyQueue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}
@JmsListener(destination = MqConfig.REFUND_NOTIFY_QUEUE_NAME)
public void receive(String msg) {
_log.info("处理退款任务.msg={}", msg);
JSONObject msgObj = JSON.parseObject(msg);
String refundOrderId = msgObj.getString("refundOrderId");
String channelName = msgObj.getString("channelName");
RefundOrder refundOrder = baseSelectRefundOrder(refundOrderId);
if(refundOrder == null) {
_log.warn("查询退款订单为空,不能退款.refundOrderId={}", refundOrderId);
return;
}
if(refundOrder.getStatus() != PayConstant.REFUND_STATUS_INIT) {
_log.warn("退款状态不是初始({})或失败({}),不能退款.refundOrderId={}", PayConstant.REFUND_STATUS_INIT, PayConstant.REFUND_STATUS_FAIL, refundOrderId);
return;
}
int result = this.baseUpdateStatus4Ing(refundOrderId, "");
if(result != 1) {
_log.warn("更改退款为退款中({})失败,不能退款.refundOrderId={}", PayConstant.REFUND_STATUS_REFUNDING, refundOrderId);
return;
}
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map resultMap;
if(PayConstant.CHANNEL_NAME_WX.equalsIgnoreCase(channelName)) {
resultMap = payChannel4WxService.doWxRefundReq(jsonParam);
}else if(PayConstant.CHANNEL_NAME_ALIPAY.equalsIgnoreCase(channelName)) {
resultMap = payChannel4AliService.doAliRefundReq(jsonParam);
}else {
_log.warn("不支持的退款渠道,停止退款处理.refundOrderId={},channelName={}", refundOrderId, channelName);
return;
}
if(!RpcUtil.isSuccess(resultMap)) {
_log.warn("发起退款返回异常,停止退款处理.refundOrderId={}", refundOrderId);
return;
}
Map bizResult = (Map) resultMap.get("bizResult");
Boolean isSuccess = false;
if(bizResult.get("isSuccess") != null) isSuccess = Boolean.parseBoolean(bizResult.get("isSuccess").toString());
if(isSuccess) {
// 更新退款状态为成功
String channelOrderNo = StrUtil.toString(bizResult.get("channelOrderNo"));
result = baseUpdateStatus4Success(refundOrderId, channelOrderNo);
_log.info("更新退款订单状态为成功({}),refundOrderId={},返回结果:{}", PayConstant.REFUND_STATUS_SUCCESS, refundOrderId, result);
// 发送商户通知
baseNotify4MchRefund.doNotify(refundOrder, true);
}else {
// 更新退款状态为失败
String channelErrCode = StrUtil.toString(bizResult.get("channelErrCode"));
String channelErrMsg = StrUtil.toString(bizResult.get("channelErrMsg"));
result = baseUpdateStatus4Fail(refundOrderId, channelErrCode, channelErrMsg);
_log.info("更新退款订单状态为失败({}),refundOrderId={},返回结果:{}", PayConstant.REFUND_STATUS_FAIL, refundOrderId, result);
// 发送商户通知
baseNotify4MchRefund.doNotify(refundOrder, true);
}
}
}
package org.xxpay.dubbo.service.mq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.activemq.ScheduledMessage;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.RpcUtil;
import org.xxpay.dal.dao.model.TransOrder;
import org.xxpay.dubbo.api.service.IPayChannel4AliService;
import org.xxpay.dubbo.api.service.IPayChannel4WxService;
import org.xxpay.dubbo.service.BaseNotify4MchTrans;
import org.xxpay.dubbo.service.BaseService;
import org.xxpay.dubbo.service.BaseService4TransOrder;
import javax.jms.*;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @Description: 业务通知MQ实现
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-30
* @version V1.0
* @Copyright: www.xxpay.org
*/
@Component
public class Mq4TransNotify extends BaseService4TransOrder {
@Autowired
private Queue transNotifyQueue;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private IPayChannel4WxService payChannel4WxService;
@Autowired
private IPayChannel4AliService payChannel4AliService;
@Autowired
private BaseNotify4MchTrans baseNotify4MchTrans;
private static final MyLog _log = MyLog.getLog(Mq4TransNotify.class);
public void send(String msg) {
_log.info("发送MQ消息:msg={}", msg);
this.jmsTemplate.convertAndSend(this.transNotifyQueue, msg);
}
/**
* 发送延迟消息
* @param msg
* @param delay
*/
public void send(String msg, long delay) {
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
jmsTemplate.send(this.transNotifyQueue, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage tm = session.createTextMessage(msg);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
return tm;
}
});
}
@JmsListener(destination = MqConfig.TRANS_NOTIFY_QUEUE_NAME)
public void receive(String msg) {
_log.info("处理转账任务.msg={}", msg);
JSONObject msgObj = JSON.parseObject(msg);
String transOrderId = msgObj.getString("transOrderId");
String channelName = msgObj.getString("channelName");
TransOrder transOrder = baseSelectTransOrder(transOrderId);
if(transOrder == null) {
_log.warn("查询转账订单为空,不能转账.transOrderId={}", transOrderId);
return;
}
if(transOrder.getStatus() != PayConstant.TRANS_STATUS_INIT) {
_log.warn("转账状态不是初始({})或失败({}),不能转账.transOrderId={}", PayConstant.TRANS_STATUS_INIT, PayConstant.TRANS_STATUS_FAIL, transOrderId);
return;
}
int result = this.baseUpdateStatus4Ing(transOrderId, "");
if(result != 1) {
_log.warn("更改转账为转账中({})失败,不能转账.transOrderId={}", PayConstant.TRANS_STATUS_TRANING, transOrderId);
return;
}
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map resultMap;
if(PayConstant.CHANNEL_NAME_WX.equalsIgnoreCase(channelName)) {
resultMap = payChannel4WxService.doWxTransReq(jsonParam);
}else if(PayConstant.CHANNEL_NAME_ALIPAY.equalsIgnoreCase(channelName)) {
resultMap = payChannel4AliService.doAliTransReq(jsonParam);
}else {
_log.warn("不支持的转账渠道,停止转账处理.transOrderId={},channelName={}", transOrderId, channelName);
return;
}
if(!RpcUtil.isSuccess(resultMap)) {
_log.warn("发起转账返回异常,停止转账处理.transOrderId={}", transOrderId);
return;
}
Map bizResult = (Map) resultMap.get("bizResult");
Boolean isSuccess = false;
if(bizResult.get("isSuccess") != null) isSuccess = Boolean.parseBoolean(bizResult.get("isSuccess").toString());
if(isSuccess) {
// 更新转账状态为成功
String channelOrderNo = bizResult.get("channelOrderNo") == null ? "" : bizResult.get("channelOrderNo").toString();
result = baseUpdateStatus4Success(transOrderId, channelOrderNo);
_log.info("更新转账订单状态为成功({}),transOrderId={},返回结果:{}", PayConstant.TRANS_STATUS_SUCCESS, transOrderId, result);
// 发送商户通知
baseNotify4MchTrans.doNotify(transOrder, true);
}else {
// 更新转账状态为成功
String channelErrCode = bizResult.get("channelErrCode") == null ? "" : bizResult.get("channelErrCode").toString();
String channelErrMsg = bizResult.get("channelErrMsg") == null ? "" : bizResult.get("channelErrMsg").toString();
result = baseUpdateStatus4Fail(transOrderId, channelErrCode, channelErrMsg);
_log.info("更新转账订单状态为失败({}),transOrderId={},返回结果:{}", PayConstant.TRANS_STATUS_FAIL, transOrderId, result);
// 发送商户通知
baseNotify4MchTrans.doNotify(transOrder, true);
}
}
}
......@@ -18,9 +18,51 @@ public class MqConfig {
public static final String PAY_NOTIFY_QUEUE_NAME = "pay.notify.queue";
public static final String MCH_NOTIFY_QUEUE_NAME = "queue.notify.mch";
public static final String MCH_PAY_NOTIFY_QUEUE_NAME = "queue.notify.mch.pay";
public static final String MCH_TRANS_NOTIFY_QUEUE_NAME = "queue.notify.mch.trans";
public static final String MCH_REFUND_NOTIFY_QUEUE_NAME = "queue.notify.mch.refund";
public static final String TRANS_NOTIFY_QUEUE_NAME = "queue.notify.trans";
public static final String REFUND_NOTIFY_QUEUE_NAME = "queue.notify.refund";
@Bean
public Queue payNotifyQueue() {
return new ActiveMQQueue(PAY_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue mchNotifyQueue() {
return new ActiveMQQueue(MCH_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue transNotifyQueue() {
return new ActiveMQQueue(TRANS_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue refundNotifyQueue() {
return new ActiveMQQueue(REFUND_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue mchPayNotifyQueue() {
return new ActiveMQQueue(MCH_PAY_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue mchTransNotifyQueue() {
return new ActiveMQQueue(MCH_TRANS_NOTIFY_QUEUE_NAME);
}
@Bean
public Queue mchRefundNotifyQueue() {
return new ActiveMQQueue(MCH_REFUND_NOTIFY_QUEUE_NAME);
}
}
package org.xxpay.dubbo.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.xxpay.common.util.MySeq;
import org.xxpay.common.util.RpcUtil;
import org.xxpay.dal.dao.model.RefundOrder;
import org.xxpay.dal.dao.model.TransOrder;
import org.xxpay.dubbo.api.service.IPayChannel4AliService;
import org.xxpay.dubbo.api.service.IPayChannel4WxService;
import java.util.HashMap;
import java.util.Map;
/**
* @author: dingzhiwei
* @date: 17/10/27
* @description:
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class PayServiceTest {
@Autowired
IPayChannel4AliService payChannel4AliService;
@Autowired
IPayChannel4WxService payChannel4WxService;
String TransOrderId = System.currentTimeMillis()+"";
@Test
public void testDoAliTransReq() {
TransOrder transOrder = new TransOrder();
transOrder.setTransOrderId(TransOrderId);
transOrder.setMchId("20001223");
transOrder.setChannelId("ALIPAY_PC");
transOrder.setChannelUser("jmdhappy@126.com");
transOrder.setAmount(10l);
transOrder.setRemarkInfo("测试XxPay转账");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4AliService.doAliTransReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void testGetAliTransReq() {
TransOrder transOrder = new TransOrder();
//transOrder.setTransOrderId("1509098344835");
transOrder.setChannelOrderNo("302892158947140");
transOrder.setMchId("20001223");
transOrder.setChannelId("ALIPAY_PC");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4AliService.getAliTransReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void testDoAliRefundReq() {
RefundOrder refundOrder = new RefundOrder();
refundOrder.setRefundOrderId(MySeq.getRefund());
refundOrder.setPayOrderId("P0020171028110830000001");
refundOrder.setChannelPayOrderNo("2017102821001003030281781741");
refundOrder.setRefundAmount(100l);
refundOrder.setMchId("20001223");
refundOrder.setChannelId("ALIPAY_PC");
refundOrder.setChannelUser("jmdhappy@126.com");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4AliService.doAliRefundReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void testetAliRefundReq() {
RefundOrder refundOrder = new RefundOrder();
refundOrder.setRefundOrderId(MySeq.getRefund());
refundOrder.setPayOrderId("");
refundOrder.setChannelPayOrderNo("");
refundOrder.setRefundAmount(10l);
refundOrder.setMchId("20001223");
refundOrder.setChannelId("ALIPAY_PC");
refundOrder.setChannelUser("jmdhappy@126.com");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4AliService.getAliRefundReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void testDoWxTransReq() {
TransOrder transOrder = new TransOrder();
transOrder.setTransOrderId(TransOrderId);
transOrder.setMchId("20001222");
transOrder.setChannelId("WX_JSAPI");
transOrder.setChannelUser("oIkQuwhPgPUgl-TvQ48_UUpZUwMs");
transOrder.setAmount(100l);
transOrder.setUserName("丁志伟");
transOrder.setRemarkInfo("测试XxPay转账");
transOrder.setExtra("{\"checkName\":\"FORCE_CHECK\"}"); // 附加参数
transOrder.setClientIp("210.73.211.141");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4WxService.doWxTransReq(jsonParam);
System.out.println("map=" + map);
}
//
@Test
public void testGetWxTransReq() {
TransOrder transOrder = new TransOrder();
transOrder.setTransOrderId("1509276544421");
transOrder.setMchId("20001222");
transOrder.setChannelId("WX_JSAPI");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4WxService.getWxTransReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void testDoWxRefundReq() {
RefundOrder refundOrder = new RefundOrder();
refundOrder.setRefundOrderId(MySeq.getRefund());
refundOrder.setPayOrderId("P0020171029202216000002");
//refundOrder.setChannelPayOrderNo("wx201710292022176ff41580340020277393");
refundOrder.setRefundAmount(1l);
refundOrder.setPayAmount(1l);
refundOrder.setMchId("20001223");
refundOrder.setChannelId("WX_JSAPI");
refundOrder.setChannelUser("oIkQuwhPgPUgl-TvQ48_UUpZUwMs");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4WxService.doWxRefundReq(jsonParam);
System.out.println("map=" + map);
}
@Test
public void tesGetWxRefundReq() {
RefundOrder refundOrder = new RefundOrder();
refundOrder.setRefundOrderId("R0020171029202641000000");
refundOrder.setPayOrderId("");
refundOrder.setChannelPayOrderNo("");
refundOrder.setMchId("20001223");
refundOrder.setChannelId("WX_JSAPI");
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map map = payChannel4WxService.getWxRefundReq(jsonParam);
System.out.println("map=" + map);
}
}
......@@ -62,7 +62,7 @@ public class PayOrderController {
}
if (object instanceof JSONObject) payOrder = (JSONObject) object;
if(payOrder == null) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心下单失败", null, null));
int result = payOrderService.createPayOrder(payOrder);
int result = payOrderService.create(payOrder);
_log.info("{}创建支付订单,结果:{}", logPrefix, result);
if(result != 1) {
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "创建支付订单失败", null, null));
......@@ -251,18 +251,4 @@ public class PayOrderController {
return payOrder;
}
String getJsonParam(String[] names, Object[] values) {
JSONObject jsonParam = new JSONObject();
for (int i = 0; i < names.length; i++) {
jsonParam.put(names[i], values[i]);
}
return jsonParam.toJSONString();
}
String getJsonParam(String name, Object value) {
JSONObject jsonParam = new JSONObject();
jsonParam.put(name, value);
return jsonParam.toJSONString();
}
}
......@@ -58,7 +58,7 @@ public class QueryPayOrderController {
String mchOrderNo = po.getString("mchOrderNo"); // 商户订单号
String payOrderId = po.getString("payOrderId"); // 支付订单号
String executeNotify = po.getString("executeNotify"); // 是否执行回调
JSONObject payOrder = payOrderService.queryPayOrder(mchId, payOrderId, mchOrderNo, executeNotify);
JSONObject payOrder = payOrderService.query(mchId, payOrderId, mchOrderNo, executeNotify);
_log.info("{}查询支付订单,结果:{}", logPrefix, payOrder);
if (payOrder == null) {
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付订单不存在", null, null));
......
package org.xxpay.dubbo.web.ctrl;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.MySeq;
import org.xxpay.common.util.XXPayUtil;
import org.xxpay.dubbo.web.service.*;
import java.util.Map;
/**
* @Description: 转账订单
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-30
* @version V1.0
* @Copyright: www.xxpay.org
*/
@RestController
public class RefundOrderController {
private final MyLog _log = MyLog.getLog(RefundOrderController.class);
@Autowired
private RefundOrderService refundOrderService;
@Autowired
private PayOrderService payOrderService;
@Autowired
private PayChannelService payChannelService;
@Autowired
private MchInfoService mchInfoService;
/**
* 统一转账接口:
* 1)先验证接口参数以及签名信息
* 2)验证通过创建支付订单
* 3)根据商户选择渠道,调用支付服务进行下单
* 4)返回下单数据
* @param params
* @return
*/
@RequestMapping(value = "/api/refund/create_order")
public String payOrder(@RequestParam String params) {
_log.info("###### 开始接收商户统一退款请求 ######");
String logPrefix = "【商户统一退款】";
try {
JSONObject po = JSONObject.parseObject(params);
JSONObject refundContext = new JSONObject();
JSONObject refundOrder = null;
// 验证参数有效性
Object object = validateParams(po, refundContext);
if (object instanceof String) {
_log.info("{}参数校验不通过:{}", logPrefix, object);
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, object.toString(), null, null));
}
if (object instanceof JSONObject) refundOrder = (JSONObject) object;
if(refundOrder == null) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心退款失败", null, null));
int result = refundOrderService.create(refundOrder);
_log.info("{}创建退款订单,结果:{}", logPrefix, result);
if(result != 1) {
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "创建退款订单失败", null, null));
}
// 发送异步退款消息
String transOrderId = refundOrder.getString("refundOrderId");
String channelName = refundContext.getString("channelName");
refundOrderService.sendRefundNotify(transOrderId, channelName);
_log.info("{}发送转账任务完成,transOrderId={}", logPrefix, transOrderId);
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
map.put("refundOrderId", refundOrder.getString("refundOrderId"));
return XXPayUtil.makeRetData(map, refundContext.getString("resKey"));
}catch (Exception e) {
_log.error(e, "");
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心系统异常", null, null));
}
}
/**
* 验证创建订单请求参数,参数通过返回JSONObject对象,否则返回错误文本信息
* @param params
* @return
*/
private Object validateParams(JSONObject params, JSONObject refundContext) {
// 验证请求参数,参数有问题返回错误提示
String errorMessage;
// 支付参数
String mchId = params.getString("mchId"); // 商户ID
String payOrderId = params.getString("payOrderId"); // 支付订单号
String mchOrderNo = params.getString("mchOrderNo"); // 商户支付单号
String mchRefundNo = params.getString("mchRefundNo"); // 商户退款单号
String channelId = params.getString("channelId"); // 渠道ID
String amount = params.getString("amount"); // 退款金额(单位分)
String currency = params.getString("currency"); // 币种
String clientIp = params.getString("clientIp"); // 客户端IP
String device = params.getString("device"); // 设备
String extra = params.getString("extra"); // 特定渠道发起时额外参数
String param1 = params.getString("param1"); // 扩展参数1
String param2 = params.getString("param2"); // 扩展参数2
String notifyUrl = params.getString("notifyUrl"); // 转账结果回调URL
String sign = params.getString("sign"); // 签名
String channelUser = params.getString("channelUser"); // 渠道用户标识,如微信openId,支付宝账号
String userName = params.getString("userName"); // 用户姓名
String remarkInfo = params.getString("remarkInfo"); // 备注
// 验证请求参数有效性(必选项)
if(StringUtils.isBlank(mchId)) {
errorMessage = "request params[mchId] error.";
return errorMessage;
}
if(StringUtils.isBlank(payOrderId) && StringUtils.isBlank(mchOrderNo)) {
errorMessage = "request params[payOrderId,mchOrderNo] error.";
return errorMessage;
}
if(StringUtils.isBlank(mchRefundNo)) {
errorMessage = "request params[mchRefundNo] error.";
return errorMessage;
}
if(StringUtils.isBlank(channelId)) {
errorMessage = "request params[channelId] error.";
return errorMessage;
}
if(!NumberUtils.isNumber(amount)) {
errorMessage = "request params[amount] error.";
return errorMessage;
}
if(StringUtils.isBlank(currency)) {
errorMessage = "request params[currency] error.";
return errorMessage;
}
if(StringUtils.isBlank(notifyUrl)) {
errorMessage = "request params[notifyUrl] error.";
return errorMessage;
}
if(StringUtils.isBlank(channelUser)) {
errorMessage = "request params[channelUser] error.";
return errorMessage;
}
// 签名信息
if (StringUtils.isEmpty(sign)) {
errorMessage = "request params[sign] error.";
return errorMessage;
}
// 查询商户信息
JSONObject mchInfo = mchInfoService.getByMchId(mchId);
if(mchInfo == null) {
errorMessage = "Can't found mchInfo[mchId="+mchId+"] record in db.";
return errorMessage;
}
if(mchInfo.getByte("state") != 1) {
errorMessage = "mchInfo not available [mchId="+mchId+"] record in db.";
return errorMessage;
}
String reqKey = mchInfo.getString("reqKey");
if (StringUtils.isBlank(reqKey)) {
errorMessage = "reqKey is null[mchId="+mchId+"] record in db.";
return errorMessage;
}
refundContext.put("resKey", mchInfo.getString("resKey"));
// 查询商户对应的支付渠道
JSONObject payChannel = payChannelService.getByMchIdAndChannelId(mchId, channelId);
if(payChannel == null) {
errorMessage = "Can't found payChannel[channelId="+channelId+",mchId="+mchId+"] record in db.";
return errorMessage;
}
if(payChannel.getByte("state") != 1) {
errorMessage = "channel not available [channelId="+channelId+",mchId="+mchId+"]";
return errorMessage;
}
refundContext.put("channelName", payChannel.getString("channelName"));
// 验证签名数据
boolean verifyFlag = XXPayUtil.verifyPaySign(params, reqKey);
if(!verifyFlag) {
errorMessage = "Verify XX refund sign failed.";
return errorMessage;
}
// 验证支付订单是否存在
JSONObject payOrder = payOrderService.query(mchId, payOrderId, mchOrderNo, "false");
if(payOrder == null) {
errorMessage = "payOrder is not exist.";
return errorMessage;
}
String channelPayOrderNo = payOrder.getString("channelOrderNo"); // 渠道测支付单号
Long payAmount = payOrder.getLong("amount");
// 验证参数通过,返回JSONObject对象
JSONObject refundOrder = new JSONObject();
refundOrder.put("refundOrderId", MySeq.getRefund());
refundOrder.put("payOrderId", payOrderId);
refundOrder.put("channelPayOrderNo", channelPayOrderNo);
refundOrder.put("mchId", mchId);
refundOrder.put("mchRefundNo", mchRefundNo);
refundOrder.put("channelId", channelId);
refundOrder.put("refundAmount", Long.parseLong(amount)); // 退款金额
refundOrder.put("payAmount", payAmount); // 退款金额
refundOrder.put("currency", currency);
refundOrder.put("clientIp", clientIp);
refundOrder.put("device", device);
refundOrder.put("channelUser", channelUser);
refundOrder.put("userName", userName);
refundOrder.put("remarkInfo", remarkInfo);
refundOrder.put("extra", extra);
refundOrder.put("channelMchId", payChannel.getString("channelMchId"));
refundOrder.put("param1", param1);
refundOrder.put("param2", param2);
refundOrder.put("notifyUrl", notifyUrl);
return refundOrder;
}
}
package org.xxpay.dubbo.web.ctrl;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.MySeq;
import org.xxpay.common.util.XXPayUtil;
import org.xxpay.dubbo.web.service.MchInfoService;
import org.xxpay.dubbo.web.service.PayChannelService;
import org.xxpay.dubbo.web.service.TransOrderService;
import java.util.Map;
/**
* @Description: 转账订单
* @author dingzhiwei jmdhappy@126.com
* @date 2017-10-30
* @version V1.0
* @Copyright: www.xxpay.org
*/
@RestController
public class TransOrderController {
private final MyLog _log = MyLog.getLog(TransOrderController.class);
@Autowired
private TransOrderService transOrderService;
@Autowired
private PayChannelService payChannelService;
@Autowired
private MchInfoService mchInfoService;
/**
* 统一转账接口:
* 1)先验证接口参数以及签名信息
* 2)验证通过创建支付订单
* 3)根据商户选择渠道,调用支付服务进行下单
* 4)返回下单数据
* @param params
* @return
*/
@RequestMapping(value = "/api/trans/create_order")
public String payOrder(@RequestParam String params) {
_log.info("###### 开始接收商户统一转账请求 ######");
String logPrefix = "【商户统一转账】";
try {
JSONObject po = JSONObject.parseObject(params);
JSONObject transContext = new JSONObject();
JSONObject transOrder = null;
// 验证参数有效性
Object object = validateParams(po, transContext);
if (object instanceof String) {
_log.info("{}参数校验不通过:{}", logPrefix, object);
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, object.toString(), null, null));
}
if (object instanceof JSONObject) transOrder = (JSONObject) object;
if(transOrder == null) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心转账失败", null, null));
int result = transOrderService.create(transOrder);
_log.info("{}创建转账订单,结果:{}", logPrefix, result);
if(result != 1) {
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "创建转账订单失败", null, null));
}
// 发送异步转账消息
String transOrderId = transOrder.getString("transOrderId");
String channelName = transContext.getString("channelName");
transOrderService.sendTransNotify(transOrderId, channelName);
_log.info("{}发送转账任务完成,transOrderId={}", logPrefix, transOrderId);
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
map.put("transOrderId", transOrderId);
return XXPayUtil.makeRetData(map, transContext.getString("resKey"));
}catch (Exception e) {
_log.error(e, "");
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心系统异常", null, null));
}
}
/**
* 验证创建订单请求参数,参数通过返回JSONObject对象,否则返回错误文本信息
* @param params
* @return
*/
private Object validateParams(JSONObject params, JSONObject transContext) {
// 验证请求参数,参数有问题返回错误提示
String errorMessage;
// 支付参数
String mchId = params.getString("mchId"); // 商户ID
String mchTransNo = params.getString("mchTransNo"); // 商户转账单号
String channelId = params.getString("channelId"); // 渠道ID
String amount = params.getString("amount"); // 转账金额(单位分)
String currency = params.getString("currency"); // 币种
String clientIp = params.getString("clientIp"); // 客户端IP
String device = params.getString("device"); // 设备
String extra = params.getString("extra"); // 特定渠道发起时额外参数
String param1 = params.getString("param1"); // 扩展参数1
String param2 = params.getString("param2"); // 扩展参数2
String notifyUrl = params.getString("notifyUrl"); // 转账结果回调URL
String sign = params.getString("sign"); // 签名
String channelUser = params.getString("channelUser"); // 渠道用户标识,如微信openId,支付宝账号
String userName = params.getString("userName"); // 用户姓名
String remarkInfo = params.getString("remarkInfo"); // 备注
// 验证请求参数有效性(必选项)
if(StringUtils.isBlank(mchId)) {
errorMessage = "request params[mchId] error.";
return errorMessage;
}
if(StringUtils.isBlank(mchTransNo)) {
errorMessage = "request params[mchTransNo] error.";
return errorMessage;
}
if(StringUtils.isBlank(channelId)) {
errorMessage = "request params[channelId] error.";
return errorMessage;
}
if(!NumberUtils.isNumber(amount)) {
errorMessage = "request params[amount] error.";
return errorMessage;
}
if(StringUtils.isBlank(currency)) {
errorMessage = "request params[currency] error.";
return errorMessage;
}
if(StringUtils.isBlank(notifyUrl)) {
errorMessage = "request params[notifyUrl] error.";
return errorMessage;
}
if(StringUtils.isBlank(channelUser)) {
errorMessage = "request params[channelUser] error.";
return errorMessage;
}
if(StringUtils.isBlank(remarkInfo)) {
errorMessage = "request params[remarkInfo] error.";
return errorMessage;
}
// 签名信息
if (StringUtils.isEmpty(sign)) {
errorMessage = "request params[sign] error.";
return errorMessage;
}
// 查询商户信息
JSONObject mchInfo = mchInfoService.getByMchId(mchId);
if(mchInfo == null) {
errorMessage = "Can't found mchInfo[mchId="+mchId+"] record in db.";
return errorMessage;
}
if(mchInfo.getByte("state") != 1) {
errorMessage = "mchInfo not available [mchId="+mchId+"] record in db.";
return errorMessage;
}
String reqKey = mchInfo.getString("reqKey");
if (StringUtils.isBlank(reqKey)) {
errorMessage = "reqKey is null[mchId="+mchId+"] record in db.";
return errorMessage;
}
transContext.put("resKey", mchInfo.getString("resKey"));
// 查询商户对应的支付渠道
JSONObject payChannel = payChannelService.getByMchIdAndChannelId(mchId, channelId);
if(payChannel == null) {
errorMessage = "Can't found payChannel[channelId="+channelId+",mchId="+mchId+"] record in db.";
return errorMessage;
}
if(payChannel.getByte("state") != 1) {
errorMessage = "channel not available [channelId="+channelId+",mchId="+mchId+"]";
return errorMessage;
}
transContext.put("channelName", payChannel.getString("channelName"));
// 验证签名数据
boolean verifyFlag = XXPayUtil.verifyPaySign(params, reqKey);
if(!verifyFlag) {
errorMessage = "Verify XX trans sign failed.";
return errorMessage;
}
// 验证参数通过,返回JSONObject对象
JSONObject transOrder = new JSONObject();
transOrder.put("transOrderId", MySeq.getTrans());
transOrder.put("mchId", mchId);
transOrder.put("mchTransNo", mchTransNo);
transOrder.put("channelId", channelId);
transOrder.put("amount", Long.parseLong(amount));
transOrder.put("currency", currency);
transOrder.put("clientIp", clientIp);
transOrder.put("device", device);
transOrder.put("channelUser", channelUser);
transOrder.put("userName", userName);
transOrder.put("remarkInfo", remarkInfo);
transOrder.put("extra", extra);
transOrder.put("channelMchId", payChannel.getString("channelMchId"));
transOrder.put("param1", param1);
transOrder.put("param2", param2);
transOrder.put("notifyUrl", notifyUrl);
return transOrder;
}
}
......@@ -25,29 +25,29 @@ public class PayOrderService {
@Autowired
private RpcCommonService rpcCommonService;
public int createPayOrder(JSONObject payOrder) {
public int create(JSONObject payOrder) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("payOrder", payOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = rpcCommonService.rpcPayOrderService.createPayOrder(jsonParam);
Map<String, Object> result = rpcCommonService.rpcPayOrderService.create(jsonParam);
String s = RpcUtil.mkRet(result);
if(s == null) return 0;
return Integer.parseInt(s);
}
public JSONObject queryPayOrder(String mchId, String payOrderId, String mchOrderNo, String executeNotify) {
public JSONObject query(String mchId, String payOrderId, String mchOrderNo, String executeNotify) {
Map<String,Object> paramMap = new HashMap<>();
Map<String, Object> result;
if(StringUtils.isNotBlank(payOrderId)) {
paramMap.put("mchId", mchId);
paramMap.put("payOrderId", payOrderId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcPayOrderService.selectPayOrderByMchIdAndPayOrderId(jsonParam);
result = rpcCommonService.rpcPayOrderService.selectByMchIdAndPayOrderId(jsonParam);
}else {
paramMap.put("mchId", mchId);
paramMap.put("mchOrderNo", mchOrderNo);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcPayOrderService.selectPayOrderByMchIdAndMchOrderNo(jsonParam);
result = rpcCommonService.rpcPayOrderService.selectByMchIdAndMchOrderNo(jsonParam);
}
String s = RpcUtil.mkRet(result);
if(s == null) return null;
......
package org.xxpay.dubbo.web.service;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.RpcUtil;
import org.xxpay.common.util.XXPayUtil;
import java.util.HashMap;
import java.util.Map;
/**
* @author: dingzhiwei
* @date: 17/10/30
* @description:
*/
@Service
public class RefundOrderService {
private static final MyLog _log = MyLog.getLog(RefundOrderService.class);
@Autowired
private RpcCommonService rpcCommonService;
public int create(JSONObject refundOrder) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = rpcCommonService.rpcRefundOrderService.create(jsonParam);
String s = RpcUtil.mkRet(result);
if(s == null) return 0;
return Integer.parseInt(s);
}
public void sendRefundNotify(String refundOrderId, String channelName) {
JSONObject object = new JSONObject();
object.put("refundOrderId", refundOrderId);
object.put("channelName", channelName);
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("msg", object);
String jsonParam = RpcUtil.createBaseParam(paramMap);
rpcCommonService.rpcRefundOrderService.sendRefundNotify(jsonParam);
}
public JSONObject query(String mchId, String refundOrderId, String mchRefundNo, String executeNotify) {
Map<String,Object> paramMap = new HashMap<>();
Map<String, Object> result;
if(StringUtils.isNotBlank(refundOrderId)) {
paramMap.put("mchId", mchId);
paramMap.put("refundOrderId", refundOrderId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcRefundOrderService.selectByMchIdAndRefundOrderId(jsonParam);
}else {
paramMap.put("mchId", mchId);
paramMap.put("mchRefundNo", mchRefundNo);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcRefundOrderService.selectByMchIdAndMchRefundNo(jsonParam);
}
String s = RpcUtil.mkRet(result);
if(s == null) return null;
boolean isNotify = Boolean.parseBoolean(executeNotify);
JSONObject payOrder = JSONObject.parseObject(s);
if(isNotify) {
paramMap = new HashMap<>();
paramMap.put("refundOrderId", refundOrderId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcNotifyPayService.sendBizPayNotify(jsonParam);
s = RpcUtil.mkRet(result);
_log.info("业务查单完成,并再次发送业务支付通知.发送结果:{}", s);
}
return payOrder;
}
public String doWxRefundReq(String tradeType, JSONObject refundOrder, String resKey) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("tradeType", tradeType);
paramMap.put("refundOrder", refundOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = rpcCommonService.rpcPayChannel4AliService.doAliRefundReq(jsonParam);
String s = RpcUtil.mkRet(result);
if(s == null) {
return XXPayUtil.makeRetData(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用微信支付失败"), resKey);
}
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
map.putAll((Map) result.get("bizResult"));
return XXPayUtil.makeRetData(map, resKey);
}
}
......@@ -30,4 +30,10 @@ public class RpcCommonService {
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
public INotifyPayService rpcNotifyPayService;
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
public ITransOrderService rpcTransOrderService;
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
public IRefundOrderService rpcRefundOrderService;
}
package org.xxpay.dubbo.web.service;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xxpay.common.constant.PayConstant;
import org.xxpay.common.util.MyLog;
import org.xxpay.common.util.RpcUtil;
import org.xxpay.common.util.XXPayUtil;
import java.util.HashMap;
import java.util.Map;
/**
* @author: dingzhiwei
* @date: 17/10/30
* @description:
*/
@Service
public class TransOrderService {
private static final MyLog _log = MyLog.getLog(TransOrderService.class);
@Autowired
private RpcCommonService rpcCommonService;
public int create(JSONObject transOrder) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("transOrder", transOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = rpcCommonService.rpcTransOrderService.create(jsonParam);
String s = RpcUtil.mkRet(result);
if(s == null) return 0;
return Integer.parseInt(s);
}
public void sendTransNotify(String transOrderId, String channelName) {
JSONObject object = new JSONObject();
object.put("transOrderId", transOrderId);
object.put("channelName", channelName);
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("msg", object);
String jsonParam = RpcUtil.createBaseParam(paramMap);
rpcCommonService.rpcTransOrderService.sendTransNotify(jsonParam);
}
public JSONObject query(String mchId, String transOrderId, String mchTransNo, String executeNotify) {
Map<String,Object> paramMap = new HashMap<>();
Map<String, Object> result;
if(StringUtils.isNotBlank(transOrderId)) {
paramMap.put("mchId", mchId);
paramMap.put("transOrderId", transOrderId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcTransOrderService.selectByMchIdAndTransOrderId(jsonParam);
}else {
paramMap.put("mchId", mchId);
paramMap.put("mchTransNo", mchTransNo);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcTransOrderService.selectByMchIdAndMchTransNo(jsonParam);
}
String s = RpcUtil.mkRet(result);
if(s == null) return null;
boolean isNotify = Boolean.parseBoolean(executeNotify);
JSONObject payOrder = JSONObject.parseObject(s);
if(isNotify) {
paramMap = new HashMap<>();
paramMap.put("transOrderId", transOrderId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
result = rpcCommonService.rpcNotifyPayService.sendBizPayNotify(jsonParam);
s = RpcUtil.mkRet(result);
_log.info("业务查单完成,并再次发送业务支付通知.发送结果:{}", s);
}
return payOrder;
}
public String doWxTransReq(String tradeType, JSONObject payOrder, String resKey) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("tradeType", tradeType);
paramMap.put("payOrder", payOrder);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = rpcCommonService.rpcPayChannel4WxService.doWxPayReq(jsonParam);
String s = RpcUtil.mkRet(result);
if(s == null) {
return XXPayUtil.makeRetData(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用微信支付失败"), resKey);
}
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
map.putAll((Map) result.get("bizResult"));
return XXPayUtil.makeRetData(map, resKey);
}
}
......@@ -81,6 +81,22 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/lib/</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......
Supports Markdown
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