java提现功能开发_利用java实现提现金额到支付宝账户的功能

本文介绍了如何使用Java实现从企业账户向支付宝账户转账的功能。首先需要导入支付宝SDK,然后配置相关参数,如AppId、私钥等。接着,通过AlipayClient执行转账请求,并根据响应结果判断转账是否成功。在实际操作中,需先获取支付宝会员id,如果使用手机号提现,还需提供姓名信息。
摘要由CSDN通过智能技术生成

11500662d1b30f690823277f6561031e.png

实现步骤具体如下:

(学习视频分享:java教学视频)

1、导入依赖

com.alipay.sdk

alipay-sdk-java

4.9.5.ALL

2、配置参数

3e4c0c4753ed8f6794109d62f0c1de5c.png

3、实现方法@ApiOperation(value = "企业转账到支付宝", httpMethod = "POST", produces = "application/json;charset=UTF-8")

@ApiImplicitParams(value = {@ApiImplicitParam(value = "*用户token", name = "token",defaultValue ="", dataType = "String",paramType="header"),

@ApiImplicitParam(value = "支付宝会员id", name = "aliuserId",defaultValue ="", dataType = "int",paramType="query",example = "0"),

@ApiImplicitParam(value = "金额", name = "money",defaultValue ="", dataType = "String",paramType="query")

})

@PostMapping("/alipay/transfer")

public Result getMoney(HttpServletRequest servletRequest,BigDecimal money,@NotNull(message = "支付宝会员id不能为空")String aliuserId){

try {

String out_biz_no = "R-" + System.currentTimeMillis() + ((long) ((Math.random() * 9 + 1) * 100000000L) + "").substring(0, 8);

//构造client

CertAlipayRequest certAlipayRequest = new CertAlipayRequest();

//设置网关地址https://openapi.alipay.com/gateway.do

certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");

//设置应用AppId

certAlipayRequest.setAppId(appid);

//设置应用私钥

certAlipayRequest.setPrivateKey(zzpri);

certAlipayRequest.setFormat("json");

//设置字符集

certAlipayRequest.setCharset("UTF-8");

//设置签名类型

certAlipayRequest.setSignType("RSA2");

//设置应用公钥证书路径

certAlipayRequest.setCertPath(appcertpath);

//设置支付宝公钥证书路径

certAlipayRequest.setAlipayPublicCertPath(alicertpath);

//设置支付宝根证书路径

certAlipayRequest.setRootCertPath(rootcertpath);

//构造Client

AlipayClient alipayClient = null;

try {

alipayClient = new DefaultAlipayClient(certAlipayRequest);

} catch (AlipayApiException e) {

e.printStackTrace();

}

//实例化接口

AlipayFundTransUniTransferRequest request=new AlipayFundTransUniTransferRequest();

request.setBizContent("{" +

"\"out_biz_no\":\""+out_biz_no+"\"," +

"\"trans_amount\":\""+money+"\"," +

"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +

"\"biz_scene\":\"DIRECT_TRANSFER\"," +

"\"order_title\":\"转账\"," +

"\"payee_info\":{" +

"\"identity\":\""+aliuserId+"\"," +

"\"identity_type\":\"ALIPAY_USER_ID\"," +

" }," +

"\"remark\":\"单笔转账\"" +

" }");

AlipayFundTransUniTransferResponse response=null;

response = alipayClient.certificateExecute(request);

if (response.isSuccess()){

if("10000".equals(response.getCode())){

return Result.ok("转账成功");

} else {

return Result.fail(Integer.valueOf(response.getCode()),response.getSubMsg());

}

}else {

return Result.fail(Integer.valueOf(response.getCode()),response.getSubMsg());

}

}catch (Exception e){

e.printStackTrace();

return Result.error(901,"支付宝转账失败!");

}

}

注意:该功能实现需要先实现支付宝授权功能获取支付宝会员id,支付宝会员id是由2088开头的,如果是用客户手机号进行提现,就会还需要输入客户真实姓名。

用客户手机号提现只是部分参数不同,代码如下:request.setBizContent("{" +

"\"out_biz_no\":\""+out_biz_no+"\"," +

"\"trans_amount\":\""+money+"\"," +

"\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," +

"\"biz_scene\":\"DIRECT_TRANSFER\"," +

"\"order_title\":\"转账\"," +

"\"payee_info\":{" +

"\"identity\":\""+aliuserId+"\"," +

"\"identity_type\":\"ALIPAY_USER_ID\"," +

"\"name\":\"ALIPAY_USER_ID\"" +

" }," +

"\"remark\":\"姓名\"" +

" }");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值