利用java實現提現金額到支付寶賬戶的功能
實現步驟具體如下:
(學習視訊分享:java教學視訊)
1、匯入依賴
1
2
3
4
5
com.alipay.sdk
alipay-sdk-java
4.9.5.ALL
2、配置引數
3、實現方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@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開頭的,如果是用客戶手機號進行提現,就會還需要輸入客戶真實姓名。
用客戶手機號提現只是部分引數不同,程式碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
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
- 免SDK實現微信/支付寶轉賬打賞功能
- Laravel實現支付寶分賬Laravel
- 探索支付寶賬單的技術實現
- 查詢賬單功能的實現
- java支付寶支付(即時到賬)Java
- 如何利用 Redis 快速實現簽到統計功能Redis
- 支付寶實時到賬的MVC示例MVC
- 利用百度地圖實現支付寶 “到位” 功能(地圖模式)地圖模式
- 使用remix實現給合約賬戶轉賬REM
- Android實現收款成功金額的語音播報功能(Nice tone)Android
- [MySQLFAQ]系列–如何利用觸發器實現賬戶許可權審計MySql觸發器
- 支付寶截圖反饋功能實現
- ios10支付寶如何提現 ios10支付寶無法充值提現怎麼辦iOS
- Linux利用UDF庫實現Mysql提權LinuxMySql
- web3.js 互動 geth 實現轉賬餘額查詢功能WebJS
- Android 支付寶支付功能封裝實現Android封裝
- Java----【實現copy的功能】Java
- 用java實現ftp的功能JavaFTP
- 完美實現賬戶踢出時的全域性彈窗
- 金額轉換出現的BUG
- jQuery實現客戶端CheckAll功能jQuery客戶端
- Java中國銀行系統ATM機自助實現登入、開戶、存款、取款、轉賬、查詢餘額、修改預留手機號、登出賬號等功能(Ziph)Java
- SpringMVC 實現支付寶支付功能(沙箱環境)SpringMVC
- 利用jQuery實現表單驗證功能jQuery
- 利用指標實現strncmp函式功能指標函式
- 利用JS實現複製/貼上功能JS
- 如何利用~ & ^ | + 及移位運算子來實現 ! 的功能
- js利用cookie實現的計數功能程式碼JSCookie
- 利用Oracle的全文索引實現切詞功能Oracle索引
- CRM公海客戶自動分配功能的實現
- pycurl實現hadoop的客戶端功能薦Hadoop客戶端
- laravel + redis + bitmap 實現簽到功能LaravelRedis
- java 實現excel中的資料匯入到資料庫的功能JavaExcel資料庫
- WebServlet.Sqlite OkHttp實現賬戶管理系統的設計WebServletSQLiteHTTP
- Java實現評論回覆功能Java
- Java實現郵件推送功能Java
- Java Web(十一) 分頁功能的實現JavaWeb