|
|
|
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.binarywang.wxpay.service.WxPayService; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
@@ -19,6 +20,8 @@ import com.iformall.domain.po.WxCashOut; |
|
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
|
import com.iformall.domain.po.WxPayOrder; |
|
|
|
import com.iformall.domain.po.WxRefundOrder; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.enums.EnumAppPlat; |
|
|
|
import com.iformall.enums.EnumCashOutStatus; |
|
|
|
import com.iformall.enums.EnumPayMode; |
|
|
|
import com.iformall.enums.EnumPayType; |
|
|
|
@@ -35,6 +38,7 @@ import com.iformall.pay.WxPay; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import com.iformall.pay.WxRefundOrderP; |
|
|
|
import com.iformall.pay.WxRefundOrderSP; |
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
|
import com.iformall.service.pay.service.cashout.CashOutAdapterService; |
|
|
|
import com.iformall.service.pay.service.cashout.entity.CashOutAdapterResult; |
|
|
|
import com.iformall.service.pay.service.refund.RefundPayAdapterService; |
|
|
|
@@ -42,6 +46,7 @@ import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; |
|
|
|
import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; |
|
|
|
import com.iformall.utils.BeanUtils; |
|
|
|
import com.iformall.utils.CipherUtil; |
|
|
|
import com.iformall.utils.MaUtil; |
|
|
|
import com.iformall.utils.Utility; |
|
|
|
import com.iformall.utils.XmlUtil; |
|
|
|
|
|
|
|
@@ -50,6 +55,12 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
MaUtil maUtil; |
|
|
|
|
|
|
|
JSONObject errorRefundReqMap = JSON.parseObject("{\n" + |
|
|
|
" \"NO_AUTH\": {\n" + |
|
|
|
@@ -187,11 +198,6 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
" }\n" + |
|
|
|
"}"); |
|
|
|
|
|
|
|
/** |
|
|
|
* https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 |
|
|
|
* |
|
|
|
* 在wx_pay_account里面要设置merchant_cert_path,登陆特约商户的商户后台,账号中心-API安全。 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public CashOutAdapterResult cashOut(WxAppinfo appInfo, WxPayAccount payAccount, WxCashOut cashOut) { |
|
|
|
if (StringUtils.isBlank(payAccount.getMerchantCertPath())) { |
|
|
|
@@ -200,25 +206,23 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
if (StringUtils.isBlank(payAccount.getMerchantApiKey())) { |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户密钥为空。请联系管理员配置。", null); |
|
|
|
} |
|
|
|
WxCashOutP wxCashOutP = generateWxCashOutP(payAccount, appInfo, cashOut); |
|
|
|
Map signMap = null; |
|
|
|
try { |
|
|
|
signMap = BeanUtils.toStringMap(wxCashOutP); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("零钱支付命令生辰: " + e.getMessage(),e); |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付签名异常", null); |
|
|
|
} |
|
|
|
|
|
|
|
String signAgent = WxPayment.createSign(signMap, payAccount.getMerchantApiKey()); |
|
|
|
signMap.put("sign", signAgent); |
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(payAccount, EnumAppPlat.WX); |
|
|
|
if(cAppInfo == null){ |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。当前商场未查询到微信C端小程序配置。", null); |
|
|
|
} |
|
|
|
WxPayService payService = maUtil.getWxPayService(cAppInfo,payAccount); |
|
|
|
if (null == payService) { |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。当前小程序未查询到payService。", null); |
|
|
|
} |
|
|
|
String response = null; |
|
|
|
try { |
|
|
|
response = WxPay.merchantTranferChange(signMap, payAccount.getMerchantCertPath(), payAccount.getSubMchId()); |
|
|
|
response = WxPay.merchantTranferChange(payService,""); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("零钱支付异常: " + e.getMessage(),e); |
|
|
|
return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "微信零钱支付接口调用异常", null); |
|
|
|
} |
|
|
|
log.info("微信零钱支付:" + wxCashOutP.toString() +", response: " + response.toString()); |
|
|
|
//log.info("微信零钱支付:" + wxCashOutP.toString() +", response: " + response.toString()); |
|
|
|
return getReusltFromp(response,cashOut); |
|
|
|
|
|
|
|
// if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
@@ -226,6 +230,46 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
// /** |
|
|
|
// * https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 |
|
|
|
// * |
|
|
|
// * 在wx_pay_account里面要设置merchant_cert_path,登陆特约商户的商户后台,账号中心-API安全。 |
|
|
|
// */ |
|
|
|
// @Deprecated |
|
|
|
// @Override |
|
|
|
// public CashOutAdapterResult cashOut(WxAppinfo appInfo, WxPayAccount payAccount, WxCashOut cashOut) { |
|
|
|
// if (StringUtils.isBlank(payAccount.getMerchantCertPath())) { |
|
|
|
// return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户证书为空。请联系管理员配置。", null); |
|
|
|
// } |
|
|
|
// if (StringUtils.isBlank(payAccount.getMerchantApiKey())) { |
|
|
|
// return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户密钥为空。请联系管理员配置。", null); |
|
|
|
// } |
|
|
|
// WxCashOutP wxCashOutP = generateWxCashOutP(payAccount, appInfo, cashOut); |
|
|
|
// Map signMap = null; |
|
|
|
// try { |
|
|
|
// signMap = BeanUtils.toStringMap(wxCashOutP); |
|
|
|
// } catch (Exception e) { |
|
|
|
// log.error("零钱支付命令生辰: " + e.getMessage(),e); |
|
|
|
// return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付签名异常", null); |
|
|
|
// } |
|
|
|
// |
|
|
|
// String signAgent = WxPayment.createSign(signMap, payAccount.getMerchantApiKey()); |
|
|
|
// signMap.put("sign", signAgent); |
|
|
|
// String response = null; |
|
|
|
// try { |
|
|
|
// response = WxPay.merchantTranferChange(signMap, payAccount.getMerchantCertPath(), payAccount.getSubMchId()); |
|
|
|
// } catch (Exception e) { |
|
|
|
// log.error("零钱支付异常: " + e.getMessage(),e); |
|
|
|
// return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "微信零钱支付接口调用异常", null); |
|
|
|
// } |
|
|
|
// log.info("微信零钱支付:" + wxCashOutP.toString() +", response: " + response.toString()); |
|
|
|
// return getReusltFromp(response,cashOut); |
|
|
|
// |
|
|
|
//// if (payAccount.getType() == EnumPayMode.MCH.getCode()) { |
|
|
|
// // 普通商户模式 |
|
|
|
//// } |
|
|
|
// } |
|
|
|
|
|
|
|
private WxCashOutP generateWxCashOutP(WxPayAccount payAccount,WxAppinfo appInfo,WxCashOut cashOut) { |
|
|
|
String noncestr = Utility.generate32UUID(); |
|
|
|
WxCashOutP wxCashOutP = new WxCashOutP(); |
|
|
|
|