您好,登錄后才能下訂單哦!
小編給大家分享一下如何利用java實現提現金額到支付寶賬戶的功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
實現步驟具體如下:
1、導入依賴
<dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>4.9.5.ALL</version> </dependency>
2、配置參數
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實現提現金額到支付寶賬戶的功能”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。