|
|
|
@@ -17,6 +17,7 @@ import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.pay.*; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.service.helper.WxPayOrderServiceHelper; |
|
|
|
import com.iformall.utils.*; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
@@ -234,11 +235,39 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
if (oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { |
|
|
|
logger.error("已支付>>>" + order); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_EXIST); |
|
|
|
//如果是支付中的,则调用微信接口查询支付状态 |
|
|
|
}else if (oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_WAIT.getCode()) { |
|
|
|
logger.error("支付中,等待微信同步状态>>>" + order); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付中,等待微信同步状态,防止重复支付!"); |
|
|
|
}else { |
|
|
|
//如果是其他状态的,可以重复支付,把状态更新为支付中,不再新增订单 |
|
|
|
int wxpaystatus = WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); |
|
|
|
if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经支付,请勿重复支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_REFUND.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REFUND.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经退款,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_CLOSE.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_CLOSE.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经关闭,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_REVERSE.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已撤销,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_WAIT.getCode()==wxpaystatus) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单支付中,请勿重复支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_FAIL.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
oldRecord.setPayOrderNo(String.valueOf(idworker.nextId())); |
|
|
|
int sqlRow0 =wxPayOrderMapper.updateById(oldRecord); |
|
|
|
if (sqlRow0 != 1) { |
|
|
|
logger.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
record = oldRecord; |
|
|
|
} |
|
|
|
//如果是支付错误,可以重新支付 |
|
|
|
}else if(oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_FAIL.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
//重新设置支付no |
|
|
|
oldRecord.setPayOrderNo(String.valueOf(idworker.nextId())); |
|
|
|
@@ -248,6 +277,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
record = oldRecord; |
|
|
|
}else { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单状态不允许支付!"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
{ |
|
|
|
@@ -666,65 +697,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String wechatPayOrderQuery(WxAppinfo appInfo, WxPayOrder record) { |
|
|
|
// get payAccount |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
// 普通商户号模式 |
|
|
|
WxPayOrderQ payOrderQ = new WxPayOrderQ(); |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
payOrderQ.setAppid(appInfo.getAppId()); |
|
|
|
payOrderQ.setMch_id(payAccount.getMchId()); |
|
|
|
payOrderQ.setNonce_str(noncestr); |
|
|
|
if (StringUtils.isNotBlank(record.getTransactionId())) { |
|
|
|
payOrderQ.setTransaction_id(record.getTransactionId()); |
|
|
|
} else { |
|
|
|
payOrderQ.setOut_trade_no(record.getPayOrderNo()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
Map map = BeanUtils.toStringMap(payOrderQ); |
|
|
|
payOrderQ.setSign(WxPayment.createSign(map, payAccount.getApiKey())); |
|
|
|
map = BeanUtils.toStringMap(payOrderQ); |
|
|
|
String response = WxPay.orderQuery(map); |
|
|
|
return response; |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 服务商模式 |
|
|
|
WxPayOrderSQ payOrderSQ = new WxPayOrderSQ(); |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
payOrderSQ.setAppid(appInfo.getParentAppId()); |
|
|
|
payOrderSQ.setSub_appid(appInfo.getAppId()); |
|
|
|
payOrderSQ.setMch_id(payAccount.getMchId()); |
|
|
|
payOrderSQ.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
payOrderSQ.setNonce_str(noncestr); |
|
|
|
if (StringUtils.isNotBlank(record.getTransactionId())) { |
|
|
|
payOrderSQ.setTransaction_id(record.getTransactionId()); |
|
|
|
} else { |
|
|
|
payOrderSQ.setOut_trade_no(record.getPayOrderNo()); |
|
|
|
} |
|
|
|
payOrderSQ.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
|
|
try { |
|
|
|
Map map = BeanUtils.toStringMap(payOrderSQ); |
|
|
|
payOrderSQ.setSign(WxPayment.createSignHMAC(map, payAccount.getApiKey())); |
|
|
|
map = BeanUtils.toStringMap(payOrderSQ); |
|
|
|
|
|
|
|
String response = WxPay.orderQuery(map); |
|
|
|
return response; |
|
|
|
} catch (RuntimeException e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 微信订单查询 |
|
|
|
*/ |
|
|
|
@@ -750,7 +722,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(record); |
|
|
|
|
|
|
|
String response = wechatPayOrderQuery(appInfo, record); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
String response = WxPayOrderServiceHelper.wechatPayOrderQuery(appInfo, record,payAccount); |
|
|
|
|
|
|
|
logger.info("pay order query, " + record.toString() + ", response: " + response); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
@@ -1648,7 +1621,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
// 回调未返回,主动检查支付订单状态 |
|
|
|
try { |
|
|
|
record.setPayOrderNo(String.valueOf(record.getId())); |
|
|
|
String response = wechatPayOrderQuery(appInfo, record); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
String response = WxPayOrderServiceHelper.wechatPayOrderQuery(appInfo, record,payAccount); |
|
|
|
|
|
|
|
logger.info("pay order query, " + record.toString() + ", response: " + response); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
|