温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何利用java实现提现金额到支付宝账户的功能

发布时间:2020-12-11 09:42:13 来源:亿速云 阅读:629 作者:小新 栏目:编程语言

小编给大家分享一下如何利用java实现提现金额到支付宝账户的功能,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

实现步骤具体如下:

1、导入依赖

<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.9.5.ALL</version>
</dependency>

2、配置参数

如何利用java实现提现金额到支付宝账户的功能

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\":\"姓名\"" +
" }");

以上是“如何利用java实现提现金额到支付宝账户的功能”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI