Home Java Javagetting Started Use Java to realize the function of withdrawing cash to Alipay account

Use Java to realize the function of withdrawing cash to Alipay account

Dec 10, 2020 pm 04:21 PM
java Alipay

Use Java to realize the function of withdrawing cash to Alipay account

The implementation steps are as follows:

(Learning video sharing: java teaching video)

1. Import dependencies

1

2

3

4

5

<dependency>

<groupId>com.alipay.sdk</groupId>

<artifactId>alipay-sdk-java</artifactId>

<version>4.9.5.ALL</version>

</dependency>

Copy after login

2. Configuration parameters

Use Java to realize the function of withdrawing cash to Alipay account

3. Implementation method

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,"支付宝转账失败!");

}

}

Copy after login

Note: This function requires Alipay to be implemented first The authorization function obtains the Alipay member ID. The Alipay member ID starts with 2088. If you use the customer's mobile phone number to withdraw cash, you will also need to enter the customer's real name.

Only some parameters are different when using the customer’s mobile phone number. The code is as follows:

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

" }");

Copy after login

Related recommendations: java introductory tutorial

The above is the detailed content of Use Java to realize the function of withdrawing cash to Alipay account. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

How to solve the problem of 'Undefined array key 'sign'' error when calling Alipay EasySDK using PHP? How to solve the problem of 'Undefined array key 'sign'' error when calling Alipay EasySDK using PHP? Mar 31, 2025 pm 11:51 PM

Problem Description When calling Alipay EasySDK using PHP, after filling in the parameters according to the official code, an error message was reported during operation: "Undefined...

List of handling fees for okx trading platform List of handling fees for okx trading platform Feb 15, 2025 pm 03:09 PM

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

Ouyi Exchange app domestic download tutorial Ouyi Exchange app domestic download tutorial Mar 21, 2025 pm 05:42 PM

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

How to Run Your First Spring Boot Application in Spring Tool Suite? How to Run Your First Spring Boot Application in Spring Tool Suite? Feb 07, 2025 pm 12:11 PM

Spring Boot simplifies the creation of robust, scalable, and production-ready Java applications, revolutionizing Java development. Its "convention over configuration" approach, inherent to the Spring ecosystem, minimizes manual setup, allo

Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Sesame Open Door Login Registration Entrance gate.io Exchange Registration Official Website Entrance Mar 04, 2025 pm 04:51 PM

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

See all articles