Browse Source

update

release_toaliyun_real
xiaohanzi 5 years ago
parent
commit
dcbe9c6463
27 changed files with 330 additions and 211 deletions
  1. +1
    -1
      mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java
  2. +8
    -6
      mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java
  3. +48
    -48
      mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java
  4. +1
    -1
      mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java
  5. +1
    -1
      mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java
  6. +3
    -3
      mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java
  7. +15
    -110
      mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java
  8. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java
  9. +2
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java
  10. +14
    -14
      mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java
  11. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java
  12. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java
  13. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/CreateCUser.java
  14. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayAdapterResult.java
  15. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayQueryAdapterResult.java
  16. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java
  17. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java
  18. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java
  19. +3
    -3
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java
  20. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java
  21. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundAdapterResult.java
  22. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundNotifyAdapterResult.java
  23. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java
  24. +8
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java
  25. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java
  26. +76
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/ShareNotifyAdapterResult.java
  27. +130
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java

+ 1
- 1
mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java View File

@@ -180,7 +180,7 @@ public class WxPayController extends BaseController {
xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8"));
paramMap = WxPayment.xmlToMap(xml);
logger.info("share wxpay, notify, param: " + xml );
response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT);
response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT);
logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString());
return response;
} catch (BizMessageException e) {


+ 8
- 6
mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java View File

@@ -37,8 +37,8 @@ public class MqBaseConsumer {
@Autowired
private MqBaseProducer mqBaseProducer;

@Autowired
private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService;
//@Autowired
//private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService;
@Autowired
private FmInsideNotifyRefundSuccessMsgServiceImpl fmInsideNotifyRefundSuccessMsgService;
@Autowired
@@ -89,11 +89,13 @@ public class MqBaseConsumer {
// 内部消息 - c端登录
FmInsideCLoginMsg msg = (FmInsideCLoginMsg)JsonUtil.readValue(message,FmInsideCLoginMsg.class);
fmInsideCouponVerifyMsgService.send(msg);
} else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) {
}
//else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) {
// 内部消息 - 微信支付通知
FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class);
fmInsideNotifyPaySuccessMsgService.send(msg);
} else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) {
//FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class);
//fmInsideNotifyPaySuccessMsgService.send(msg);
//}
else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) {
// 内部消息 - 微信退款通知
FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg)JsonUtil.readValue(message,FmInsideNotifyRefundSuccessMsg.class);
fmInsideNotifyRefundSuccessMsgService.send(msg);


+ 48
- 48
mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java View File

@@ -25,56 +25,56 @@ public class MsgReSendSchedule {
@Autowired
private MqBaseProducer mqBaseProducer;

@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次
//@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次
//@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次
public void msgReSend() {
logger.info("消息重发开始...");
//消息重发
WxMsgRecord msgRecord = new WxMsgRecord();
msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode());
List<WxMsgRecord> recordList = wxMsgRecordService.findList(msgRecord);
for (WxMsgRecord wxMsgRecord:recordList) {
logger.info("消息重发:{}",wxMsgRecord.getMsgJson());
TenantEntity tenantEntity = wxMsgRecord.getTenantInfo();
try {
if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
//内部消息 - 下订单成功
FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class);
msg.setMsgType(wxMsgRecord.getMsgType());
msg.setReceiver(wxMsgRecord.getReceiver());
msg.updateTenantInfo(tenantEntity);
mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
}else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){
FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class);
msg.setMsgType(wxMsgRecord.getMsgType());
msg.setReceiver(wxMsgRecord.getReceiver());
msg.updateTenantInfo(tenantEntity);
mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
}else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){
FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class);
msg.setMsgType(wxMsgRecord.getMsgType());
msg.setReceiver(wxMsgRecord.getReceiver());
msg.updateTenantInfo(tenantEntity);
mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
}else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class);
msg.setMsgType(wxMsgRecord.getMsgType());
msg.setReceiver(wxMsgRecord.getReceiver());
msg.updateTenantInfo(tenantEntity);
mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
}else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class);
msg.setMsgType(wxMsgRecord.getMsgType());
msg.setReceiver(wxMsgRecord.getReceiver());
msg.updateTenantInfo(tenantEntity);
mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
}
} catch (Exception e) {
e.printStackTrace();
logger.error("消息重发错误:" + e.getMessage());
}
}
logger.info("消息重发结束...");
// logger.info("消息重发开始...");
// //消息重发
// WxMsgRecord msgRecord = new WxMsgRecord();
// msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode());
// List<WxMsgRecord> recordList = wxMsgRecordService.findList(msgRecord);
// for (WxMsgRecord wxMsgRecord:recordList) {
// logger.info("消息重发:{}",wxMsgRecord.getMsgJson());
// TenantEntity tenantEntity = wxMsgRecord.getTenantInfo();
// try {
// if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
// //内部消息 - 下订单成功
// FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class);
// msg.setMsgType(wxMsgRecord.getMsgType());
// msg.setReceiver(wxMsgRecord.getReceiver());
// msg.updateTenantInfo(tenantEntity);
// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
// }else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){
// FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class);
// msg.setMsgType(wxMsgRecord.getMsgType());
// msg.setReceiver(wxMsgRecord.getReceiver());
// msg.updateTenantInfo(tenantEntity);
// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
// }else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){
// FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class);
// msg.setMsgType(wxMsgRecord.getMsgType());
// msg.setReceiver(wxMsgRecord.getReceiver());
// msg.updateTenantInfo(tenantEntity);
// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
// }else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
// FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class);
// msg.setMsgType(wxMsgRecord.getMsgType());
// msg.setReceiver(wxMsgRecord.getReceiver());
// msg.updateTenantInfo(tenantEntity);
// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
// }else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){
// FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class);
// msg.setMsgType(wxMsgRecord.getMsgType());
// msg.setReceiver(wxMsgRecord.getReceiver());
// msg.updateTenantInfo(tenantEntity);
// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
// }
// } catch (Exception e) {
// e.printStackTrace();
// logger.error("消息重发错误:" + e.getMessage());
// }
// }
// logger.info("消息重发结束...");
}



+ 1
- 1
mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java View File

@@ -30,7 +30,7 @@ import com.iformall.service.WxPayOrderService;
import com.iformall.service.WxRefundOrderService;
import com.iformall.service.helper.WxPayOrderServiceHelper;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.utils.DateUtils;

@Component


+ 1
- 1
mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java View File

@@ -15,7 +15,7 @@ public enum EnumMsgRecordType {
INSIDE_ORDER_SUCCESS(100, "下订单成功"),
INSIDE_COUPON_VERIFY(101, "券核销"),
INSIDE_C_LOGIN(102, "C端用户登录"),
INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"),
//INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"),
INSIDE_NOTIFY_REFUND_SUCCESS(104, "微信退款回调"),
COUPON_STOCK(105, "券库存更新"),
;


+ 3
- 3
mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java View File

@@ -14,9 +14,9 @@ import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumPayShare;
import com.iformall.enums.EnumPayWay;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;

public interface WxPayOrderService {

@@ -68,7 +68,7 @@ public interface WxPayOrderService {
* @param payWay 支付方式
* @return
*/
String notify(Map<String, String> paramMap, EnumPayWay payWay);
String shareNotify(Map<String, String> paramMap, EnumPayWay payWay);

/**
* 支付成功处理


+ 15
- 110
mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java View File

@@ -19,13 +19,14 @@ import com.iformall.pay.*;
import com.iformall.service.*;
import com.iformall.service.helper.WxPayOrderServiceHelper;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.entity.CreateCUser;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.CPassivePayService;
import com.iformall.service.pay.service.pay.PayAdapterService;
import com.iformall.service.pay.service.pay.entity.CreateCUser;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
import com.iformall.utils.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -877,119 +878,23 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {


/**
* 提供微信支付回调调用
* 提供微信支付回调调用 --- 分账通知
*
* @param paramMap 异步通知参数
* @param payWay 支付方式
* @return
*/
@Override
public String notify(Map<String, String> paramMap, EnumPayWay payWay) {
// how to get wechatAppId, wechatMchId, partnerKey
String appId = paramMap.get("appid");
String subAppId = paramMap.get("sub_appid");
String mchId = paramMap.get("mch_id");
String subMchId = paramMap.get("sub_mch_id");
WxAppinfo appinfo = null;
boolean isNormal = true;
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) {
// 普通商户号
appinfo = wxAppinfoMapper.findByAppId(appId);
if (appinfo == null) {
logger.error("appid not found: " + appId);
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
isNormal = true;
} else {
// 服务号 现在用hmac-sha256
appinfo = wxAppinfoMapper.findByAppId(subAppId);
if (appinfo == null) {
logger.error("subappid not found: " + subAppId);
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
isNormal = false;
}

WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId());
if (payAccount == null) {
throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND);
}
String partnerKey = payAccount.getApiKey();
try {
if (payWay == EnumPayWay.PAY_WAY_WECHAT) {
boolean signVerified = false;
if (isNormal) {
// 普通商户号支付
signVerified = WxPayment.verifyNotify(paramMap, partnerKey);
if (!signVerified) {
logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR);
}
} else {
// 服务号 现在用hmac-sha256
signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey);
if (!signVerified) {
logger.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR);
}
}

if (!"SUCCESS".equals(paramMap.get("return_code"))) {
logger.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", "订单状态码非SUCCESS");
return XmlUtil.getRequestXml(resultMap);
}

String payOrderNo = paramMap.get("out_trade_no");
String timEndStr = paramMap.get("time_end");
Long payOrderId = Long.valueOf(payOrderNo);
WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId);
if (payOrder == null) {
logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", "订单不存在");
return XmlUtil.getRequestXml(resultMap);
}
// 验证支付金额
if (!paramMap.get("total_fee").equals(payOrder.getPayAmount().toString())) {
logger.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", "订单总金额不一致");
return XmlUtil.getRequestXml(resultMap);
}

Date timeEnd = null;

try {
timeEnd = Utility.getDateFromString(timEndStr);
} catch (ParseException e) {
logger.error("解析timeEnd失败");
timeEnd = new Date();
}
payOrder.setPayTimeEnd(timeEnd);
payOrder.setPayEndFrom(EnumPayEndFrom.CALLBACK.getCode());

// 处理支付成功
handleOrderPaySuccess(payOrder, paramMap.get("transaction_id"));
logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "SUCCESS");
resultMap.put("return_msg", "OK");
return XmlUtil.getRequestXml(resultMap);
}
} catch (RuntimeException e) {
logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR);
}

SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", "FAILED");
return XmlUtil.getRequestXml(resultMap);
public String shareNotify(Map<String, String> paramMap, EnumPayWay payWay) {
ShareNotifyAdapterResult shareResult = payServiceFactory.getPayShareAdapterService(payWay.getCode()).notify(paramMap,payWay);
if (shareResult.isSuccess()) {
// 处理支付成功
shareResult.getPayOrder().setPayEndFrom(EnumPayEndFrom.CALLBACK.getCode());
handleOrderPaySuccess(shareResult.getPayOrder(), shareResult.getTranscationId());
return shareResult.getReturnJson();
}else {
return shareResult.getReturnJson();
}
}

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java View File

@@ -21,7 +21,7 @@ import com.iformall.mapper.*;
import com.iformall.pay.*;
import com.iformall.service.WxProfitSharingOrderService;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.DateUtils;
import com.iformall.utils.Utility;


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java View File

@@ -21,8 +21,8 @@ import com.iformall.service.WxOrderService;
import com.iformall.service.WxRefundOrderService;
import com.iformall.service.helper.WxPayOrderServiceHelper;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.entity.RefundAdapterResult;
import com.iformall.service.pay.entity.RefundNotifyAdapterResult;
import com.iformall.service.pay.service.refund.entity.RefundAdapterResult;
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.CipherUtil;
import com.iformall.utils.Utility;


+ 14
- 14
mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java View File

@@ -18,17 +18,17 @@ import java.util.Map;
* @author Stormeye Wu
* @date 2019/5/10
*/
@Service
public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxPayOrderService wxPayOrderService;
@Override
public void send(BaseMsg baseMsg) throws Exception {
FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg;
Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class);
wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay()));
}
}
//@Service
//public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService {
// private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
// @Autowired
// private WxPayOrderService wxPayOrderService;
//
// @Override
// public void send(BaseMsg baseMsg) throws Exception {
// FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg;
// Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class);
// wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay()));
// }
//}

+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java View File

@@ -7,9 +7,9 @@ import com.iformall.domain.po.WxOrder;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumPayShare;
import com.iformall.service.pay.entity.CreateCUser;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.service.pay.entity.CreateCUser;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;

