| @@ -97,4 +97,7 @@ alter table wx_cash_out_95 ADD COLUMN `real_name` varchar(32) COMMENT '实 | |||
| alter table wx_cash_out_96 ADD COLUMN `real_name` varchar(32) COMMENT '实名姓名,超2000需实名'; | |||
| alter table wx_cash_out_97 ADD COLUMN `real_name` varchar(32) COMMENT '实名姓名,超2000需实名'; | |||
| alter table wx_cash_out_98 ADD COLUMN `real_name` varchar(32) COMMENT '实名姓名,超2000需实名'; | |||
| alter table wx_cash_out_99 ADD COLUMN `real_name` varchar(32) COMMENT '实名姓名,超2000需实名'; | |||
| alter table wx_cash_out_99 ADD COLUMN `real_name` varchar(32) COMMENT '实名姓名,超2000需实名'; | |||
| alter table wx_pay_account add COLUMN `merchant_key_path` varchar(100) COMMENT '商户key证书路径'; | |||
| alter table wx_pay_account add COLUMN `merchant_apiv3_key` varchar(100) COMMENT '商户apiV3Key'; | |||
| @@ -30,6 +30,10 @@ public class WxPayAccount extends TenantEntity { | |||
| private String certPath; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户自己的证书",name="merchantCertPath") | |||
| private String merchantCertPath; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户自己的密钥文件",name="merchantKeyPath") | |||
| private String merchantKeyPath; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户自己的apiv3密钥",name="merchantApiv3Key") | |||
| private String merchantApiv3Key; | |||
| @io.swagger.annotations.ApiModelProperty(value="商户模式-0:普通商户模式1:服务商模式",name="type") | |||
| private Integer type; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否开启分账(0:未开启分账1:开启分账)",name="type") | |||
| @@ -56,13 +60,13 @@ public class WxPayAccount extends TenantEntity { | |||
| private String serviceId; | |||
| @io.swagger.annotations.ApiModelProperty(value="微信支付分回调地址",name="payScoreNotifyUrl") | |||
| private String payScoreNotifyUrl; | |||
| @io.swagger.annotations.ApiModelProperty(value="apiV3秘钥",name="apiV3Key") | |||
| @io.swagger.annotations.ApiModelProperty(value="平台apiV3秘钥",name="apiV3Key") | |||
| private String apiV3Key; | |||
| @io.swagger.annotations.ApiModelProperty(value="证书序列号",name="certSerialNo") | |||
| @io.swagger.annotations.ApiModelProperty(value="平台证书序列号",name="certSerialNo") | |||
| private String certSerialNo; | |||
| @io.swagger.annotations.ApiModelProperty(value="apiv3 商户apiclient_key.pem 商户私钥",name="privateKeyPath") | |||
| @io.swagger.annotations.ApiModelProperty(value="平台私钥文件",name="privateKeyPath") | |||
| private String privateKeyPath; | |||
| @io.swagger.annotations.ApiModelProperty(value="apiv3 商户apiclient_cert.pem",name="privateCertPath") | |||
| @io.swagger.annotations.ApiModelProperty(value="平台证书文件,同certPath",name="privateCertPath") | |||
| private String privateCertPath; | |||
| // @io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat") | |||
| @@ -8,9 +8,11 @@ import java.util.Map; | |||
| import javax.crypto.IllegalBlockSizeException; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.binarywang.wxpay.config.WxPayConfig; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.utils.HttpUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -204,17 +204,17 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ | |||
| @Override | |||
| public CashOutAdapterResult cashOut(WxAppinfo appInfo, WxPayAccount payAccount, WxCashOut cashOut) { | |||
| if (StringUtils.isBlank(payAccount.getPrivateCertPath())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。证书PrivateCertPath为空。请联系管理员配置。", null); | |||
| if (StringUtils.isBlank(payAccount.getMerchantCertPath())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户证书为空。请联系管理员配置。", null); | |||
| } | |||
| if (StringUtils.isBlank(payAccount.getPrivateKeyPath())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。密钥PrivateKeyPath为空。请联系管理员配置。", null); | |||
| if (StringUtils.isBlank(payAccount.getMerchantKeyPath())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户密钥为空。请联系管理员配置。", null); | |||
| } | |||
| if (StringUtils.isBlank(payAccount.getApiV3Key())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。密钥ApiV3Key为空。请联系管理员配置。", null); | |||
| if (StringUtils.isBlank(payAccount.getMerchantApiv3Key())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。商户密钥ApiV3为空。请联系管理员配置。", null); | |||
| } | |||
| WxPayService payService = maUtil.getWxPayService(appInfo,payAccount); | |||
| WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo,payAccount); | |||
| if (null == payService) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。当前小程序未查询到payService。", null); | |||
| } | |||
| @@ -279,7 +279,7 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ | |||
| if (StringUtils.isBlank(payAccount.getApiV3Key())) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。密钥ApiV3Key为空。请联系管理员配置。", null); | |||
| } | |||
| WxPayService payService = maUtil.getWxPayService(appInfo,payAccount); | |||
| WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo,payAccount); | |||
| if (null == payService) { | |||
| return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付失败。当前小程序未查询到payService。", null); | |||
| } | |||
| @@ -92,6 +92,16 @@ public class MaUtil { | |||
| } | |||
| public WxPayService getWxPayService(WxAppinfo appinfo, WxPayAccount payAccount) { | |||
| return getWxPayService(appinfo,payAccount,true); | |||
| } | |||
| //自研非服务商模式 | |||
| public WxPayService getWxPayServiceBySelfModel(WxAppinfo appinfo, WxPayAccount payAccount) { | |||
| return getWxPayService(appinfo,payAccount,false); | |||
| } | |||
| //@isService 是否服务商模式 | |||
| private WxPayService getWxPayService(WxAppinfo appinfo, WxPayAccount payAccount,boolean isService) { | |||
| WxPayConfig config = new WxPayConfig(); | |||
| config.setAppId(appinfo.getAppId()); | |||
| config.setMchId(payAccount.getMchId()); | |||
| @@ -103,20 +113,31 @@ public class MaUtil { | |||
| //以下是apiv3以及支付分相关 | |||
| // config.setServiceId(payAccount.getServiceId()); | |||
| // config.setPayScoreNotifyUrl(payAccount.getPayScoreNotifyUrl()); | |||
| //服务商,取平台的 | |||
| int iss = 0; | |||
| if (isService) { | |||
| iss = 1; | |||
| config.setPrivateKeyPath(payAccount.getPrivateKeyPath()); | |||
| config.setPrivateCertPath(payAccount.getPrivateCertPath()); | |||
| //config.setCertSerialNo(payAccount.getCertSerialNo()); | |||
| config.setApiV3Key(payAccount.getApiV3Key()); | |||
| }else { | |||
| config.setPrivateKeyPath(payAccount.getMerchantKeyPath()); | |||
| config.setPrivateCertPath(payAccount.getMerchantCertPath()); | |||
| //config.setCertSerialNo(payAccount.getCertSerialNo()); | |||
| config.setApiV3Key(payAccount.getMerchantApiv3Key()); | |||
| } | |||
| String key = new StringBuffer(appinfo.getAppId()).append("_").append(iss).toString(); | |||
| config.setPrivateKeyPath(payAccount.getPrivateKeyPath());//apiv3 商户apiclient_key.pem 商户私钥 | |||
| config.setPrivateCertPath(payAccount.getPrivateCertPath());//apiv3 商户apiclient_cert.pem | |||
| config.setCertSerialNo(payAccount.getCertSerialNo());//证书序列号 | |||
| config.setApiV3Key(payAccount.getApiV3Key());//apiV3秘钥 | |||
| WxPayService service = payServiceMap.get(appinfo.getAppId()); | |||
| WxPayService service = payServiceMap.get(key); | |||
| if ( null == service ) { | |||
| synchronized("getWxPayServiceBlock"+appinfo.getAppId()) { | |||
| service = payServiceMap.get(appinfo.getAppId()); | |||
| synchronized("getWxPayServiceBlock"+key) { | |||
| service = payServiceMap.get(key); | |||
| if (null == service) { | |||
| service = new WxPayServiceImpl(); | |||
| service.setConfig(config); | |||
| payServiceMap.put(appinfo.getAppId(), service); | |||
| payServiceMap.put(key, service); | |||
| } | |||
| } | |||
| } | |||
| @@ -10,6 +10,8 @@ | |||
| <result column="sub_app_id" jdbcType="VARCHAR" property="subAppId"/> | |||
| <result column="api_key" jdbcType="VARCHAR" property="apiKey"/> | |||
| <result column="merchant_api_key" jdbcType="VARCHAR" property="merchantApiKey"/> | |||
| <result column="merchant_key_path" jdbcType="VARCHAR" property="merchantKeyPath"/> | |||
| <result column="merchant_apiv3_key" jdbcType="VARCHAR" property="merchantApiv3Key"/> | |||
| <result column="notify_url" jdbcType="VARCHAR" property="notifyUrl"/> | |||
| <result column="notify_token" jdbcType="VARCHAR" property="notifyToken"/> | |||
| @@ -31,7 +33,7 @@ | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`mch_id`,`sub_mch_id`,`sub_app_id`,`api_key`,`merchant_api_key`,`notify_url`,`notify_token`,`cert_path`, | |||
| `merchant_cert_path`,`type`,`share`,`rate`,`real_rate`, | |||
| `service_id`,`pay_score_notify_url`,`api_v3_key`,`cert_serial_no`,`private_key_path`,`private_cert_path` | |||
| `service_id`,`pay_score_notify_url`,`api_v3_key`,`cert_serial_no`,`private_key_path`,`private_cert_path`,`merchant_key_path`,`merchant_apiv3_key` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||