实现步骤具体如下:
(学习视频分享:java教学视频)
1、导入依赖
登录后复制com.alipay.sdk alipay-sdk-java 4.9.5.ALL
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入门教程
以上就是利用java实现提现金额到支付宝账户的功能的详细内容,更多请关注慧达安全导航其它相关文章!
免责 声明
1、本网站名称:慧达安全导航
2、本站永久网址:https//www.huida178.com/
3、本站所有资源来源于网友投稿和高价购买,所有资源仅对编程人员及源代码爱好者开放下载做参考和研究及学习,本站不提供任何技术服务!
4、本站所有资源的属示图片和信息不代表本站的立场!本站只是储蓄平台及搬运
5、下载者禁止在服务器和虚拟机下进行搭建运营,本站所有资源不支持联网运行!只允许调试,参考和研究!!!!
6、未经原版权作者许可禁止用于任何商业环境,任何人不得擅作它用,下载者不得用于违反国家法律,否则发生的一切法律后果自行承担!
7、为尊重作者版权,请在下载24小时内删除!请购买原版授权作品,支持你喜欢的作者,谢谢!
8.若资源侵犯了您的合法权益,请持 您的版权证书和相关原作品信息来信通知我们!QQ:1247526623我们会及时删除,给您带来的不便,我们深表歉意!
9、如下载链接失效、广告或者压缩包问题请联系站长处理
10、如果你也有好源码或者教程,可以发布到网站,分享有金币奖励和额外收入!
11、本站资源售价只是赞助,收取费用仅维持本站的日常运营所需
12、因源码具有可复制性,一经赞助,不得以任何形式退款。
13、本文内容由网友自发贡献和站长收集,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系1247526623@qq.com
转载请注明出处: 慧达安全导航 » 利用java实现提现金额到支付宝账户的功能
发表评论 取消回复