|
|
@@ -15,15 +15,18 @@ import com.simple.exception.BizMessageException; |
|
|
import com.simple.exception.MallinkException; |
|
|
import com.simple.exception.MallinkException; |
|
|
import com.simple.mapper.WxOrderMapper; |
|
|
import com.simple.mapper.WxOrderMapper; |
|
|
import com.simple.mapper.WxPayOrderMapper; |
|
|
import com.simple.mapper.WxPayOrderMapper; |
|
|
|
|
|
import com.simple.pay.WxPayment; |
|
|
import com.simple.service.WxOrderService; |
|
|
import com.simple.service.WxOrderService; |
|
|
import com.simple.service.WxPayOrderService; |
|
|
import com.simple.service.WxPayOrderService; |
|
|
import com.simple.utils.Utility; |
|
|
import com.simple.utils.Utility; |
|
|
|
|
|
import com.simple.utils.XmlUtil; |
|
|
import org.apache.log4j.Logger; |
|
|
import org.apache.log4j.Logger; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import com.simple.common.IdWorker; |
|
|
import com.simple.common.IdWorker; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import tk.mybatis.mapper.entity.Example; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
@@ -32,11 +35,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxOrderMapper wxOrderMapper; |
|
|
WxOrderMapper wxOrderMapper; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxPayOrderMapper wxPayOrderMapper; |
|
|
WxPayOrderMapper wxPayOrderMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxOrderService wxOrderService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
|
|
public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { |
|
|
public ResultData createPayOrder(WxPayOrder record, EnumPayWay payWay) { |
|
|
try { |
|
|
try { |
|
|
// 1. check 订单 |
|
|
// 1. check 订单 |
|
|
@@ -75,6 +81,81 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String notify(Map<String, String> paramMap, EnumPayWay payWay) { |
|
|
public String notify(Map<String, String> paramMap, EnumPayWay payWay) { |
|
|
|
|
|
// how to get wechatAppId, wechatMchId, partnerKey |
|
|
|
|
|
String wechatAppId = ""; |
|
|
|
|
|
String wechatMchId = ""; |
|
|
|
|
|
String partnerKey = ""; |
|
|
|
|
|
try { |
|
|
|
|
|
if (payWay == EnumPayWay.PAY_WAY_WEAPP) { |
|
|
|
|
|
boolean signVerified = false; |
|
|
|
|
|
if (payWay == EnumPayWay.PAY_WAY_WECHAT) { |
|
|
|
|
|
// 微信支付 |
|
|
|
|
|
signVerified = WxPayment.verifyNotify(paramMap, partnerKey); |
|
|
|
|
|
} |
|
|
|
|
|
if (!signVerified) { |
|
|
|
|
|
logger.warn("notify order, wxpay checksign error, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.PAYORDER_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()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "订单状态码非SUCCESS"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
if (!wechatAppId.equals(paramMap.get("appid"))) { |
|
|
|
|
|
logger.warn("notify order, wxpay appid is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "非法请求appid"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
if (!(wechatMchId.equals(paramMap.get("mch_id")))) { |
|
|
|
|
|
logger.warn("notify order, wxpay mch_id is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "非法请求mch_id"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!"SUCCESS".equals(paramMap.get("result_code"))) { |
|
|
|
|
|
logger.warn("notify order, wxpay result_code is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "result_code fail"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
String payOrderNo = paramMap.get("out_trade_no"); |
|
|
|
|
|
Long payOrderId = Long.valueOf(payOrderNo); |
|
|
|
|
|
WxPayOrder payOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); |
|
|
|
|
|
if (payOrder == null) { |
|
|
|
|
|
logger.warn("notify order, wxpay check pay order not exists, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "订单不存在"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(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()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "FAIL"); |
|
|
|
|
|
resultMap.put("return_msg", "订单总金额不一致"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理支付成功 |
|
|
|
|
|
handleOrderPaySuccess(payOrder, paramMap.get("transaction_id")); |
|
|
|
|
|
logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); |
|
|
|
|
|
Map<String, String> resultMap = new LinkedHashMap<>(); |
|
|
|
|
|
resultMap.put("return_code", "SUCCESS"); |
|
|
|
|
|
resultMap.put("return_msg", "OK"); |
|
|
|
|
|
return XmlUtil.parseDto2Xml(resultMap, ""); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
|
logger.warn("notify order, alipay checksign error, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.PAYORDER_NOTIFY_CHECK_SIGN_ERROR); |
|
|
|
|
|
} |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -83,6 +164,47 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
|
|
public void handleOrderPaySuccess(WxPayOrder record, String tradeNo) { |
|
|
|
|
|
EnumPayStatus payStatus = EnumPayStatus.getEnum(record.getPayOrderStatus()); |
|
|
|
|
|
// 判断支付状态 |
|
|
|
|
|
if (payStatus != EnumPayStatus.PAY_WAY_WAIT) { |
|
|
|
|
|
logger.error("pay success handle, payOrder " + record.getPayOrderNo() + |
|
|
|
|
|
"is paid success , orderId : " + record.getOrderId()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
WxOrder order = wxOrderMapper.selectByPrimaryKey(record.getOrderId()); |
|
|
|
|
|
if (order == null) { |
|
|
|
|
|
logger.error("pay success handle, order " + record.getOrderId() +" not found , payOrderGid : " + record.getPayOrderNo()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 修改订单状态 |
|
|
|
|
|
wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); |
|
|
|
|
|
|
|
|
|
|
|
// 修改支付订单状态 |
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
|
|
WxPayOrder updatePayOrder = new WxPayOrder(); |
|
|
|
|
|
updatePayOrder.setId(record.getId()); |
|
|
|
|
|
updatePayOrder.setOrderId(record.getOrderId()); |
|
|
|
|
|
updatePayOrder.setUpdateTime(currentDate); |
|
|
|
|
|
updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); |
|
|
|
|
|
//updatePayOrder.setTradeNo(tradeNo); |
|
|
|
|
|
wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> msgMap = new HashMap<>(); |
|
|
|
|
|
try { |
|
|
|
|
|
msgMap.put("name", String.valueOf(order.getCouponId())); |
|
|
|
|
|
msgMap.put("orderNo", String.valueOf(order.getId())); |
|
|
|
|
|
msgMap.put("createTime", Utility.getDataFormatString3(order.getCreateDate())); |
|
|
|
|
|
msgMap.put("standingTime", order.getCreateDate() + "-" + currentDate ); |
|
|
|
|
|
//smsSenderHandler.sendSms("SMS_18195394", order.getMobile(), msgMap); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("pay success handle, sms send exception, payOrderi: " + updatePayOrder+ ", msgMap: " + msgMap.toString() + ", e: " + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageInfo<WxPayOrder> listAsPage(WxPayOrder record, Integer pageIndex, Integer pageSize) { |
|
|
public PageInfo<WxPayOrder> listAsPage(WxPayOrder record, Integer pageIndex, Integer pageSize) { |
|
|
|