|
|
|
@@ -74,20 +74,18 @@ public class WxPayAdapterService implements PayAdapterService{ |
|
|
|
return wxPayOrderP; |
|
|
|
} |
|
|
|
|
|
|
|
private PayAdapterResult getOrderPResult(Map<String, String> returnMap,WxPayOrder record,String noncestr) { |
|
|
|
private PayAdapterResult getOrderPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,String noncestr) { |
|
|
|
PayAdapterResult par = new PayAdapterResult(); |
|
|
|
returnMap.put("payOrderId", String.valueOf(record.getId())); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
par.setSuccess(true); |
|
|
|
par.setMsg("success."); |
|
|
|
par.setData(returnMap); |
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxPayOrderMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); |
|
|
|
Map<String, String> sighMap = MapUtil.getOrderMap(); |
|
|
|
@@ -102,7 +100,6 @@ public class WxPayAdapterService implements PayAdapterService{ |
|
|
|
returnMap.put("package", "prepay_id=" + prepay_id); |
|
|
|
returnMap.put("paySign", signAgent); |
|
|
|
log.info("back to UI: " + returnMap.toString()); |
|
|
|
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
@@ -114,19 +111,18 @@ public class WxPayAdapterService implements PayAdapterService{ |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxPayOrderMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
|
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg(errMsg); |
|
|
|
par.setData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
return par; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private WxPayOrderSP generateWxPayOrderSP(WxPayAccount payAccount, WxOrder order, WxPayOrder record,WxAppinfo appInfo,String openId,String parentAppId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { |
|
|
|
private WxPayOrderSP generateWxPayOrderSP(WxPayAccount payAccount, WxOrder order, WxPayOrder record,WxAppinfo appInfo,String openId,String appId,Date currentDate,EnumPayShare isShare) throws Exception { |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); |
|
|
|
wxPayOrderSP.setSub_openid(openId); |
|
|
|
@@ -157,83 +153,75 @@ public class WxPayAdapterService implements PayAdapterService{ |
|
|
|
return wxPayOrderSP; |
|
|
|
} |
|
|
|
|
|
|
|
private PayAdapterResult getOrderSPResult(Map<String, String> returnMap,WxPayOrder record,WxPayAccount payAccount,WxAppinfo appInfo,String noncestr) { |
|
|
|
PayAdapterResult par = new PayAdapterResult(); |
|
|
|
returnMap.put("payOrderId", String.valueOf(record.getId())); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
par.setSuccess(true); |
|
|
|
par.setMsg("success."); |
|
|
|
par.setData(returnMap); |
|
|
|
|
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
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"); |
|
|
|
log.info("back to UI: " + returnMap.toString()); |
|
|
|
} else { |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("return_msg"); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
par.setSuccess(false); |
|
|
|
par.setMsg(errMsg); |
|
|
|
par.setData(returnMap); |
|
|
|
} |
|
|
|
return par; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PayAdapterResult pay(WxPayAccount payAccount, WxOrder order, WxPayOrder record, Object... params) { |
|
|
|
WxAppinfo appInfo = (WxAppinfo) params[01]; |
|
|
|
String openId = (String) params[1]; |
|
|
|
String appId = (String) params[2]; |
|
|
|
Date currentDate = (Date) params[3]; |
|
|
|
EnumPayShare isShare = (EnumPayShare) params[4]; |
|
|
|
|
|
|
|
public PayAdapterResult pay(WxPayAccount payAccount, WxOrder order, WxPayOrder record,EnumPayShare isShare,WxAppinfo appInfo, Object... params) throws Exception { |
|
|
|
String openId = (String) params[0]; |
|
|
|
String appId = (String) params[1]; |
|
|
|
Date currentDate = (Date) params[2]; |
|
|
|
|
|
|
|
|
|
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
WxPayOrderP wxPayOrderP = generateWxPayOrderP(payAccount,order,record,openId,appId,currentDate); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); |
|
|
|
|
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 统一下单 // 服务商模式 |
|
|
|
WxPayOrderSP wxPayOrderSP = generateWxPayOrderSP(payAccount,order,record,openId,parentAppId,appId,currentDate,isShare); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); |
|
|
|
|
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
returnMap.put("payOrderId", String.valueOf(record.getId())); |
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_code)) { |
|
|
|
String prepay_id = returnMap.get("prepay_id"); |
|
|
|
// update payOrder with prepay_id |
|
|
|
record.setPrepayId(prepay_id); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxPayOrderMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("pay order 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=" + 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 { |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorMap.getJSONObject(result_code); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("return_msg"); |
|
|
|
record.setFailReason(errMsg); |
|
|
|
} |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
try { |
|
|
|
wxPayOrderMapper.updateById(record); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("pay order update error: " + record.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); |
|
|
|
} |
|
|
|
} |
|
|
|
//普通商户模式 |
|
|
|
if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
WxPayOrderP wxPayOrderP = generateWxPayOrderP(payAccount,order,record,openId,appId,currentDate); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
return getOrderPResult(returnMap,record,payAccount,wxPayOrderP.getNonce_str()); |
|
|
|
|
|
|
|
} else { |
|
|
|
// 统一下单 // 服务商模式 |
|
|
|
WxPayOrderSP wxPayOrderSP = generateWxPayOrderSP(payAccount,order,record,appInfo,openId,appId,currentDate,isShare); |
|
|
|
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); |
|
|
|
log.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
return getOrderSPResult(returnMap,record,payAccount,appInfo,wxPayOrderSP.getNonce_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |