|
|
|
@@ -30,6 +30,7 @@ import com.iformall.mapper.WxPayAccountMapper; |
|
|
|
import com.iformall.mapper.WxPayOrderMapper; |
|
|
|
import com.iformall.mapper.WxRefundOrderMapper; |
|
|
|
import com.iformall.pay.WxCashOutP; |
|
|
|
import com.iformall.pay.WxCashOutQueryP; |
|
|
|
import com.iformall.pay.WxPay; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import com.iformall.pay.WxRefundOrderP; |
|
|
|
@@ -148,7 +149,45 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
" }\n" + |
|
|
|
"}"); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject errorQueryReqMap = JSON.parseObject("{\n" + |
|
|
|
" \"CA_ERROR\": {\n" + |
|
|
|
" \"detail\": \"请求未携带证书,或请求携带的证书出错\",\n" + |
|
|
|
" \"reason\": \"请求未携带证书,或请求携带的证书出错\",\n" + |
|
|
|
" \"resolution\": \"到商户平台下载证书,请求带上证书后重试。\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"SIGN_ERROR\": {\n" + |
|
|
|
" \"detail\": \"商户签名错误\",\n" + |
|
|
|
" \"reason\": \"商户签名错误\",\n" + |
|
|
|
" \"resolution\": \"按文档要求重新生成签名后再重试。\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"FREQ_LIMIT\": {\n" + |
|
|
|
" \"detail\": \"受频率限制\",\n" + |
|
|
|
" \"reason\": \"受频率限制\\t\",\n" + |
|
|
|
" \"resolution\": \"请对请求做频率控制\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"XML_ERROR\": {\n" + |
|
|
|
" \"detail\": \"请求的xml格式错误,或者post的数据为空\",\n" + |
|
|
|
" \"reason\": \"请求的xml格式错误,或者post的数据为空\",\n" + |
|
|
|
" \"resolution\": \"检查请求串,确认无误后重试。\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"PARAM_ERROR\": {\n" + |
|
|
|
" \"detail\": \"参数错误\",\n" + |
|
|
|
" \"reason\": \"参数错误\",\n" + |
|
|
|
" \"resolution\": \"请查看err_code_des,修改设置错误的参数。\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"SYSTEMERROR\": {\n" + |
|
|
|
" \"detail\": \"系统繁忙,请再试\",\n" + |
|
|
|
" \"reason\": \"系统繁忙,请再试\\t\",\n" + |
|
|
|
" \"resolution\": \"系统繁忙\"\n" + |
|
|
|
" },\n" + |
|
|
|
" \"NOT_FOUND\": {\n" + |
|
|
|
" \"detail\": \"1、指定单号数据不存在 2、指定单号数据不存在,单据查询超过有效期\",\n" + |
|
|
|
" \"reason\": \"1、指定单号数据不存在 2、指定单号数据不存在,单据查询超过有效期\",\n" + |
|
|
|
" \"resolution\": \"1、查询单号对应的数据不存在,请使用正确的商户订单号查询2、如需查询超过有效期的单据,请登录到商户平台进行查询。\"\n" + |
|
|
|
" }\n" + |
|
|
|
"}"); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public CashOutAdapterResult cashOut(WxAppinfo appInfo, WxPayAccount payAccount, WxCashOut cashOut) { |
|
|
|
WxCashOutP wxCashOutP = generateWxCashOutP(payAccount, appInfo, cashOut); |
|
|
|
@@ -213,4 +252,63 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), errMsg, returnMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CashOutAdapterResult queryCashOut(WxAppinfo appInfo, WxPayAccount payAccount, WxCashOut cashOut) { |
|
|
|
WxCashOutQueryP wxCashOutP = generateQueryWxCashOutP(payAccount, appInfo, cashOut); |
|
|
|
Map signMap = null; |
|
|
|
try { |
|
|
|
signMap = BeanUtils.toStringMap(wxCashOutP); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("零钱支付命令生辰: " + e.getMessage(),e); |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "零钱支付签名异常"); |
|
|
|
} |
|
|
|
|
|
|
|
String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); |
|
|
|
signMap.put("sign", signAgent); |
|
|
|
String response = null; |
|
|
|
try { |
|
|
|
response = WxPay.getTransferInfo(signMap, payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("零钱支付异常: " + e.getMessage(),e); |
|
|
|
throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "零钱支付异常"); |
|
|
|
} |
|
|
|
log.info("微信零钱支付:" + wxCashOutP.toString() + ", response: " + response.toString()); |
|
|
|
return getReusltFromQueryp(response); |
|
|
|
} |
|
|
|
|
|
|
|
private WxCashOutQueryP generateQueryWxCashOutP(WxPayAccount payAccount,WxAppinfo appInfo,WxCashOut cashOut) { |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxCashOutQueryP wxCashOutQueryP = new WxCashOutQueryP(); |
|
|
|
wxCashOutQueryP.setAppid(appInfo.getAppId()); |
|
|
|
wxCashOutQueryP.setMch_id(payAccount.getSubMchId()); |
|
|
|
wxCashOutQueryP.setNonce_str(noncestr); |
|
|
|
wxCashOutQueryP.setPartner_trade_no(String.valueOf(cashOut.getId())); |
|
|
|
return wxCashOutQueryP; |
|
|
|
} |
|
|
|
|
|
|
|
private CashOutAdapterResult getReusltFromQueryp(String response) throws MallinkException{ |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String result_no = returnMap.get("result_code"); |
|
|
|
if ("SUCCESS".equals(result_no)) { |
|
|
|
String realStatus = returnMap.get("status"); |
|
|
|
if ("SUCCESS".equals(realStatus)) { |
|
|
|
return new CashOutAdapterResult(true,EnumCashOutStatus.SUCCESS.getCode(),"微信零钱支付申请成功",returnMap); |
|
|
|
}else { |
|
|
|
String msg = returnMap.get("reason"); |
|
|
|
return new CashOutAdapterResult(false,EnumCashOutStatus.SUCCESS.getCode(),msg,returnMap); |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.error("微信零钱支付查询失败: " + response); |
|
|
|
String errMsg = ""; |
|
|
|
JSONObject errObj = errorQueryReqMap.getJSONObject(result_no); |
|
|
|
if (errObj != null) { |
|
|
|
errMsg = errObj.toJSONString(); |
|
|
|
} else { |
|
|
|
errMsg = returnMap.get("err_code_des"); |
|
|
|
} |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), errMsg, returnMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |