@@ -55,8 +55,6 @@ public class AdapayMemberService {
@Value ( " ${adapay.jsowell.appId} " )
private String ADAPAY_APP_ID ;
// private final String CALLBACK_URL = "https://api.jsowellcloud.com/uniapp/pay/callbackAdapay";
@Value ( " ${adapay.callback} " )
private String ADAPAY_CALLBACK_URL ;
@@ -81,6 +79,11 @@ public class AdapayMemberService {
*/
public void createSettleAccount ( SettleAccountDTO dto ) throws BaseAdaPayException , BusinessException {
String bankAcctType = dto . getBankAcctType ( ) ;
// 设置wechatAppId
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
dto . setWechatAppId ( wechatAppId ) ;
if ( StringUtils . equals ( bankAcctType , Constants . ONE ) ) {
createCorpMember ( dto ) ;
} else if ( StringUtils . equals ( bankAcctType , Constants . TWO ) ) {
@@ -96,22 +99,28 @@ public class AdapayMemberService {
*/
@Transactional ( readOnly = false , propagation = Propagation . REQUIRED )
public void createMember ( SettleAccountDTO dto ) throws BaseAdaPayException , BusinessException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( dto . getWechatAppId ( ) ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
// 查询汇付会员关系
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService . selectByMerchantId ( dto . getMerchantId ( ) ) ;
if ( adapayMemberAccount ! = null ) {
log . error ( " 通过merchantId:{}, 没有 查询到结算账户配置 " , dto . getMerchantId ( ) ) ;
log . error ( " 通过merchantId:{}, 查询到结算账户配置:{} " , dto . getMerchantId ( ) , JSON . toJSONString ( adapayMemberAccount ) );
return ;
}
log . info ( " =======execute CreateMember begin======= " ) ;
Map < String , Object > memberParams = Maps . newHashMap ( ) ;
String adapayMemberId = Constants . ADAPAY_MEMBER_PREFIX + IdUtils . getMemberId ( ) ;
memberParams . put ( " member_id " , adapayMemberId ) ;
memberParams . put ( " app_id " , ADAPAY_APP_ID ) ;
memberParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
memberParams . put ( " location " , dto . getLocation ( ) ) ;
memberParams . put ( " email " , dto . getEmail ( ) ) ;
memberParams . put ( " gender " , dto . getGender ( ) ) ;
memberParams . put ( " nickname " , dto . getNickname ( ) ) ;
log . info ( " 创建用户,请求参数: " + JSON . toJSONString ( memberParams ) ) ;
Map < String , Object > member = Member . create ( memberParams ) ;
Map < String , Object > member = Member . create ( memberParams , config . getWechatAppId ( ) );
log . info ( " 创建用户,返回参数: " + JSON . toJSONString ( member ) ) ;
log . info ( " =======execute CreateMember end======= " ) ;
@@ -151,12 +160,12 @@ public class AdapayMemberService {
Map < String , Object > settleCountParams = Maps . newHashMap ( ) ;
settleCountParams . put ( " member_id " , adapayMemberId ) ;
settleCountParams . put ( " app_id " , ADAPAY_APP_ID ) ;
settleCountParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
// channel String Y 目前仅支持: bank_account( 银行卡)
settleCountParams . put ( " channel " , " bank_account " ) ;
settleCountParams . put ( " account_info " , accountInfo ) ;
log . info ( " 创建汇付结算账户param:{} " , settleCountParams ) ;
Map < String , Object > settleCount = SettleAccount . create ( settleCountParams ) ;
Map < String , Object > settleCount = SettleAccount . create ( settleCountParams , config . getWechatAppId ( ) );
log . info ( " 创建汇付结算账户result:{} " , settleCount ) ;
if ( settleCount = = null | | StringUtils . equals ( ( String ) settleCount . get ( " status " ) , " failed " ) ) {
@@ -189,7 +198,7 @@ public class AdapayMemberService {
}
// 通过merchantId获取appId
String wechatAppi d = pileMerchantInfoService . queryAppIdByMerchantId ( merchantId ) ;
String wechatAppI d = pileMerchantInfoService . queryAppIdByMerchantId ( merchantId ) ;
String adapayMemberId = adapayMemberAccount . getAdapayMemberId ( ) ;
String bankAcctType ;
@@ -199,11 +208,11 @@ public class AdapayMemberService {
if ( StringUtils . startsWith ( adapayMemberId , Constants . ADAPAY_MEMBER_PREFIX ) ) {
bankAcctType = Constants . TWO ;
// 查询个人用户
adapayMemberInfoVO = queryAdapayMemberInfo ( adapayMemberId , wechatAppi d ) ;
adapayMemberInfoVO = queryAdapayMemberInfo ( adapayMemberId , wechatAppI d ) ;
if ( adapayMemberInfoVO ! = null ) {
adapayMemberInfoVO . setMerchantId ( merchantId ) ;
}
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount ( adapayMemberId , adapayMemberAccount . getSettleAccountId ( ) ) ;
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount ( adapayMemberId , adapayMemberAccount . getSettleAccountId ( ) , wechatAppId );
if ( adapaySettleAccountVO ! = null ) {
adapaySettleAccountVO . setMerchantId ( merchantId ) ;
}
@@ -214,7 +223,7 @@ public class AdapayMemberService {
} else {
bankAcctType = Constants . ONE ;
// 查询企业用户
adapayCorpMemberVO = queryCorpAdapayMemberInfo ( adapayMemberId ) ;
adapayCorpMemberVO = queryCorpAdapayMemberInfo ( adapayMemberId , wechatAppId );
}
map . put ( " bankAcctType " , bankAcctType ) ;
@@ -229,13 +238,19 @@ public class AdapayMemberService {
* 查询汇付会员信息
*/
public AdapayMemberInfoVO queryAdapayMemberInfo ( String adapayMemberId , String wechatAppId ) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
if ( StringUtils . isBlank ( adapayMemberId ) ) {
return null ;
}
Map < String , Object > memberParams = Maps . newHashMap ( ) ;
memberParams . put ( " member_id " , adapayMemberId ) ;
memberParams . put ( " app_id " , ADAPAY_APP_ID ) ;
Map < String , Object > member = Member . query ( memberParams , w echatAppId) ;
memberParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
Map < String , Object > member = Member . query ( memberParams , config . getW echatAppId( ) );
log . info ( " ==查询个人用户,请求参数:{},返回参数:{} " , JSON . toJSONString ( memberParams ) , JSON . toJSONString ( member ) ) ;
if ( member = = null | | member . isEmpty ( ) | | ! " succeeded " . equals ( member . get ( " status " ) ) ) {
@@ -255,11 +270,17 @@ public class AdapayMemberService {
/**
* 查询企业用户信息
*/
public AdapayCorpMemberVO queryCorpAdapayMemberInfo ( String adapayMemberId ) throws BaseAdaPayException {
public AdapayCorpMemberVO queryCorpAdapayMemberInfo ( String adapayMemberId , String wechatAppId ) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
Map < String , Object > memberParams = Maps . newHashMap ( ) ;
memberParams . put ( " member_id " , adapayMemberId ) ;
memberParams . put ( " app_id " , ADAPAY_APP_ID ) ;
Map < String , Object > member = CorpMember . query ( memberParams ) ;
memberParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
Map < String , Object > member = CorpMember . query ( memberParams , config . getWechatAppId ( ) );
log . info ( " ==查询企业用户信息 param:{}, result:{} " , JSON . toJSONString ( memberParams ) , JSON . toJSONString ( member ) ) ;
if ( member = = null | | member . isEmpty ( ) | | ! " succeeded " . equals ( member . get ( " status " ) ) ) {
return null ;
@@ -294,7 +315,7 @@ public class AdapayMemberService {
JSONObject jsonObject = JSON . parseObject ( response . getSettle_accounts ( ) ) ;
String settleAccountId = jsonObject . getString ( " id " ) ;
if ( StringUtils . isNotEmpty ( settleAccountId ) ) {
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount ( adapayMemberId , settleAccountId ) ;
AdapaySettleAccountVO adapaySettleAccountVO = queryAdapaySettleAccount ( adapayMemberId , settleAccountId , config . getWechatAppId ( ) );
if ( adapaySettleAccountVO ! = null ) {
corpMemberVO . setBankCode ( adapaySettleAccountVO . getBankCode ( ) ) ;
corpMemberVO . setCardName ( adapaySettleAccountVO . getCardName ( ) ) ;
@@ -308,7 +329,13 @@ public class AdapayMemberService {
/**
* 查询汇付结算账户信息
*/
public AdapaySettleAccountVO queryAdapaySettleAccount ( String adapayMemberId , String settleAccountId ) throws BaseAdaPayException {
public AdapaySettleAccountVO queryAdapaySettleAccount ( String adapayMemberId , String settleAccountId , String wechatAppId ) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
if ( StringUtils . isBlank ( adapayMemberId ) | | StringUtils . isBlank ( settleAccountId ) ) {
return null ;
}
@@ -316,9 +343,8 @@ public class AdapayMemberService {
Map < String , Object > settleCountParams = Maps . newHashMap ( ) ;
settleCountParams . put ( " settle_account_id " , settleAccountId ) ;
settleCountParams . put ( " member_id " , adapayMemberId ) ;
settleCountParams . put ( " app_id " , ADAPAY_APP_ID ) ;
Map < String , Object > settleAccount = SettleAccount . query ( settleCountParams ) ;
settleCountParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
Map < String , Object > settleAccount = SettleAccount . query ( settleCountParams , config . getWechatAppId ( ) ) ;
log . info ( " ==查询汇付结算账户信息param:{}, result:{} " , JSON . toJSONString ( settleCountParams ) , JSON . toJSONString ( settleAccount ) ) ;
if ( settleAccount = = null | | settleAccount . isEmpty ( ) | | ! " succeeded " . equals ( settleAccount . get ( " status " ) ) ) {
@@ -349,6 +375,12 @@ public class AdapayMemberService {
* 查询汇付会员账户余额
*/
public AdapayAccountBalanceVO queryAdapayAccountBalance ( String merchantId ) throws BaseAdaPayException {
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( merchantId ) ;
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
AdapayAccountBalanceVO vo = AdapayAccountBalanceVO . builder ( ) . build ( ) ;
// 通过merchantId 查询出汇付会员id 和 结算账户id, 用来查询余额
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService . selectByMerchantId ( merchantId ) ;
@@ -360,8 +392,8 @@ public class AdapayMemberService {
Map < String , Object > queryParams = Maps . newHashMap ( ) ;
queryParams . put ( " settle_account_id " , settle_account_id ) ;
queryParams . put ( " member_id " , member_id ) ;
queryParams . put ( " app_id " , ADAPAY_APP_ID ) ;
Map < String , Object > settleCount = SettleAccount . balance ( queryParams ) ;
queryParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
Map < String , Object > settleCount = SettleAccount . balance ( queryParams , config . getWechatAppId ( ) );
if ( settleCount = = null | | settleCount . isEmpty ( ) | | ! " succeeded " . equals ( settleCount . get ( " status " ) ) ) {
return vo ;
}
@@ -381,6 +413,13 @@ public class AdapayMemberService {
* @throws BaseAdaPayException
*/
public void updateSettleAccountConfig ( UpdateAccountConfigDTO dto ) throws BaseAdaPayException {
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
// 通过merchantId 查询出汇付会员id 和 结算账户id, 用来查询余额
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService . selectByMerchantId ( dto . getMerchantId ( ) ) ;
if ( adapayMemberAccount = = null ) {
@@ -389,7 +428,7 @@ public class AdapayMemberService {
}
// 修改账户配置
Map < String , Object > params = Maps . newHashMap ( ) ;
params . put ( " app_id " , ADAPAY_APP_ID ) ;
params . put ( " app_id " , config . getAdapayAppId ( ) ) ;
params . put ( " member_id " , adapayMemberAccount . getAdapayMemberId ( ) ) ;
params . put ( " settle_account_id " , adapayMemberAccount . getSettleAccountId ( ) ) ;
if ( StringUtils . isNotBlank ( dto . getMinAmt ( ) ) ) {
@@ -409,10 +448,16 @@ public class AdapayMemberService {
* 创建企业用户
*/
public void createCorpMember ( SettleAccountDTO dto ) throws BaseAdaPayException , BusinessException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( dto . getWechatAppId ( ) ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
Map < String , Object > memberParams = Maps . newHashMap ( ) ;
String adapayMemberId = Constants . ADAPAY_CORP_MEMBER_PREFIX + IdUtils . getMemberId ( ) ;
memberParams . put ( " member_id " , adapayMemberId ) ;
memberParams . put ( " app_id " , ADAPAY_APP_ID ) ;
memberParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
memberParams . put ( " order_no " , " jsdk_order " + System . currentTimeMillis ( ) ) ;
memberParams . put ( " social_credit_code_expires " , dto . getSocialCreditCodeExpires ( ) ) ;
memberParams . put ( " business_scope " , dto . getBusinessScope ( ) ) ;
@@ -434,7 +479,7 @@ public class AdapayMemberService {
memberParams . put ( " card_name " , dto . getCardName ( ) ) ;
memberParams . put ( " notify_url " , ADAPAY_CALLBACK_URL ) ;
File file = ZipUtil . createZipFileFromImages ( dto . getImgList ( ) ) ;
Map < String , Object > member = CorpMember . create ( memberParams , file ) ;
Map < String , Object > member = CorpMember . create ( memberParams , file , config . getWechatAppId ( ) );
log . info ( " 创建企业账户param:{}, result:{} " , JSON . toJSONString ( memberParams ) , JSON . toJSONString ( member ) ) ;
if ( StringUtils . equals ( ( String ) member . get ( " status " ) , " failed " ) ) {
throw new BusinessException ( " " , ( String ) member . get ( " error_msg " ) ) ;
@@ -464,6 +509,12 @@ public class AdapayMemberService {
* @throws BaseAdaPayException
*/
public void drawCash ( WithdrawDTO dto ) throws BaseAdaPayException {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( dto . getWechatAppId ( ) ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
// 查询余额
AdapayAccountBalanceVO adapayAccountBalanceVO = queryAdapayAccountBalance ( dto . getMerchantId ( ) ) ;
if ( adapayAccountBalanceVO = = null ) {
@@ -486,11 +537,11 @@ public class AdapayMemberService {
settleCountParams . put ( " order_no " , " drawcash_ " + System . currentTimeMillis ( ) ) ;
settleCountParams . put ( " cash_amt " , AdapayUtil . formatAmount ( cashAmt ) ) ;
settleCountParams . put ( " member_id " , adapayAccountBalanceVO . getAdapayMemberId ( ) ) ;
settleCountParams . put ( " app_id " , ADAPAY_APP_ID ) ;
settleCountParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
settleCountParams . put ( " settle_account_id " , adapayAccountBalanceVO . getSettleAccountId ( ) ) ;
settleCountParams . put ( " cash_type " , " T1 " ) ;
settleCountParams . put ( " notify_url " , ADAPAY_CALLBACK_URL ) ;
Map < String , Object > settleCount = Drawcash . create ( settleCountParams ) ;
Map < String , Object > settleCount = Drawcash . create ( settleCountParams , config . getWechatAppId ( ) );
log . info ( " 申请取现接口,请求参数:{}, 返回参数:{} " , JSON . toJSONString ( settleCountParams ) , JSON . toJSONString ( settleCount ) ) ;
if ( settleCount = = null ) {
@@ -500,7 +551,7 @@ public class AdapayMemberService {
String id = ( String ) settleCount . get ( " id " ) ;
// 发起支付手续费请求 inMemberId为0表示本商户
createBalancePaymentRequest ( adapayAccountBalanceVO . getAdapayMemberId ( ) , Constants . ZERO , feeAmt . toString ( ) , " 提现手续费 " , " 提现单号: " + id ) ;
createBalancePaymentRequest ( adapayAccountBalanceVO . getAdapayMemberId ( ) , Constants . ZERO , feeAmt . toString ( ) , " 提现手续费 " , " 提现单号: " + id , config . getWechatAppId ( ) );
// 保存提现记录
ClearingWithdrawInfo record = new ClearingWithdrawInfo ( ) ;
@@ -528,6 +579,13 @@ public class AdapayMemberService {
* @throws BaseAdaPayException
*/
public Map < String , Object > updateAdapayMember ( SettleAccountDTO dto ) throws BaseAdaPayException {
String wechatAppId = pileMerchantInfoService . queryAppIdByMerchantId ( dto . getMerchantId ( ) ) ;
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService . selectByMerchantId ( dto . getMerchantId ( ) ) ;
if ( adapayMemberAccount = = null ) {
log . error ( " 通过merchantId:{}, 没有查询到结算账户配置 " , dto . getMerchantId ( ) ) ;
@@ -537,7 +595,7 @@ public class AdapayMemberService {
Map < String , Object > memberParams = Maps . newHashMap ( ) ;
memberParams . put ( " adapay_func_code " , " corp_members.update " ) ;
memberParams . put ( " member_id " , adapayMemberAccount . getAdapayMemberId ( ) ) ;
memberParams . put ( " app_id " , ADAPAY_APP_ID ) ;
memberParams . put ( " app_id " , config . getAdapayAppId ( ) ) ;
memberParams . put ( " order_no " , " jsdk_order_ " + System . currentTimeMillis ( ) ) ;
memberParams . put ( " social_credit_code_expires " , dto . getSocialCreditCodeExpires ( ) ) ;
memberParams . put ( " business_scope " , dto . getBusinessScope ( ) ) ;
@@ -553,7 +611,7 @@ public class AdapayMemberService {
memberParams . put ( " telphone " , dto . getTelphone ( ) ) ;
memberParams . put ( " email " , dto . getEmail ( ) ) ;
File file = ZipUtil . createZipFileFromImages ( dto . getImgList ( ) ) ;
Map < String , Object > member = AdapayCommon . requestAdapayFile ( memberParams , file ) ;
Map < String , Object > member = AdapayCommon . requestAdapayFile ( memberParams , file , config . getWechatAppId ( ) );
log . info ( " 更新企业账户param:{}, result:{} " , JSON . toJSONString ( memberParams ) , JSON . toJSONString ( member ) ) ;
if ( AdapayStatusEnum . FAILED . getValue ( ) . equals ( ( String ) member . get ( " status " ) ) ) {
throw new BusinessException ( " " , ( String ) member . get ( " error_msg " ) ) ;
@@ -611,9 +669,15 @@ public class AdapayMemberService {
* @param title 标题
* @param desc 描述信息
*/
public BalancePaymentResponse createBalancePaymentRequest ( String outMemberId , String inMemberId , String transAmt , String title , String desc ) {
public BalancePaymentResponse createBalancePaymentRequest ( String outMemberId , String inMemberId , String transAmt , String title , String desc , String wechatAppId ) {
// 获取汇付支付配置
AbstractAdapayConfig config = AdapayConfigFactory . getConfig ( wechatAppId ) ;
if ( config = = null ) {
throw new BusinessException ( ReturnCodeEnum . CODE_ADAPAY_CONFIG_IS_NULL_ERROR ) ;
}
Map < String , Object > balanceParam = Maps . newHashMap ( ) ;
balanceParam . put ( " app_id " , ADAPAY_APP_ID ) ;
balanceParam . put ( " app_id " , config . getAdapayAppId ( ) ) ;
balanceParam . put ( " adapay_func_code " , " settle_accounts.balancePay " ) ;
balanceParam . put ( " order_no " , IdUtils . fastSimpleUUID ( ) ) ;
balanceParam . put ( " out_member_id " , outMemberId ) ;
@@ -623,7 +687,7 @@ public class AdapayMemberService {
balanceParam . put ( " goods_desc " , desc ) ;
Map < String , Object > paymentResult = null ;
try {
paymentResult = AdapayCommon . requestAdapay ( balanceParam ) ;
paymentResult = AdapayCommon . requestAdapay ( balanceParam , config . getWechatAppId ( ) );
} catch ( BaseAdaPayException e ) {
log . error ( " 创建余额支付请求error " , e ) ;
}