构建支付宝进件参数

This commit is contained in:
gong
2026-01-07 15:01:33 +08:00
parent 74122fae45
commit f89fda0698
5 changed files with 133 additions and 9 deletions

View File

@@ -295,6 +295,8 @@ public class EntryManager {
SettlementInfoDto settlementInfo = reqDto.getSettlementInfo();
AssertUtil.isBlank(settlementInfo.getSettlementCardNo(), "结算卡号不能为空");
AssertUtil.isBlank(settlementInfo.getSettlementName(), "结算账户户名不能为空");
AssertUtil.isBlank(settlementInfo.getBankName(), "结算银行名称不能为空");
AssertUtil.isBlank(settlementInfo.getBankInstId(), "结算银行缩写不能为空");
AssertUtil.isBlank(settlementInfo.getBankMobile(), "结算银行预留手机号不能为空");
AssertUtil.isBlank(settlementInfo.getSettlementCardType(), "结算卡类型不能为空");
AssertUtil.isBlank(settlementInfo.getOpenAccProvinceId(), "结算开户行省ID不能为空");
@@ -346,8 +348,9 @@ public class EntryManager {
verifyEntryParam(merchantDto);
uploadParamImage(merchantDto);
System.out.println(merchantDto);
entryMerchant(merchantDto, PayCst.Platform.WECHAT);
// entryMerchant(merchantDto, PayCst.Platform.WECHAT, PayCst.Platform.ALIPAY);
// entryMerchant(merchantDto, PayCst.Platform.WECHAT);
// entryMerchant(merchantDto, PayCst.Platform.ALIPAY);
entryMerchant(merchantDto, PayCst.Platform.WECHAT, PayCst.Platform.ALIPAY);
}
private static AggregateMerchantDto getTestMerchantEntryData() {
@@ -420,6 +423,7 @@ public class EntryManager {
settlementInfoDto.setOpenAccCity("深圳市");
settlementInfoDto.setOpenAccArea("南山区");
settlementInfoDto.setBankName("中国工商银行");
settlementInfoDto.setBankInstId("ICBC");
settlementInfoDto.setBankType("1");
settlementInfoDto.setBankBranchName("广东省深圳市南山区");
settlementInfoDto.setBankBranchCode("440300");

View File

@@ -81,6 +81,11 @@ public class SettlementInfoDto {
*/
private String bankName;
/**
* 开户行缩写
*/
private String bankInstId;
/**
* 开户行编号
*/

View File

@@ -4,11 +4,17 @@ import com.alibaba.fastjson2.JSONArray;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.FileItem;
import com.alipay.api.domain.AlipayFinancialnetAuthPbcnameQueryModel;
import com.alipay.api.domain.AntMerchantExpandIndirectZftCreateModel;
import com.alipay.api.domain.AntMerchantExpandIndirectZftSimplecreateModel;
import com.alipay.api.domain.SiteInfo;
import com.alipay.api.request.AlipayFinancialnetAuthPbcnameQueryRequest;
import com.alipay.api.request.AntMerchantExpandIndirectImageUploadRequest;
import com.alipay.api.request.AntMerchantExpandIndirectZftCreateRequest;
import com.alipay.api.request.AntMerchantExpandIndirectZftSimplecreateRequest;
import com.alipay.api.response.AlipayFinancialnetAuthPbcnameQueryResponse;
import com.alipay.api.response.AntMerchantExpandIndirectImageUploadResponse;
import com.alipay.api.response.AntMerchantExpandIndirectZftCreateResponse;
import com.alipay.api.response.AntMerchantExpandIndirectZftSimplecreateResponse;
import com.alipay.v3.ApiClient;
import com.alipay.v3.ApiException;
import com.alipay.v3.Configuration;
@@ -17,10 +23,11 @@ import com.alipay.v3.api.AntMerchantExpandIndirectImageApi;
import com.alipay.v3.model.*;
import com.alipay.v3.util.model.AlipayConfig;
import com.czg.PayCst;
import com.czg.dto.req.AggregateMerchantDto;
import com.czg.dto.req.*;
import com.czg.dto.resp.BankBranchDto;
import com.czg.dto.resp.EntryRespDto;
import com.czg.dto.resp.EntryThirdRespDto;
import com.czg.exception.CzgException;
import com.czg.third.alipay.dto.config.AlipayConfigDto;
import com.czg.third.wechat.dto.req.entry.WechatEntryReqDto;
import com.czg.utils.UploadFileUtil;
@@ -50,12 +57,25 @@ public class AlipayEntryManager {
* @param reqDto 请求信息
*/
public static EntryThirdRespDto entryMerchant(AlipayConfigDto configDto, AggregateMerchantDto reqDto) {
AntMerchantExpandIndirectZftSimplecreateModel entryReqDto = buildEntryParams(reqDto);
AntMerchantExpandIndirectZftCreateModel entryReqDto = buildEntryParams(reqDto);
EntryThirdRespDto respDto = new EntryThirdRespDto()
.setPlatform(PayCst.Platform.ALIPAY);
try {
// entry(configDto, entryReqDto);
AntMerchantExpandIndirectZftCreateRequest request = new AntMerchantExpandIndirectZftCreateRequest();
DefaultAlipayClient defaultAlipayClient = AlipayClient.getDefaultClient(configDto);
request.setBizModel(entryReqDto);
AntMerchantExpandIndirectZftCreateResponse response = defaultAlipayClient.execute(request);
log.info("支付宝进件结果:{}", response.getBody());
if (response.isSuccess()) {
respDto.setStatus(PayCst.EntryStatus.INIT);
respDto.setEntryId(response.getOrderId());
respDto.setErrorMsg("");
} else {
respDto.setStatus(PayCst.EntryStatus.FAIL);
respDto.setEntryId("");
respDto.setErrorMsg(response.getSubMsg());
}
} catch (Exception e) {
log.error("支付宝进件报错:{}", e.getMessage(), e);
respDto.setStatus(PayCst.EntryStatus.FAIL);
@@ -135,9 +155,93 @@ public class AlipayEntryManager {
* @param reqDto 请求参数
* @return 进件参数
*/
private static AntMerchantExpandIndirectZftSimplecreateModel buildEntryParams(AggregateMerchantDto reqDto) {
AntMerchantExpandIndirectZftSimplecreateModel entryParams = new AntMerchantExpandIndirectZftSimplecreateModel();
private static AntMerchantExpandIndirectZftCreateModel buildEntryParams(AggregateMerchantDto reqDto) {
AntMerchantExpandIndirectZftCreateModel entryParams = new AntMerchantExpandIndirectZftCreateModel();
MerchantBaseInfoDto baseInfo = reqDto.getMerchantBaseInfo();
LegalPersonInfoDto legalPersonInfo = reqDto.getLegalPersonInfo();
BusinessLicenceInfoDto businessLicenceInfo = reqDto.getBusinessLicenceInfo();
StoreInfoDto storeInfo = reqDto.getStoreInfo();
SettlementInfoDto settlementInfo = reqDto.getSettlementInfo();
entryParams.setExternalId(reqDto.getMerchantCode());
if ("0".equals(baseInfo.getUserType())) {
entryParams.setMerchantType("07");
} else if ("1".equals(baseInfo.getUserType())) {
switch (baseInfo.getCompanyChildType()) {
case "1" -> entryParams.setMerchantType("01");
case "2" -> entryParams.setMerchantType("02");
case "3" -> entryParams.setMerchantType("05");
case "4" -> entryParams.setMerchantType("04");
default -> throw new CzgException("主体类型错误");
}
} else {
throw new CzgException("用户类型错误");
}
entryParams.setName(businessLicenceInfo.getLicenceName());
entryParams.setAliasName(baseInfo.getShortName());
entryParams.setMcc(baseInfo.getMccCode());
entryParams.setService(List.of("当面付", "jsapi支付", "小程序支付"));
entryParams.setInDoorImages(List.of(storeInfo.getInsidePic().getAlipayId(), storeInfo.getCashierDeskPic().getAlipayId()));
entryParams.setOutDoorImages(List.of(storeInfo.getDoorPic().getAlipayId()));
// 证件类型(目前只支持个体和企业,所以都是营业执照)
entryParams.setCertType("201");
entryParams.setCertImage(businessLicenceInfo.getLicensePic().getAlipayId());
entryParams.setCertNo(businessLicenceInfo.getLicenceNo());
entryParams.setLegalName(legalPersonInfo.getLegalPersonName());
entryParams.setLegalCertNo(legalPersonInfo.getLegalPersonId());
entryParams.setLegalCertFrontImage(legalPersonInfo.getIdCardFrontPic().getAlipayId());
entryParams.setLegalCertBackImage(legalPersonInfo.getIdCardBackPic().getAlipayId());
entryParams.setServicePhone(PayCst.ContactPersonType.LEGAL.equals(baseInfo.getContactPersonType()) ? legalPersonInfo.getLegalPersonPhone() : baseInfo.getContactPhone());
com.alipay.api.domain.AddressInfo addressInfo = new com.alipay.api.domain.AddressInfo();
addressInfo.setCityCode(storeInfo.getMercCityCode());
addressInfo.setDistrictCode(storeInfo.getMercAreaCode());
addressInfo.setProvinceCode(storeInfo.getMercProvCode());
addressInfo.setAddress(storeInfo.getBusinessAddress());
entryParams.setBusinessAddress(addressInfo);
com.alipay.api.domain.SettleCardInfo settleCardInfo = new com.alipay.api.domain.SettleCardInfo();
settleCardInfo.setAccountHolderName(settlementInfo.getSettlementName());
settleCardInfo.setAccountNo(settlementInfo.getSettlementCardNo());
settleCardInfo.setAccountInstProvince(settlementInfo.getOpenAccProvince());
settleCardInfo.setAccountInstCity(settlementInfo.getOpenAccCity());
settlementInfo.setBankBranchName(settlementInfo.getBankBranchName());
settleCardInfo.setUsageType("21".equals(settlementInfo.getSettlementCardType()) ? "01" : "02");
settleCardInfo.setAccountType("DC");
settleCardInfo.setAccountInstName(settlementInfo.getBankName());
settleCardInfo.setAccountInstId(settlementInfo.getBankInstId());
settleCardInfo.setBankCode(settlementInfo.getBankBranchCode());
entryParams.setBizCards(List.of(settleCardInfo));
com.alipay.api.domain.ContactInfo contactInfo = new com.alipay.api.domain.ContactInfo();
if (PayCst.ContactPersonType.SUPER.equals(baseInfo.getContactPersonType())) {
contactInfo.setName(baseInfo.getContactName());
contactInfo.setMobile(baseInfo.getContactPhone());
contactInfo.setEmail(baseInfo.getContactEmail());
contactInfo.setIdCardNo(baseInfo.getContactPersonId());
} else if (PayCst.ContactPersonType.LEGAL.equals(baseInfo.getContactPersonType())) {
contactInfo.setName(legalPersonInfo.getLegalPersonName());
contactInfo.setMobile(legalPersonInfo.getLegalPersonPhone());
contactInfo.setEmail(legalPersonInfo.getLegalPersonEmail());
contactInfo.setIdCardNo(legalPersonInfo.getLegalPersonId());
} else {
throw new CzgException("联系人类型错误");
}
entryParams.setContactInfos(List.of(contactInfo));
entryParams.setLicenseAuthLetterImage(businessLicenceInfo.getLicensePic().getAlipayId());
// 小程序
SiteInfo miniAppInfo = new SiteInfo();
miniAppInfo.setSiteType("06");
miniAppInfo.setSiteUrl("https://sxczgkj.cn");
miniAppInfo.setSiteName("银收客");
miniAppInfo.setTinyAppId("2021004145625815");
entryParams.setSites(List.of(miniAppInfo));
return entryParams;
}

View File

@@ -49,7 +49,16 @@ public class WechatEntryManager {
try {
String params = JSONObject.toJSONString(entryReqDto, JSONWriter.Feature.IgnoreEmpty);
String respBody = WechatReqUtils.postReq(configDto, "/v3/applyment4sub/applyment/", params);
System.out.println("调用成功:" + respBody);
JSONObject object = JSONObject.parseObject(respBody);
if (object.containsKey("applyment_id")) {
respDto.setStatus(PayCst.EntryStatus.INIT);
respDto.setEntryId(object.getString("applyment_id"));
respDto.setErrorMsg("");
} else {
respDto.setStatus(PayCst.EntryStatus.FAIL);
respDto.setEntryId("");
respDto.setErrorMsg(object.getString("message"));
}
} catch (Exception e) {
log.error("微信进件报错:{}", e.getMessage(), e);
respDto.setStatus(PayCst.EntryStatus.FAIL);

View File

@@ -1,6 +1,7 @@
package com.czg.third.wechat;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.czg.exception.CzgException;
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
@@ -62,7 +63,8 @@ public class WechatReqUtils {
.header("Wechatpay-Serial", configDto.getPublicKeyId());
default -> throw new CzgException("不支持的请求方法");
};
String s = request.execute().body();
HttpResponse response = request.execute();
String s = response.body();
log.info("微信支付请求url = {}, method: {}, body: {}, resp: {}", url, method, body, s);
return s;
}