/**
* C端被动发起的支付


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java View File

@@ -6,9 +6,9 @@ import com.iformall.domain.po.WxOrder;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumPayShare;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;

public interface PayAdapterService {



mallinkService/src/main/java/com/iformall/service/pay/entity/CreateCUser.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/CreateCUser.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.pay.entity;

import java.io.Serializable;


mallinkService/src/main/java/com/iformall/service/pay/entity/PayAdapterResult.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayAdapterResult.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.pay.entity;

import java.io.Serializable;


mallinkService/src/main/java/com/iformall/service/pay/entity/PayQueryAdapterResult.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayQueryAdapterResult.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.pay.entity;

import java.io.Serializable;


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java View File

@@ -7,8 +7,8 @@ import com.iformall.domain.po.WxOrder;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.service.helper.WxPayOrderServiceHelper;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.PayAdapterService;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;

public class BaseWxPayAdapterService {



+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java View File

@@ -9,10 +9,10 @@ import com.iformall.domain.po.WxOrder;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumPayShare;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService;

@Service


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java View File

@@ -22,10 +22,10 @@ import com.iformall.pay.WxPay;
import com.iformall.pay.WxPayOrderP;
import com.iformall.pay.WxPayOrderSP;
import com.iformall.pay.WxPayment;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.MapUtil;


+ 3
- 3
mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java View File

@@ -22,11 +22,11 @@ import com.iformall.pay.WxMicroPayOrderSP;
import com.iformall.pay.WxPay;
import com.iformall.pay.WxPayment;
import com.iformall.service.WxCUserService;
import com.iformall.service.pay.entity.CreateCUser;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.CPassivePayService;
import com.iformall.service.pay.service.pay.entity.CreateCUser;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.Utility;


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java View File

@@ -8,8 +8,8 @@ import com.iformall.domain.po.WxPayOrder;
import com.iformall.domain.po.WxRefundOrder;
import com.iformall.enums.EnumPayType;
import com.iformall.enums.EnumPayWay;
import com.iformall.service.pay.entity.RefundAdapterResult;
import com.iformall.service.pay.entity.RefundNotifyAdapterResult;
import com.iformall.service.pay.service.refund.entity.RefundAdapterResult;
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult;

public interface RefundPayAdapterService {



mallinkService/src/main/java/com/iformall/service/pay/entity/RefundAdapterResult.java → mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundAdapterResult.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.refund.entity;

import java.io.Serializable;


mallinkService/src/main/java/com/iformall/service/pay/entity/RefundNotifyAdapterResult.java → mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundNotifyAdapterResult.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.refund.entity;

import java.io.Serializable;


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java View File

@@ -31,9 +31,9 @@ import com.iformall.pay.WxPay;
import com.iformall.pay.WxPayment;
import com.iformall.pay.WxRefundOrderP;
import com.iformall.pay.WxRefundOrderSP;
import com.iformall.service.pay.entity.RefundAdapterResult;
import com.iformall.service.pay.entity.RefundNotifyAdapterResult;
import com.iformall.service.pay.service.refund.RefundPayAdapterService;
import com.iformall.service.pay.service.refund.entity.RefundAdapterResult;
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.CipherUtil;
import com.iformall.utils.Utility;


+ 8
- 1
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java View File

@@ -1,13 +1,17 @@
package com.iformall.service.pay.service.share;

import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.enums.EnumPayWay;
import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.exception.MallinkException;
import com.iformall.service.pay.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;

/**
* 分账接口
@@ -58,4 +62,7 @@ public interface PayShareAdapterService {
*/
public EnumProfitSharingReceiverType getShareAccount(Integer accountType);
public ShareNotifyAdapterResult notify(Map<String, String> paramMap,EnumPayWay payWay);
}

mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java → mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java View File

@@ -1,4 +1,4 @@
package com.iformall.service.pay.entity;
package com.iformall.service.pay.service.share.entity;

import java.io.Serializable;


+ 76
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/ShareNotifyAdapterResult.java View File

@@ -0,0 +1,76 @@
package com.iformall.service.pay.service.share.entity;

import java.io.Serializable;
import com.iformall.domain.po.WxPayOrder;

