|
|
@@ -14,10 +14,7 @@ import com.iformall.mapper.*; |
|
|
import com.iformall.pay.*; |
|
|
import com.iformall.pay.*; |
|
|
import com.iformall.service.WxBillAllService; |
|
|
import com.iformall.service.WxBillAllService; |
|
|
import com.iformall.service.WxPayBillService; |
|
|
import com.iformall.service.WxPayBillService; |
|
|
import com.iformall.utils.BeanUtils; |
|
|
|
|
|
import com.iformall.utils.MapUtil; |
|
|
|
|
|
import com.iformall.utils.Utility; |
|
|
|
|
|
import com.iformall.utils.XmlUtil; |
|
|
|
|
|
|
|
|
import com.iformall.utils.*; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
@@ -88,213 +85,166 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
|
EnumPayShare isShare = EnumPayShare.NO; |
|
|
EnumPayShare isShare = EnumPayShare.NO; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
// 1. check 订单 |
|
|
|
|
|
|
|
|
//查询账单是否存在 |
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
|
|
|
wxBillAll.setTenantId(appInfo.getTenantId()); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
if (bills == null) { |
|
|
|
|
|
logger.error("pay bill, bill not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString()); |
|
|
|
|
|
|
|
|
if (bills.size()==0) { |
|
|
|
|
|
logger.error("pay bill, bill not allow, repaymentReq: " + JSONObject.toJSONString(record) + ", payWay: " + payWay.toString()); |
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
Map<String, Object> bill; |
|
|
|
|
|
//获取账单数据 |
|
|
//获取账单数据 |
|
|
if(bills.size()>0){ |
|
|
|
|
|
bill = bills.get(0); |
|
|
|
|
|
}else{ |
|
|
|
|
|
logger.error("pay bill, bill not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> bill = bills.get(0); |
|
|
|
|
|
//获取支付账户信息 |
|
|
WxPayAccountBill payAccount = wxPayAccountBillMapper.selectByPrimaryKey(appInfo.getPayBillId()); |
|
|
WxPayAccountBill payAccount = wxPayAccountBillMapper.selectByPrimaryKey(appInfo.getPayBillId()); |
|
|
|
|
|
|
|
|
// 2. check 是否有支付订单 |
|
|
|
|
|
Date currentDate = new Date(); |
|
|
Date currentDate = new Date(); |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
|
|
List<WxPayBill> list = wxPayBillMapper.findList(record); |
|
|
|
|
|
String payBillNo; |
|
|
String payBillNo; |
|
|
|
|
|
List<WxPayBill> list = wxPayBillMapper.findList(record); |
|
|
|
|
|
//数据库不存在已有订单,新建订单 |
|
|
if (list.size() <= 0) { |
|
|
if (list.size() <= 0) { |
|
|
// 3. 创建支付订单 |
|
|
|
|
|
|
|
|
// 创建支付订单 |
|
|
Long id = idworker.nextId(); |
|
|
Long id = idworker.nextId(); |
|
|
payBillNo = String.valueOf(id); |
|
|
|
|
|
|
|
|
payBillNo = id+DateUtils.getSystemTime("yyMMddHHmmss"); |
|
|
record.setId(id); |
|
|
record.setId(id); |
|
|
record.setTenantId(appInfo.getTenantId()); |
|
|
record.setTenantId(appInfo.getTenantId()); |
|
|
record.setbUserId(record.getbUserId()); |
|
|
record.setbUserId(record.getbUserId()); |
|
|
record.setCreateTime(currentDate); |
|
|
record.setCreateTime(currentDate); |
|
|
record.setUpdateTime(currentDate); |
|
|
record.setUpdateTime(currentDate); |
|
|
record.setPayTimeStart(currentDate); |
|
|
record.setPayTimeStart(currentDate); |
|
|
record.setPayTimeEnd(currentDate); |
|
|
|
|
|
|
|
|
long endtime = currentDate.getTime() + 120 * 60 * 1000; |
|
|
|
|
|
record.setPayTimeEnd(new Date(endtime)); |
|
|
// 支付单号 |
|
|
// 支付单号 |
|
|
record.setPayBillNo(payBillNo); |
|
|
record.setPayBillNo(payBillNo); |
|
|
record.setPayAmount((Integer) bill.get("owe")); |
|
|
record.setPayAmount((Integer) bill.get("owe")); |
|
|
record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); |
|
|
record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); |
|
|
record.setShare(isShare.getCode()); |
|
|
record.setShare(isShare.getCode()); |
|
|
|
|
|
|
|
|
int sqlRow = wxPayBillMapper.insertSelective(record); |
|
|
int sqlRow = wxPayBillMapper.insertSelective(record); |
|
|
if (sqlRow != 1) { |
|
|
if (sqlRow != 1) { |
|
|
logger.error("pay bill insert error: " + record.toString()); |
|
|
|
|
|
|
|
|
logger.error("pay bill insert error: " + JSONObject.toJSONString(record)); |
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
} |
|
|
} |
|
|
|
|
|
logger.info("创建支付订单:"+record.toString()); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
//数据库存在订单信息,更新支付中状态,返回之前的预支付信息 |
|
|
record = list.get(0); |
|
|
record = list.get(0); |
|
|
record.setShare(isShare.getCode()); |
|
|
record.setShare(isShare.getCode()); |
|
|
payBillNo = String.valueOf(record.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isReal) { |
|
|
|
|
|
// 微信实际支付 |
|
|
|
|
|
if (payAccount.getType().equals(EnumPayMode.MCH.getCode())) { |
|
|
|
|
|
// 统一下单 普通商户模式 |
|
|
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
|
|
WxPayOrderP wxPayBillP = new WxPayOrderP(); |
|
|
|
|
|
wxPayBillP.setOpenid(record.getOpenId()); |
|
|
|
|
|
wxPayBillP.setAppid(appInfo.getAppId()); |
|
|
|
|
|
wxPayBillP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxPayBillP.setNonce_str(noncestr); |
|
|
|
|
|
wxPayBillP.setBody(bill.get("billType").toString()); |
|
|
|
|
|
wxPayBillP.setOut_trade_no(record.getPayBillNo()); |
|
|
|
|
|
wxPayBillP.setTotal_fee((Integer) bill.get("owe")); |
|
|
|
|
|
// 终端IP |
|
|
|
|
|
wxPayBillP.setSpbill_create_ip(record.getIp()); |
|
|
|
|
|
wxPayBillP.setNotify_url(payAccount.getPayNotifyUrl()); |
|
|
|
|
|
// 终端类型 |
|
|
|
|
|
wxPayBillP.setTrade_type(WxPay.TradeType.JSAPI.name()); |
|
|
|
|
|
// 订单ID |
|
|
|
|
|
wxPayBillP.setProduct_id(bill.get("id").toString()); |
|
|
|
|
|
wxPayBillP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); |
|
|
|
|
|
Date futureDate = new Date(); |
|
|
|
|
|
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); |
|
|
|
|
|
// 15分钟后结束 |
|
|
|
|
|
wxPayBillP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); |
|
|
|
|
|
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillP); |
|
|
|
|
|
wxPayBillP.setSign(WxPayment.createSign(payBillMap, payAccount.getApiKey())); |
|
|
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillP)); |
|
|
|
|
|
logger.info("pay bill, wechat pushBill, " + wxPayBillP.toString() + ", response: " + response); |
|
|
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
|
|
returnMap.put("payBillId", payBillNo); |
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
|
|
// update payBill with prepay_id |
|
|
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
try { |
|
|
|
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("pay bill update error: " + record.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
|
|
sighMap.put("appId", returnMap.get("appid")); |
|
|
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
|
|
sighMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
sighMap.put("signType", "MD5"); |
|
|
|
|
|
String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); |
|
|
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
|
|
logger.info("back to UI: " + returnMap.toString()); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
|
|
|
} else { |
|
|
|
|
|
return updatePayBill(record, returnMap, result_code); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 统一下单 // 服务商模式 |
|
|
|
|
|
|
|
|
//更新订单状态为支付中 |
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); |
|
|
|
|
|
record.setUpdateTime(currentDate); |
|
|
|
|
|
int sqlRow = wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
if (sqlRow != 1) { |
|
|
|
|
|
logger.error("pay bill update error: " + record.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
logger.info("数据库存在订单信息,更新支付中状态,返回之前的预支付信息:"+JSONObject.toJSONString(record)); |
|
|
|
|
|
//订单在120分钟之内没有失效,延用之前预支付订单号 |
|
|
|
|
|
if(record.getPayTimeEnd().after(new Date())){ |
|
|
String noncestr = Utility.generate32UUID(); |
|
|
String noncestr = Utility.generate32UUID(); |
|
|
WxPayOrderSP wxPayBillSP = new WxPayOrderSP(); |
|
|
|
|
|
wxPayBillSP.setSub_openid(record.getOpenId()); |
|
|
|
|
|
wxPayBillSP.setAppid(appInfo.getParentAppId()); |
|
|
|
|
|
wxPayBillSP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxPayBillSP.setSub_appid(appInfo.getAppId()); |
|
|
|
|
|
wxPayBillSP.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
|
|
wxPayBillSP.setNonce_str(noncestr); |
|
|
|
|
|
wxPayBillSP.setBody(bill.get("billType").toString()); |
|
|
|
|
|
wxPayBillSP.setOut_trade_no(record.getPayBillNo()); |
|
|
|
|
|
wxPayBillSP.setTotal_fee((Integer) bill.get("owe")); |
|
|
|
|
|
wxPayBillSP.setSpbill_create_ip(record.getIp()); // 终端IP |
|
|
|
|
|
wxPayBillSP.setNotify_url(payAccount.getPayNotifyUrl()); |
|
|
|
|
|
wxPayBillSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 |
|
|
|
|
|
wxPayBillSP.setProduct_id(String.valueOf(bill.get("id").toString())); // 订单ID |
|
|
|
|
|
wxPayBillSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); |
|
|
|
|
|
Date futureDate = new Date(); |
|
|
|
|
|
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); |
|
|
|
|
|
wxPayBillSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 |
|
|
|
|
|
wxPayBillSP.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
wxPayBillSP.setProfit_sharing(null); |
|
|
|
|
|
if (isShare == EnumPayShare.YES) { |
|
|
|
|
|
wxPayBillSP.setProfit_sharing("Y"); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillSP); |
|
|
|
|
|
|
|
|
|
|
|
wxPayBillSP.setSign(WxPayment.createSignHMAC(payBillMap, payAccount.getApiKey())); |
|
|
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillSP)); |
|
|
|
|
|
logger.info("pay bill, wechat pushBill, " + wxPayBillSP.toString() + ", response: " + response.toString()); |
|
|
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
|
|
returnMap.put("payBillId", payBillNo); |
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
|
|
// update payBill with prepay_id |
|
|
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
try { |
|
|
|
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("pay bill update error: " + record.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
|
|
sighMap.put("appId", appInfo.getAppId()); |
|
|
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
|
|
sighMap.put("package", "prepay_id=" + record.getPrepayId()); |
|
|
|
|
|
sighMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); |
|
|
|
|
|
Map<String,String> returnMap=new HashMap<>(); |
|
|
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
|
|
returnMap.put("package", "prepay_id=" + record.getPrepayId()); |
|
|
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
|
|
returnMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
logger.info("订单在120分钟之内没有失效,延用之前预支付订单号:"+JSONObject.toJSONString(record)); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
|
|
|
} |
|
|
|
|
|
//超过时间关闭订单 |
|
|
|
|
|
ResultData resultData = payBillClose(appInfo, record); |
|
|
|
|
|
if(resultData.code!=Result.SUCCESS){ |
|
|
|
|
|
return new ResultData(ErrorCode.ORDER_IS_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
logger.info("超过时间关闭订单:"+record.toString()); |
|
|
|
|
|
record=wxPayBillMapper.selectByPrimaryKey(record.getId()); |
|
|
|
|
|
//创建新的订单号 |
|
|
|
|
|
payBillNo = record.getId()+DateUtils.getSystemTime("yyMMddHHmmss"); |
|
|
|
|
|
record.setPayTimeStart(currentDate); |
|
|
|
|
|
long endtime = currentDate.getTime() + 120 * 60 * 1000; |
|
|
|
|
|
record.setPayTimeEnd(new Date(endtime)); |
|
|
|
|
|
record.setPayBillNo(payBillNo); |
|
|
|
|
|
record.setPayAmount((Integer) bill.get("owe")); |
|
|
|
|
|
record.setUpdateTime(currentDate); |
|
|
|
|
|
sqlRow = wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
if (sqlRow != 1) { |
|
|
|
|
|
logger.error("pay bill update error: " + JSONObject.toJSONString(record)); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
logger.info("新的订单数据:"+JSONObject.toJSONString(record)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
|
|
sighMap.put("appId", appInfo.getAppId()); |
|
|
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
|
|
sighMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
sighMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); |
|
|
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
|
|
returnMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
logger.info("back to UI: " + returnMap.toString()); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
|
|
|
} else { |
|
|
|
|
|
return updatePayBill(record, returnMap, result_code); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 统一下单 // 服务商模式 |
|
|
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
|
|
WxPayOrderSP wxPayBillSP = new WxPayOrderSP(); |
|
|
|
|
|
wxPayBillSP.setSub_openid(record.getOpenId()); |
|
|
|
|
|
wxPayBillSP.setAppid(appInfo.getParentAppId()); |
|
|
|
|
|
wxPayBillSP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxPayBillSP.setSub_appid(appInfo.getAppId()); |
|
|
|
|
|
wxPayBillSP.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
|
|
wxPayBillSP.setNonce_str(noncestr); |
|
|
|
|
|
wxPayBillSP.setBody(bill.get("billType").toString()); |
|
|
|
|
|
wxPayBillSP.setOut_trade_no(record.getPayBillNo()); |
|
|
|
|
|
wxPayBillSP.setTotal_fee((Integer) bill.get("owe")); |
|
|
|
|
|
// 终端IP |
|
|
|
|
|
wxPayBillSP.setSpbill_create_ip(record.getIp()); |
|
|
|
|
|
wxPayBillSP.setNotify_url(payAccount.getPayNotifyUrl()); |
|
|
|
|
|
// 终端类型 |
|
|
|
|
|
wxPayBillSP.setTrade_type(WxPay.TradeType.JSAPI.name()); |
|
|
|
|
|
// 订单ID |
|
|
|
|
|
wxPayBillSP.setProduct_id(String.valueOf(bill.get("id").toString())); |
|
|
|
|
|
wxPayBillSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); |
|
|
|
|
|
wxPayBillSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(record.getPayTimeEnd())); |
|
|
|
|
|
wxPayBillSP.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
wxPayBillSP.setProfit_sharing(null); |
|
|
|
|
|
if (isShare == EnumPayShare.YES) { |
|
|
|
|
|
wxPayBillSP.setProfit_sharing("Y"); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillSP); |
|
|
|
|
|
wxPayBillSP.setSign(WxPayment.createSignHMAC(payBillMap, payAccount.getApiKey())); |
|
|
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillSP)); |
|
|
|
|
|
logger.info("pay bill, wechat pushBill, " + wxPayBillSP.toString() + ", response: " + response); |
|
|
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
|
|
returnMap.put("payBillId", record.getId().toString()); |
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
|
|
// update payBill with prepay_id |
|
|
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
try { |
|
|
|
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("pay bill update error: " + record.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
|
|
|
// 虚拟支付 |
|
|
|
|
|
WxPayOrderP wxPayBillP = new WxPayOrderP(); |
|
|
|
|
|
wxPayBillP.setOpenid(record.getOpenId()); |
|
|
|
|
|
wxPayBillP.setAppid(appInfo.getAppId()); |
|
|
|
|
|
wxPayBillP.setMch_id(payAccount.getMchId()); |
|
|
|
|
|
wxPayBillP.setBody(bill.get("billType").toString()); |
|
|
|
|
|
wxPayBillP.setOut_trade_no(record.getPayBillNo()); |
|
|
|
|
|
wxPayBillP.setTotal_fee((Integer) bill.get("owe")); |
|
|
|
|
|
// 终端IP |
|
|
|
|
|
wxPayBillP.setSpbill_create_ip(record.getIp()); |
|
|
|
|
|
wxPayBillP.setNotify_url(payAccount.getPayNotifyUrl()); |
|
|
|
|
|
// 终端类型 |
|
|
|
|
|
wxPayBillP.setTrade_type(WxPay.TradeType.JSAPI.name()); |
|
|
|
|
|
// 订单ID |
|
|
|
|
|
wxPayBillP.setProduct_id(bill.get("id").toString()); |
|
|
|
|
|
wxPayBillP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); |
|
|
|
|
|
Date futureDate = new Date(); |
|
|
|
|
|
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); |
|
|
|
|
|
// 15分钟后结束 |
|
|
|
|
|
wxPayBillP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); |
|
|
|
|
|
wxPayBillP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayBillP), payAccount.getApiKey())); |
|
|
|
|
|
Map<String, String> returnMap = BeanUtils.toStringMap(wxPayBillP); |
|
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
|
|
sighMap.put("appId", appInfo.getAppId()); |
|
|
|
|
|
sighMap.put("timeStamp", timestamp); |
|
|
|
|
|
sighMap.put("nonceStr", noncestr); |
|
|
|
|
|
sighMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
sighMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); |
|
|
|
|
|
returnMap.put("timeStamp", timestamp); |
|
|
|
|
|
returnMap.put("nonceStr", noncestr); |
|
|
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
|
|
returnMap.put("signType", "HMAC-SHA256"); |
|
|
|
|
|
logger.info("back to UI: " + returnMap.toString()); |
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
} |
|
|
} |
|
|
|
|
|
return updatePayBill(record, returnMap, result_code); |
|
|
} catch (RuntimeException e) { |
|
|
} catch (RuntimeException e) { |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
@@ -379,8 +329,8 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
@Override |
|
|
@Override |
|
|
public ResultData payBillQuery(WxAppinfo appInfo, WxPayBill record) { |
|
|
public ResultData payBillQuery(WxAppinfo appInfo, WxPayBill record) { |
|
|
try { |
|
|
try { |
|
|
if (StringUtils.isBlank(record.getPayBillNo())){ |
|
|
|
|
|
record.setPayBillNo(String.valueOf(record.getId())); |
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(record.getPayBillNo())) { |
|
|
|
|
|
record.setPayBillNo(record.getPayBillNo()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String response = wechatPayBillQuery(appInfo, record); |
|
|
String response = wechatPayBillQuery(appInfo, record); |
|
|
@@ -398,13 +348,13 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
//USERPAYING--用户支付中 |
|
|
//USERPAYING--用户支付中 |
|
|
//PAYERROR--支付失败(其他原因,如银行返回失败) |
|
|
//PAYERROR--支付失败(其他原因,如银行返回失败) |
|
|
if ("SUCCESS".equals(trade_state)) { |
|
|
if ("SUCCESS".equals(trade_state)) { |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); |
|
|
handlePayBillStatusUpdate(record); |
|
|
handlePayBillStatusUpdate(record); |
|
|
} else if ("USERPAYING".equals(trade_state)) { |
|
|
} else if ("USERPAYING".equals(trade_state)) { |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); |
|
|
handlePayBillStatusUpdate(record); |
|
|
handlePayBillStatusUpdate(record); |
|
|
} else { |
|
|
} else { |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_FAIL.getCode()); |
|
|
|
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_FAIL.getCode()); |
|
|
handlePayBillStatusUpdate(record); |
|
|
handlePayBillStatusUpdate(record); |
|
|
} |
|
|
} |
|
|
return new ResultData(Result.SUCCESS, "订单查询成功", returnMap); |
|
|
return new ResultData(Result.SUCCESS, "订单查询成功", returnMap); |
|
|
@@ -488,8 +438,13 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
String result_code = returnMap.get("result_code"); |
|
|
String result_code = returnMap.get("result_code"); |
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_CANCEL.getCode()); |
|
|
|
|
|
handlePayBillStatusUpdate(record); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
record.setPayBillStatus(EnumPayStatus.PAY_WAY_CANCEL.getCode()); |
|
|
|
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("pay bill update error: " + record.toString()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
return new ResultData(Result.SUCCESS, "订单关闭成功", returnMap); |
|
|
return new ResultData(Result.SUCCESS, "订单关闭成功", returnMap); |
|
|
} else { |
|
|
} else { |
|
|
String errMsg = ""; |
|
|
String errMsg = ""; |
|
|
@@ -527,11 +482,14 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
@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 |
|
|
// how to get wechatAppId, wechatMchId, partnerKey |
|
|
|
|
|
logger.info("-------------"); |
|
|
|
|
|
logger.info("微信回调返回值:" + JSONObject.toJSONString(paramMap)); |
|
|
|
|
|
logger.info("-------------"); |
|
|
String appId = paramMap.get("appid"); |
|
|
String appId = paramMap.get("appid"); |
|
|
String subAppId = paramMap.get("sub_appid"); |
|
|
String subAppId = paramMap.get("sub_appid"); |
|
|
String mchId = paramMap.get("mch_id"); |
|
|
String mchId = paramMap.get("mch_id"); |
|
|
String subMchId = paramMap.get("sub_mch_id"); |
|
|
String subMchId = paramMap.get("sub_mch_id"); |
|
|
WxAppinfo appinfo = null; |
|
|
|
|
|
|
|
|
WxAppinfo appinfo; |
|
|
boolean isNormal = true; |
|
|
boolean isNormal = true; |
|
|
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { |
|
|
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { |
|
|
// 普通商户号 |
|
|
// 普通商户号 |
|
|
@@ -583,7 +541,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
|
|
|
|
|
|
String payBillNo = paramMap.get("out_trade_no"); |
|
|
String payBillNo = paramMap.get("out_trade_no"); |
|
|
String timEndStr = paramMap.get("time_end"); |
|
|
String timEndStr = paramMap.get("time_end"); |
|
|
Long payBillId = Long.valueOf(payBillNo); |
|
|
|
|
|
|
|
|
Long payBillId = Long.valueOf(payBillNo.substring(0,payBillNo.length()-12)); |
|
|
WxPayBill payBill = wxPayBillMapper.selectByPrimaryKey(payBillId); |
|
|
WxPayBill payBill = wxPayBillMapper.selectByPrimaryKey(payBillId); |
|
|
if (payBill == null) { |
|
|
if (payBill == null) { |
|
|
logger.warn("notify bill, wxpay check pay bill not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
logger.warn("notify bill, wxpay check pay bill not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); |
|
|
@@ -630,14 +588,30 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
return XmlUtil.getRequestXml(resultMap); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void callback(Map<String, String> paramMap, EnumPayWay payWay) { |
|
|
|
|
|
|
|
|
public WxPayBill getById(Long id) { |
|
|
|
|
|
return wxPayBillMapper.selectByPrimaryKey(id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void updatePayBillStatus(WxPayBill payBill) { |
|
|
|
|
|
try { |
|
|
|
|
|
logger.info("更新支付订单"); |
|
|
|
|
|
wxPayBillMapper.selectByPrimaryKey(payBill); |
|
|
|
|
|
}catch (MallinkException e){ |
|
|
|
|
|
logger.info("更新支付订单失败"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxPayBill getById(Long id) { |
|
|
|
|
|
return wxPayBillMapper.selectByPrimaryKey(id); |
|
|
|
|
|
|
|
|
public WxPayBill queryPayBill(WxPayBill payBill) { |
|
|
|
|
|
List<WxPayBill> select = wxPayBillMapper.select(payBill); |
|
|
|
|
|
if(select.size()>0){ |
|
|
|
|
|
return select.get(0); |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@@ -646,44 +620,41 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
Date currentDate = new Date(); |
|
|
Date currentDate = new Date(); |
|
|
EnumPayStatus payStatus = EnumPayStatus.getEnum(record.getPayBillStatus()); |
|
|
EnumPayStatus payStatus = EnumPayStatus.getEnum(record.getPayBillStatus()); |
|
|
// 判断支付状态 |
|
|
// 判断支付状态 |
|
|
if (payStatus == EnumPayStatus.PAY_STATUS_SUCCESS) { |
|
|
|
|
|
|
|
|
if (payStatus == EnumPayStatus.PAY_WAY_SUCCESS) { |
|
|
// 已经是成功状态,只更新transactionId |
|
|
// 已经是成功状态,只更新transactionId |
|
|
try { |
|
|
try { |
|
|
record.setUpdateTime(currentDate); |
|
|
record.setUpdateTime(currentDate); |
|
|
record.setTransactionId(transactionId); |
|
|
record.setTransactionId(transactionId); |
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
wxPayBillMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
|
|
|
wxBillAll.setId(record.getBillId()); |
|
|
|
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
|
|
|
if (bills.size() > 0) { |
|
|
|
|
|
Map<String, Object> bill = bills.get(0); |
|
|
|
|
|
wxBillAllService.updateBill(bill); |
|
|
|
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error(e.getMessage()); |
|
|
logger.error(e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
} |
|
|
} |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (payStatus != EnumPayStatus.PAY_STATUS_WAIT) { |
|
|
|
|
|
logger.error("pay success handle, payBill " + record.getPayBillNo() + |
|
|
|
|
|
"is paid success , billId : " + record.getBillId()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
if (bills == null) { |
|
|
|
|
|
logger.error("pay success handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, Object> bill=null; |
|
|
|
|
|
if(bills.size()>0){ |
|
|
|
|
|
bill = bills.get(0); |
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
if (bills.size()==0) { |
|
|
logger.error("pay success handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo()); |
|
|
logger.error("pay success handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo()); |
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
|
|
|
Map<String, Object> bill; |
|
|
|
|
|
bill = bills.get(0); |
|
|
|
|
|
|
|
|
// 修改支付订单状态 |
|
|
// 修改支付订单状态 |
|
|
WxPayBill updateBill = new WxPayBill(); |
|
|
WxPayBill updateBill = new WxPayBill(); |
|
|
updateBill.setId(record.getId()); |
|
|
updateBill.setId(record.getId()); |
|
|
updateBill.setBillId(record.getBillId()); |
|
|
updateBill.setBillId(record.getBillId()); |
|
|
updateBill.setUpdateTime(currentDate); |
|
|
updateBill.setUpdateTime(currentDate); |
|
|
updateBill.setPayBillStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
|
|
|
|
|
updateBill.setPayBillStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); |
|
|
updateBill.setTransactionId(transactionId); |
|
|
updateBill.setTransactionId(transactionId); |
|
|
try { |
|
|
try { |
|
|
wxPayBillMapper.updateByPrimaryKeySelective(updateBill); |
|
|
wxPayBillMapper.updateByPrimaryKeySelective(updateBill); |
|
|
@@ -694,13 +665,10 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
|
|
|
|
|
|
//修改账单状态 |
|
|
//修改账单状态 |
|
|
try { |
|
|
try { |
|
|
int _count = wxBillAllService.updateBill(bill); |
|
|
|
|
|
if (_count > 1) { |
|
|
|
|
|
throw new MallinkException(ErrorCode.BILL_UPDATE_FAILED); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
wxBillAllService.updateBill(bill); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error(e.getMessage()); |
|
|
logger.error(e.getMessage()); |
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "账单更新"); |
|
|
|
|
|
|
|
|
throw new MallinkException(ErrorCode.BILL_UPDATE_FAILED); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@@ -709,7 +677,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public void handlePayBillStatusUpdate(WxPayBill record) { |
|
|
public void handlePayBillStatusUpdate(WxPayBill record) { |
|
|
// 判断支付状态 |
|
|
// 判断支付状态 |
|
|
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_WAIT.getCode())) { |
|
|
|
|
|
|
|
|
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_WAIT.getCode())) { |
|
|
logger.error("pay handle, payBill " + record.getPayBillNo() + |
|
|
logger.error("pay handle, payBill " + record.getPayBillNo() + |
|
|
"is complete, billId : " + record.getBillId()); |
|
|
"is complete, billId : " + record.getBillId()); |
|
|
return; |
|
|
return; |
|
|
@@ -717,25 +685,11 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
WxBillAll wxBillAll = new WxBillAll(); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
wxBillAll.setId(record.getBillId()); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); |
|
|
if (bills == null) { |
|
|
|
|
|
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillGid : " + record.getPayBillNo()); |
|
|
|
|
|
|
|
|
if (bills.size()==0) { |
|
|
|
|
|
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo()); |
|
|
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); |
|
|
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); |
|
|
} |
|
|
} |
|
|
WxMerchantBUser user = wxMerchantBUserMapper.selectByPrimaryKey(record.getbUserId()); |
|
|
|
|
|
if (user == null) { |
|
|
|
|
|
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillGid : " + record.getPayBillNo()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.BUSER_NOT_IN_APP); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, Object> bill = bills.get(0); |
|
|
Map<String, Object> bill = bills.get(0); |
|
|
Integer owe = (Integer) bill.get("owe"); |
|
|
|
|
|
if (owe > 0) { |
|
|
|
|
|
// 订单金额不为0时, 支付订单未创建, 返回异常 |
|
|
|
|
|
if (!(record.getId() >0)) { |
|
|
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
|
|
if (record.getId() > 0) { |
|
|
if (record.getId() > 0) { |
|
|
// 1. get appinfo |
|
|
// 1. get appinfo |
|
|
WxAppinfo appInfo = null; |
|
|
WxAppinfo appInfo = null; |
|
|
@@ -747,13 +701,12 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
appInfo = appList.get(0); |
|
|
appInfo = appList.get(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
WxPayBill updateBill = null; |
|
|
|
|
|
|
|
|
|
|
|
// 检查支付订单状态 |
|
|
// 检查支付订单状态 |
|
|
WxPayBill payBillQ = new WxPayBill(); |
|
|
WxPayBill payBillQ = new WxPayBill(); |
|
|
payBillQ.setId(record.getId()); |
|
|
payBillQ.setId(record.getId()); |
|
|
payBillQ.setTenantId(bill.get("tenantId").toString()); |
|
|
payBillQ.setTenantId(bill.get("tenantId").toString()); |
|
|
payBillQ.setBillId(record.getBillId()); |
|
|
payBillQ.setBillId(record.getBillId()); |
|
|
|
|
|
WxPayBill updateBill; |
|
|
try { |
|
|
try { |
|
|
updateBill = wxPayBillMapper.selectOne(payBillQ); |
|
|
updateBill = wxPayBillMapper.selectOne(payBillQ); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
@@ -761,34 +714,34 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_CANCEL.getCode())) { |
|
|
|
|
|
|
|
|
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_FAIL.getCode())) { |
|
|
// 支付订单取消 |
|
|
// 支付订单取消 |
|
|
if (record.getPayAmount() > 0) { |
|
|
|
|
|
|
|
|
if (updateBill.getPayAmount() > 0) { |
|
|
payBillQ = new WxPayBill(); |
|
|
payBillQ = new WxPayBill(); |
|
|
payBillQ.setTenantId(bill.get("tenantId").toString()); |
|
|
payBillQ.setTenantId(bill.get("tenantId").toString()); |
|
|
payBillQ.setBillId(record.getBillId()); |
|
|
payBillQ.setBillId(record.getBillId()); |
|
|
payBillQ.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
|
|
List<WxPayBill> payBills = wxPayBillMapper.select(payBillQ); |
|
|
List<WxPayBill> payBills = wxPayBillMapper.select(payBillQ); |
|
|
for (WxPayBill payBill : payBills) { |
|
|
for (WxPayBill payBill : payBills) { |
|
|
payBillClose(appInfo, payBill); |
|
|
|
|
|
|
|
|
if(payBill.getPayTimeEnd().before(new Date())){ |
|
|
|
|
|
payBillClose(appInfo, payBill); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// 支付订单成功? |
|
|
// 支付订单成功? |
|
|
if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { |
|
|
|
|
|
if (StringUtils.isBlank(updateBill.getTransactionId())) { |
|
|
|
|
|
|
|
|
if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_SUCCESS.getCode())) { |
|
|
|
|
|
if (!StringUtils.isBlank(updateBill.getTransactionId())) { |
|
|
// 回调已设置成功 |
|
|
// 回调已设置成功 |
|
|
// 继续修改订单状态 |
|
|
// 继续修改订单状态 |
|
|
} else { |
|
|
} else { |
|
|
// 回调异常 |
|
|
// 回调异常 |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "transactionId未获取"); |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "transactionId未获取"); |
|
|
} |
|
|
} |
|
|
} else if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_WAIT.getCode())) { |
|
|
|
|
|
|
|
|
} else if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_WAIT.getCode())) { |
|
|
// 回调未返回,主动检查支付订单状态 |
|
|
// 回调未返回,主动检查支付订单状态 |
|
|
try { |
|
|
try { |
|
|
record.setPayBillNo(String.valueOf(record.getId())); |
|
|
record.setPayBillNo(String.valueOf(record.getId())); |
|
|
String response = wechatPayBillQuery(appInfo, record); |
|
|
String response = wechatPayBillQuery(appInfo, record); |
|
|
|
|
|
|
|
|
logger.info("pay bill query, " + record.toString() + ", response: " + response); |
|
|
logger.info("pay bill query, " + record.toString() + ", response: " + response); |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
String result_code = returnMap.get("result_code"); |
|
|
String result_code = returnMap.get("result_code"); |
|
|
@@ -804,6 +757,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
if ("SUCCESS".equals(trade_state)) { |
|
|
if ("SUCCESS".equals(trade_state)) { |
|
|
// 查询支付订单 -- 已支付 |
|
|
// 查询支付订单 -- 已支付 |
|
|
// 继续更改状态 |
|
|
// 继续更改状态 |
|
|
|
|
|
wxBillAllService.updateBill(bill); |
|
|
} else { |
|
|
} else { |
|
|
// 支付订单未成功,返回异常 |
|
|
// 支付订单未成功,返回异常 |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "支付订单未成功"); |
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "支付订单未成功"); |
|
|
@@ -820,18 +774,6 @@ public class WxPayBillServiceImpl implements WxPayBillService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 修改账单状态 |
|
|
|
|
|
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { |
|
|
|
|
|
try { |
|
|
|
|
|
int _count = wxBillAllService.updateBill(bill); |
|
|
|
|
|
if (_count > 1) { |
|
|
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "账单更新"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|