说通俗一点就是app商家支付宝转账到用户支付宝上面,来直接上法力。
我写在测试类里面了,你们用的时候改成Controller即可,再把参数改成自己的ok
package WxTest;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;
/*
* ran
* 用户在app提现功能
* 从商家扣款,转账到用户支付宝账户上
* */
public class AlipayFundTransUniTransfer {
public static void main(String[] args) throws AlipayApiException {
// 初始化SDK
String privateKey = "<-- 请填写您的应用私钥,例如:MIIEvQIBADANB ... ... -->";
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setPrivateKey(privateKey);
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
alipayConfig.setAppId("<-- 请填写您的AppId,例如:2019091767145019 -->");
alipayConfig.setCharset("UTF-8");
alipayConfig.setSignType("RSA2");
alipayConfig.setFormat("json");
alipayConfig.setAppCertPath("<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->");
alipayConfig.setAlipayPublicCertPath("<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->");
alipayConfig.setRootCertPath("<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt -->");
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
// 构造请求参数以调用接口
AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
// 设置商家侧唯一订单号
model.setOutBizNo("201806300001");
// 设置订单总金额
model.setTransAmount("23.00");
// 设置描述特定的业务场景
model.setBizScene("DIRECT_TRANSFER");
// 设置业务产品码
model.setProductCode("TRANS_ACCOUNT_NO_PWD");
// 设置转账业务的标题
model.setOrderTitle("201905代发");
// 设置收款方信息
Participant payeeInfo = new Participant();
payeeInfo.setCertType("IDENTITY_CARD");
payeeInfo.setCertNo("1201152******72917");
payeeInfo.setIdentity("2088123412341234");
payeeInfo.setName("黄龙国际有限公司");
payeeInfo.setIdentityType("ALIPAY_USER_ID");
model.setPayeeInfo(payeeInfo);
// 设置业务备注
model.setRemark("201905代发");
// 设置转账业务请求的扩展参数
model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
request.setBizModel(model);
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
System.out.println(response.getBody());
if (response.isSuccess()) {
System.out.println("调用成功");
} else {
System.out.println("调用失败");
// sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
// String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
// System.out.println(diagnosisUrl);
}
}
}