public class ShareNotifyAdapterResult implements Serializable{
private static final long serialVersionUID = -6647306162758854293L;
private boolean isSuccess;
private Integer code;
private String msg;
private String returnJson;
private String transcationId;
private WxPayOrder payOrder;
public ShareNotifyAdapterResult() {
}
public ShareNotifyAdapterResult(boolean isSuccess,Integer code,String msg,String returnJson) {
this.isSuccess = isSuccess;
this.msg = msg;
this.returnJson = returnJson;
}
public ShareNotifyAdapterResult(String transcationId,WxPayOrder payOrder,String returnJson) {
this.isSuccess = true;
this.transcationId = transcationId;
this.payOrder = payOrder;
this.returnJson = returnJson;
}
public boolean isSuccess() {
return isSuccess;
}
public void setSuccess(boolean isSuccess) {
this.isSuccess = isSuccess;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Integer getCode() {
return code;
}

public void setCode(Integer code) {
this.code = code;
}

public String getTranscationId() {
return transcationId;
}

public void setTranscationId(String transcationId) {
this.transcationId = transcationId;
}

public String getReturnJson() {
return returnJson;
}

public void setReturnJson(String returnJson) {
this.returnJson = returnJson;
}

public WxPayOrder getPayOrder() {
return payOrder;
}

public void setPayOrder(WxPayOrder payOrder) {
this.payOrder = payOrder;
}
}

+ 130
- 1
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java View File

@@ -1,28 +1,44 @@
package com.iformall.service.pay.service.share.wx;

import java.text.ParseException;
import java.util.Date;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.iformall.common.ErrorCode;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.enums.EnumMerchantSubsidyType;
import com.iformall.enums.EnumPayEndFrom;
import com.iformall.enums.EnumPayWay;
import com.iformall.enums.EnumProfitSharingOrderStatus;
import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.enums.EnumProfitSharingType;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxAppinfoMapper;
import com.iformall.mapper.WxPayAccountMapper;
import com.iformall.mapper.WxPayOrderMapper;
import com.iformall.pay.WxPayment;
import com.iformall.pay.WxProfitSharing;
import com.iformall.pay.WxProfitSharingFinishP;
import com.iformall.pay.WxProfitSharingP;
import com.iformall.service.pay.entity.PayShareResult;
import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.PayShareBaseAdapterService;
import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.Utility;
import com.iformall.utils.XmlUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@@ -130,4 +146,117 @@ public class WxPayShareService extends PayShareBaseAdapterService{
return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id"));
}

@Autowired
WxAppinfoMapper wxAppinfoMapper;
@Autowired
WxPayAccountMapper wxPayAccountMapper;
@Autowired
WxPayOrderMapper wxPayOrderMapper;
private ShareNotifyAdapterResult getErrorResult(String msg) {
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "FAIL");
resultMap.put("return_msg", msg);
return new ShareNotifyAdapterResult(false,ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR.getCode(),msg,XmlUtil.getRequestXml(resultMap));
}
private ShareNotifyAdapterResult getSuccessResult(WxPayOrder payOrder, String transcationId){
SortedMap resultMap = new TreeMap();
resultMap.put("return_code", "SUCCESS");
resultMap.put("return_msg", "OK");
return new ShareNotifyAdapterResult(transcationId, payOrder, XmlUtil.getRequestXml(resultMap));
}
@Override
public ShareNotifyAdapterResult notify(Map<String, String> paramMap,EnumPayWay payWay) {
// how to get wechatAppId, wechatMchId, partnerKey
String appId = paramMap.get("appid");
String subAppId = paramMap.get("sub_appid");
String mchId = paramMap.get("mch_id");
String subMchId = paramMap.get("sub_mch_id");
WxAppinfo appinfo = null;
boolean isNormal = true;
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) {
// 普通商户号
appinfo = wxAppinfoMapper.findByAppId(appId);
if (appinfo == null) {
log.error("appid not found: " + appId);
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
isNormal = true;
} else {
// 服务号 现在用hmac-sha256
appinfo = wxAppinfoMapper.findByAppId(subAppId);
if (appinfo == null) {
log.error("subappid not found: " + subAppId);
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
isNormal = false;
}

WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId());
if (payAccount == null) {
throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND);
}
String partnerKey = payAccount.getApiKey();
try {
if (payWay == EnumPayWay.PAY_WAY_WECHAT) {
boolean signVerified = false;
if (isNormal) {
// 普通商户号支付
signVerified = WxPayment.verifyNotify(paramMap, partnerKey);
if (!signVerified) {
log.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR);
}
} else {
// 服务号 现在用hmac-sha256
signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey);
if (!signVerified) {
log.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR);
}
}

if (!"SUCCESS".equals(paramMap.get("return_code"))) {
log.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
return getErrorResult("订单状态码非SUCCESS");
}

String payOrderNo = paramMap.get("out_trade_no");
String timEndStr = paramMap.get("time_end");
Long payOrderId = Long.valueOf(payOrderNo);
WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId);
if (payOrder == null) {
log.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
return getErrorResult("订单不存在");
}
// 验证支付金额
if (!paramMap.get("total_fee").equals(payOrder.getPayAmount().toString())) {
log.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
return getErrorResult("订单总金额不一致");
}

Date timeEnd = null;

try {
timeEnd = Utility.getDateFromString(timEndStr);
} catch (ParseException e) {
log.error("解析timeEnd失败");
timeEnd = new Date();
}
payOrder.setPayTimeEnd(timeEnd);

log.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
return getSuccessResult(payOrder, paramMap.get("transaction_id"));
}
} catch (RuntimeException e) {
log.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR);
}

return getErrorResult("FAILED");
}
}

Loading…
Cancel
Save