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/
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.
We need to configure the following parameters into our account, the following will explain one by one:
- app_id
- merchant_private_key
- alipay_public_key
- notify_url
- return_url
- gatewayUrl
Configuration AlipayConfig
1、免费注册蚂蚁金服开发者账号
Registered Address: https://developers.alipay.com/developmentAccess/developmentAccess.htm
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.
2、配置 app_id 和 gatewayUrl
We selected after research and development services to enter the following figure
1 at the APPID
correspondence 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
we click 生成方法
, jump to the following page.
- Available after downloading key generation tool, and mounting (not installed in the Chinese path).
- We need to select the key format and key length. Always use RSA2 i.e. key length 2048 bits.
- 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:
After generating a public key and a private key, we need to get back below the Page Setup key.
- Select the endorsement mode: Public Key
- Just copy the generated public key to 2 office can
- Save the settings
so the key is set to go up.
3、配置 alipay_public_key 和 merchant_private_key
We view the location just generate public and private key file
7. Copy the contents of the application to the public 2 Chu
content 8. The application of the private copying to 1 Chu
4、配置 notify_url 和 return_url
- 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";
- 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
and then click payment (Product Description writable not write), it will jump to the following page, we select the 登录账户付款
next need to enter a sandbox environment the user name and password to pay. Exist in a sandbox account number 卖家账号信息
and 买家账号信息
.
Enter the buyers account name and password to pay
the final payment is successful, so we've had to pay in a sandbox environment.