首頁> Java> Java入門> 主體

利用java實現提現金額到支付寶帳戶的功能

王林
發布: 2020-12-10 16:21:39
轉載
3782 人瀏覽過

利用java實現提現金額到支付寶帳戶的功能

實作步驟具體如下:

(學習影片分享: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實現提現金額到支付寶帳戶的功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:csdn.net
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!