|
@@ -9,6 +9,7 @@ import com.alipay.api.domain.AlipayFundTransCommonQueryModel;
|
|
|
import com.alipay.api.domain.AlipayFundTransPagePayModel;
|
|
import com.alipay.api.domain.AlipayFundTransPagePayModel;
|
|
|
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
|
|
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
|
|
|
import com.alipay.api.domain.AlipayUserAgreementPageSignModel;
|
|
import com.alipay.api.domain.AlipayUserAgreementPageSignModel;
|
|
|
|
|
+import com.alipay.api.domain.AlipayUserAgreementQueryModel;
|
|
|
import com.alipay.api.domain.BankcardExtInfo;
|
|
import com.alipay.api.domain.BankcardExtInfo;
|
|
|
import com.alipay.api.domain.Participant;
|
|
import com.alipay.api.domain.Participant;
|
|
|
import com.alipay.api.request.AlipayFundAccountbookCreateRequest;
|
|
import com.alipay.api.request.AlipayFundAccountbookCreateRequest;
|
|
@@ -17,12 +18,14 @@ import com.alipay.api.request.AlipayFundTransCommonQueryRequest;
|
|
|
import com.alipay.api.request.AlipayFundTransPagePayRequest;
|
|
import com.alipay.api.request.AlipayFundTransPagePayRequest;
|
|
|
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
|
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
|
|
import com.alipay.api.request.AlipayUserAgreementPageSignRequest;
|
|
import com.alipay.api.request.AlipayUserAgreementPageSignRequest;
|
|
|
|
|
+import com.alipay.api.request.AlipayUserAgreementQueryRequest;
|
|
|
import com.alipay.api.response.AlipayFundAccountbookCreateResponse;
|
|
import com.alipay.api.response.AlipayFundAccountbookCreateResponse;
|
|
|
import com.alipay.api.response.AlipayFundAccountbookQueryResponse;
|
|
import com.alipay.api.response.AlipayFundAccountbookQueryResponse;
|
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
|
import com.alipay.api.response.AlipayFundTransPagePayResponse;
|
|
import com.alipay.api.response.AlipayFundTransPagePayResponse;
|
|
|
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
|
|
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
|
|
|
import com.alipay.api.response.AlipayUserAgreementPageSignResponse;
|
|
import com.alipay.api.response.AlipayUserAgreementPageSignResponse;
|
|
|
|
|
+import com.alipay.api.response.AlipayUserAgreementQueryResponse;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.payment.platform.common.exception.BusinessException;
|
|
import com.payment.platform.common.exception.BusinessException;
|
|
|
import com.payment.platform.common.utils.RedisLockUtil;
|
|
import com.payment.platform.common.utils.RedisLockUtil;
|
|
@@ -105,14 +108,17 @@ public class AlipayTransferService {
|
|
|
/**
|
|
/**
|
|
|
* alipay.user.agreement.page.sign — 页面跳转接口
|
|
* alipay.user.agreement.page.sign — 页面跳转接口
|
|
|
* 必填: personal_product_code, product_code, sign_scene, access_params
|
|
* 必填: personal_product_code, product_code, sign_scene, access_params
|
|
|
|
|
+ * 返回 sign_url + external_agreement_no(供后续 queryAgreement 反查)
|
|
|
*/
|
|
*/
|
|
|
public Map<String, String> authorizeApply(String enterpriseId) {
|
|
public Map<String, String> authorizeApply(String enterpriseId) {
|
|
|
|
|
+ // 确定性签约号,便于后续反查 — 不拼时间戳
|
|
|
|
|
+ String externalAgreementNo = enterpriseId + "_agreement";
|
|
|
try {
|
|
try {
|
|
|
AlipayUserAgreementPageSignModel model = new AlipayUserAgreementPageSignModel();
|
|
AlipayUserAgreementPageSignModel model = new AlipayUserAgreementPageSignModel();
|
|
|
model.setPersonalProductCode("GENERAL_WITHHOLDING_P");
|
|
model.setPersonalProductCode("GENERAL_WITHHOLDING_P");
|
|
|
model.setProductCode("GENERAL_WITHHOLDING");
|
|
model.setProductCode("GENERAL_WITHHOLDING");
|
|
|
model.setSignScene("DEFAULT|DEFAULT");
|
|
model.setSignScene("DEFAULT|DEFAULT");
|
|
|
- model.setExternalAgreementNo(enterpriseId + "_" + System.currentTimeMillis());
|
|
|
|
|
|
|
+ model.setExternalAgreementNo(externalAgreementNo);
|
|
|
AccessParams accessParams = new AccessParams();
|
|
AccessParams accessParams = new AccessParams();
|
|
|
accessParams.setChannel("ALIPAYAPP");
|
|
accessParams.setChannel("ALIPAYAPP");
|
|
|
model.setAccessParams(accessParams);
|
|
model.setAccessParams(accessParams);
|
|
@@ -127,12 +133,60 @@ public class AlipayTransferService {
|
|
|
throw new BusinessException(400, "申请签约失败: 无响应");
|
|
throw new BusinessException(400, "申请签约失败: 无响应");
|
|
|
|
|
|
|
|
String body = response.getBody();
|
|
String body = response.getBody();
|
|
|
- return Map.of("sign_url", body != null ? body : "");
|
|
|
|
|
|
|
+ return Map.of("sign_url", body != null ? body : "",
|
|
|
|
|
+ "external_agreement_no", externalAgreementNo);
|
|
|
} catch (AlipayApiException e) {
|
|
} catch (AlipayApiException e) {
|
|
|
throw new BusinessException(400, "申请签约失败: " + e.getMessage());
|
|
throw new BusinessException(400, "申请签约失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ==================== 1b. 查询签约结果 ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * alipay.user.agreement.query — 通过 external_agreement_no 反查签约协议号
|
|
|
|
|
+ * 用户完成签约后调用,获取支付宝侧的 agreement_no
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, String> queryAgreement(String enterpriseId, String externalAgreementNo) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ AlipayUserAgreementQueryModel model = new AlipayUserAgreementQueryModel();
|
|
|
|
|
+ model.setExternalAgreementNo(externalAgreementNo);
|
|
|
|
|
+ model.setPersonalProductCode("GENERAL_WITHHOLDING_P");
|
|
|
|
|
+ model.setSignScene("DEFAULT|DEFAULT");
|
|
|
|
|
+ model.setThirdPartyType("PARTNER");
|
|
|
|
|
+
|
|
|
|
|
+ AlipayUserAgreementQueryRequest request = new AlipayUserAgreementQueryRequest();
|
|
|
|
|
+ request.setBizModel(model);
|
|
|
|
|
+
|
|
|
|
|
+ AlipayUserAgreementQueryResponse response =
|
|
|
|
|
+ alipayClientFactory.getClient(enterpriseId).execute(request);
|
|
|
|
|
+
|
|
|
|
|
+ if (!response.isSuccess())
|
|
|
|
|
+ throw new BusinessException(400, "查询签约状态失败: " + response.getMsg());
|
|
|
|
|
+
|
|
|
|
|
+ // 写入本地 account 记录(如果有的话)
|
|
|
|
|
+ String agreementNo = response.getAgreementNo();
|
|
|
|
|
+ if (agreementNo != null && !agreementNo.isBlank()) {
|
|
|
|
|
+ var accounts = accountMapper.selectList(
|
|
|
|
|
+ new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<AccountEntity>()
|
|
|
|
|
+ .eq(AccountEntity::getEnterpriseId, enterpriseId));
|
|
|
|
|
+ for (AccountEntity acc : accounts) {
|
|
|
|
|
+ if (acc.getAgreementNo() == null || acc.getAgreementNo().isBlank()) {
|
|
|
|
|
+ acc.setAgreementNo(agreementNo);
|
|
|
|
|
+ acc.setSignStatus("SIGNED");
|
|
|
|
|
+ accountMapper.updateById(acc);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Map.of(
|
|
|
|
|
+ "agreement_no", agreementNo != null ? agreementNo : "",
|
|
|
|
|
+ "status", response.getStatus() != null ? response.getStatus() : "PENDING",
|
|
|
|
|
+ "external_agreement_no", externalAgreementNo);
|
|
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
|
|
+ return Map.of("status", "PENDING", "error", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== 2. 开通记账本 ====================
|
|
// ==================== 2. 开通记账本 ====================
|
|
|
|
|
|
|
|
/**
|
|
/**
|