Java Integration (ultra-detailed explanation) Alipay payment sandbox environment

This blog to explain in SpringBoot integrated sandbox Alipay payment.沙箱是一个测试环境,可以模拟真正在线上使用支付宝支付的效果,又不会对真实财产产生影响。

Alipay official also provides us with a payment of small demo, we first downloaded.
https://docs.open.alipay.com/270/106291/
Here Insert Picture Description
Since this demo is for learning to use, and is based on the Eclipse development, so we will import it into Eclipse.
The demo is only one configuration class AlipayConfig, the rest is a JSP.
Here Insert Picture Description
We need to configure the following parameters into our account, the following will explain one by one:

  1. app_id
  2. merchant_private_key
  3. alipay_public_key
  4. notify_url
  5. return_url
  6. gatewayUrl

Configuration AlipayConfig

1、免费注册蚂蚁金服开发者账号
Registered Address: https://developers.alipay.com/developmentAccess/developmentAccess.htm
Here Insert Picture Description
after the scan code login, we need to improve the personal information, and choose the type of service (I chose the self-study developer).
After the completed jump to the following page, select R & D services, into the sandbox environment.
Here Insert Picture Description
2、配置 app_id 和 gatewayUrl
We selected after research and development services to enter the following figure
Here Insert Picture Description
1 at the APPIDcorrespondence app_id.
2 at 支付宝网关the corresponding gatewayUrl. There gateway address dev words, represents a development environment.
3 keys at the needs of our own generation, correspond alipay_public_key.

Set the key
Here Insert Picture Description
we click 生成方法, jump to the following page.
Here Insert Picture Description

  1. Available after downloading key generation tool, and mounting (not installed in the Chinese path).
  2. We need to select the key format and key length. Always use RSA2 i.e. key length 2048 bits.
  3. Click to generate the key, the tool will automatically generate an application public key (public key) and use a private key (private key), as shown below:
    Here Insert Picture Description
    After generating a public key and a private key, we need to get back below the Page Setup key.
    Here Insert Picture Description
  4. Select the endorsement mode: Public Key
  5. Just copy the generated public key to 2 office can
  6. Save the settings
    Here Insert Picture Description
    so the key is set to go up.
    Here Insert Picture Description

3、配置 alipay_public_key 和 merchant_private_key
We view the location just generate public and private key file
Here Insert Picture Description
Here Insert Picture Description
7. Copy the contents of the application to the public 2 Chu
content 8. The application of the private copying to 1 Chu
Here Insert Picture Description

4、配置 notify_url 和 return_url

  1. Asynchronous Notification Server Page path (notify_url). If you do not rename, modify IP and port number on it, I as follows:
public static String notify_url = "http://localhost:8080/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";
  1. Jump page synchronization notice Page path (return_url). If you do not rename, modify IP and port number on it, I as follows:
public static String return_url = "http://localhost:8080/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

4、支付测试
We have just started to import the demo project (environment requires: Tomcat6 and above, JDK7 and above), as shown below
Here Insert Picture Description
and then click payment (Product Description writable not write), it will jump to the following page, we select the 登录账户付款
Here Insert Picture Description
next need to enter a sandbox environment the user name and password to pay. Exist in a sandbox account number 卖家账号信息and 买家账号信息.
Here Insert Picture Description
Enter the buyers account name and password to pay
Here Insert Picture Description
the final payment is successful, so we've had to pay in a sandbox environment.
Here Insert Picture Description

Published 29 original articles · won praise 9 · views 9885

Guess you like

Origin blog.csdn.net/weixin_44176169/article/details/104553608
Recommended