|
@ -5,6 +5,8 @@ import awesome.group.game.dao.bean.MatrixMoneyRecord; |
|
|
import awesome.group.game.dao.mapper.MatrixAppMapper; |
|
|
import awesome.group.game.dao.mapper.MatrixAppMapper; |
|
|
import awesome.group.game.service.bo.matrix.AliPayConfigBo; |
|
|
import awesome.group.game.service.bo.matrix.AliPayConfigBo; |
|
|
import awesome.group.game.service.citrus.UserService; |
|
|
import awesome.group.game.service.citrus.UserService; |
|
|
|
|
|
import awesome.group.game.service.common.exception.PaganiException; |
|
|
|
|
|
import awesome.group.game.service.common.exception.PaganiExceptionCode; |
|
|
import awesome.group.game.service.common.log.L; |
|
|
import awesome.group.game.service.common.log.L; |
|
|
import awesome.group.game.service.util.DateUtil; |
|
|
import awesome.group.game.service.util.DateUtil; |
|
|
import com.alipay.api.AlipayApiException; |
|
|
import com.alipay.api.AlipayApiException; |
|
@ -52,6 +54,40 @@ public class AlipayFundTransUniTransfer { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public AlipayClient initClient(MatrixApp app) { |
|
|
|
|
|
if (!StringUtils.hasText(app.getAliPay())) { |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "支付宝配置为空"); |
|
|
|
|
|
} |
|
|
|
|
|
AliPayConfigBo configBo = gson.fromJson(app.getAliPay(), AliPayConfigBo.class); |
|
|
|
|
|
CertAlipayRequest alipayConfig = getAlipayConfig(configBo); |
|
|
|
|
|
try { |
|
|
|
|
|
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig); |
|
|
|
|
|
appPayClientMap.put(app.getId(), alipayClient); |
|
|
|
|
|
} catch (AlipayApiException e) { |
|
|
|
|
|
L.trace("initAliPayClientError", "app:" + gson.toJson(app), e); |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "支付宝配置非法:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
return appPayClientMap.get(app.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void transfer(String appCode, String name, String aliAccount) { |
|
|
|
|
|
MatrixApp app = appMapper.queryByCode(appCode); |
|
|
|
|
|
AlipayClient client = initClient(app); |
|
|
|
|
|
String orderNo = System.currentTimeMillis() + ""; |
|
|
|
|
|
AlipayFundTransUniTransferRequest request = genRequest(app, orderNo, 10, name, aliAccount); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
AlipayFundTransUniTransferResponse response = client.certificateExecute(request); |
|
|
|
|
|
if (!response.isSuccess()) { |
|
|
|
|
|
String reason = response.getCode() + "," + response.getSubMsg(); |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, reason); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
L.trace("transferError", "app:" + app.getId() + "_" + app.getName(), e); |
|
|
|
|
|
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "转账失败:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//文档:https://opendocs.alipay.com/open/309/106236?pathHash=97724ae4#%E8%BD%AC%E8%B4%A6%E5%92%8C%E9%80%9A%E7%9F%A5
|
|
|
//文档:https://opendocs.alipay.com/open/309/106236?pathHash=97724ae4#%E8%BD%AC%E8%B4%A6%E5%92%8C%E9%80%9A%E7%9F%A5
|
|
|
public boolean transfer(MatrixMoneyRecord record) { |
|
|
public boolean transfer(MatrixMoneyRecord record) { |
|
|
AlipayClient alipayClient = appPayClientMap.get(record.getAppId()); |
|
|
AlipayClient alipayClient = appPayClientMap.get(record.getAppId()); |
|
@ -61,23 +97,8 @@ public class AlipayFundTransUniTransfer { |
|
|
} |
|
|
} |
|
|
MatrixApp app = appMapper.selectById(record.getAppId()); |
|
|
MatrixApp app = appMapper.selectById(record.getAppId()); |
|
|
try { |
|
|
try { |
|
|
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); |
|
|
|
|
|
AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel(); |
|
|
|
|
|
model.setOrderTitle(app.getName() + "-提现"); |
|
|
|
|
|
model.setBizScene("DIRECT_TRANSFER"); |
|
|
|
|
|
model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}"); |
|
|
|
|
|
model.setRemark(app.getName() + "-提现"); |
|
|
|
|
|
String orderNo = String.format("%08d", record.getId()); |
|
|
String orderNo = String.format("%08d", record.getId()); |
|
|
model.setOutBizNo(DateUtil.currentDate() + orderNo);//最小可传金额 0.1 元,
|
|
|
AlipayFundTransUniTransferRequest request = genRequest(app, orderNo, record.getCent(), record.getName(), record.getAliPayAccount()); |
|
|
model.setTransAmount(String.format("%.2f", record.getCent() / 100.0)); |
|
|
|
|
|
model.setProductCode("TRANS_ACCOUNT_NO_PWD"); |
|
|
|
|
|
Participant payeeInfo = new Participant(); |
|
|
|
|
|
payeeInfo.setIdentity(record.getAliPayAccount()); |
|
|
|
|
|
payeeInfo.setName(record.getName()); |
|
|
|
|
|
payeeInfo.setIdentityType("ALIPAY_LOGON_ID"); |
|
|
|
|
|
model.setPayeeInfo(payeeInfo); |
|
|
|
|
|
|
|
|
|
|
|
request.setBizModel(model); |
|
|
|
|
|
|
|
|
|
|
|
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request); |
|
|
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request); |
|
|
record.setOrderId(response.getOrderId()); |
|
|
record.setOrderId(response.getOrderId()); |
|
@ -100,6 +121,27 @@ public class AlipayFundTransUniTransfer { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AlipayFundTransUniTransferRequest genRequest(MatrixApp app, String orderId, int cent, String name, String aliAccount) { |
|
|
|
|
|
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); |
|
|
|
|
|
AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel(); |
|
|
|
|
|
model.setOrderTitle(app.getName() + "-提现"); |
|
|
|
|
|
model.setBizScene("DIRECT_TRANSFER"); |
|
|
|
|
|
model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}"); |
|
|
|
|
|
model.setRemark(app.getName() + "-提现"); |
|
|
|
|
|
model.setOutBizNo(DateUtil.currentDate() + orderId);//最小可传金额 0.1 元,
|
|
|
|
|
|
model.setTransAmount(String.format("%.2f", cent / 100.0)); |
|
|
|
|
|
model.setProductCode("TRANS_ACCOUNT_NO_PWD"); |
|
|
|
|
|
Participant payeeInfo = new Participant(); |
|
|
|
|
|
payeeInfo.setIdentity(aliAccount); |
|
|
|
|
|
payeeInfo.setName(name); |
|
|
|
|
|
payeeInfo.setIdentityType("ALIPAY_LOGON_ID"); |
|
|
|
|
|
model.setPayeeInfo(payeeInfo); |
|
|
|
|
|
|
|
|
|
|
|
request.setBizModel(model); |
|
|
|
|
|
return request; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static CertAlipayRequest getAlipayConfig(AliPayConfigBo bo) { |
|
|
private static CertAlipayRequest getAlipayConfig(AliPayConfigBo bo) { |
|
|
String privateKey = bo.aliPayPrivateKey; |
|
|
String privateKey = bo.aliPayPrivateKey; |
|
|
CertAlipayRequest alipayConfig = new CertAlipayRequest(); |
|
|
CertAlipayRequest alipayConfig = new CertAlipayRequest(); |
|
|