Spring boot Alipay sandbox environment testing payment function

Table of contents

1. Install Alipay payment demo

2. Configure demo information

3. Configure callback address and asynchronous address

4. Intranet penetration

(1) Introduction

(2) Usage scenarios

(3) Several commonly used software for intranet penetration

(4) Use natapp


1. Install Alipay payment demo

Select the Java version. After downloading, it is an eclipse project.

Get SDK & Demo - Alipay Document Center (alipay.com)

Reference for importing ideal: Detailed explanation of the steps for importing IDEA into Eclipse project-CSDN Blog 

2. Configure demo information

Configured in AlipayConfig, the information that needs to be configured is as follows:

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
	public static String app_id = "";
	
	// 商户私钥,您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "xxx";
	
	// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "xxx";

	// 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String notify_url = "http://工程项目/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";

	// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String return_url = "http://工程项目/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

	// 签名方式
	public static String sign_type = "RSA2";
	
	// 字符编码格式
	public static String charset = "utf-8";
	
	// 支付宝网关
	public static String gatewayUrl = "";
	
	// 支付宝网关
	public static String log_path = "";

First we enter the sandbox Alipay open platform (alipay.com)

The sandbox will assign the APPID and Alipay gateway address Alipay - online payment is safe and fast! 

The log path log_path does not need to be written. Next is the merchant private key and Alipay public key. There are four keys in total. Alipay needs to know the public key of our application. The key is hidden by itself. Then we also need to know the public key of Alipay and its relationship. As shown below:

Click Custom Key in the sandbox and select public key mode to obtain the Alipay public key

Then download the Alipay key generator key tool download - Alipay Document Center (alipay.com) (fool-proof installation, at most customize the installation path). After the generation is completed, the public key must be configured in the application public key above. The application private key is configured in the code, so the callback address and asynchronous address are still needed, but the project can already be started without affecting the overall operation.

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
	public static String app_id = "9021015688664745";
	
	// 商户私钥,您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCYVu3TUNAskQBtOk3Ghqr7QCMl47SdMgsFHgDtCO0j8WuMX7c1dr6Lrn0FenJk12P2PZ72ei1pYWjNU73nshKQUttJ0ZJ8rKKclMvUCPfFQyXtwd1m9r/ZUpFzhHcvuVeKyfTKEGKsdZu1unHf2a9BC/lOeXOsa7nU0Kr+KZHoRRQRra5rXhrYDCk9xvr45gJl1eWyR3vFEBLmKlJF6B5noUgs8QkCKcO4s6tZ2W64j5E6v/CJkOUHE9fz7XdgAzOEiDwFworgty+U4Zy6oYUnGbaPit2zqTQBItB1JAoGBAJb/mZwW8Atu9uaT6ooFFgR7y9MwD2PcjugKnvf1Ll+eiRg3qMQGrNhxNRQ2jCD6rQUYgjnLgd7WFY5RYok0tQfEHP4aNK7nN0Hd150oMwTTa5c44XipM1+G2QrzBtIEKTEQbx0mL2HkFqvstONKWDhKFexMxmqJbzixygriKvzBAoGACE+3kyPXCsOCQCxmaJuJovm9dmyMgktEtrPxhFDRfsYqOc6xyKd84LgzFNNKmcuhMVI2cTphHQw0M5l2wDhOQbKSh26t2urwZIGbHSa3v2tb/dKpkXi0gu63Y7PpsNYx1ZOKuSAStz8gv5TnqoCrPFynJKFWMhW4C0VqLVsLSvg=";
	
	// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0wnAk9KNZf8hkPzI0KwEXu8ebXRgiRs8UXOd9O8LYScDHBBNTqTgexHaGJHeOXtZf8WLo6rBFfJRFedMOTcFk9S9j7arLdvqnAew7DUzE7bWl4jgPzcs5FH1CV2nCsURwrUKUvtx9cbRTCA82hDvC0uPDO6IDkj40tfYxJtL1IjIlMzfwbh4cMRXbZxo0VetjTe/BMG7JuQBokdnXpy84dGTOK8oJC/gJCOai65l57KcuSKXcG3EmlhqUZaq8HF4Rg9A7ScdSQ7Xu7bAp6XxOIkrw2VFEyA+93zEj2x6fWr3RTNsYez3Xjy1QhXoqeaZQQckolvc3huTfsT8eV2QVQIDAQAB";

	// 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String notify_url = "http://工程项目/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";

	// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String return_url = "http://工程项目/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

	// 签名方式
	public static String sign_type = "RSA2";
	
	// 字符编码格式
	public static String charset = "utf-8";
	
	// 支付宝网关
	public static String gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
	
	// 支付宝网关
	public static String log_path = "";

You can use the payment account given to us in the sandbox, and you can also recharge unlimited amounts of money yourself.

Error when starting:

Error:(1, 1) java: Illegal character: '\ufeff'

Error:(1, 10) java: requires class, interface or enum  

solve:

Error: (1, 1) java: Illegal character: '\ufeff'_Langli Xiaocaiji's Blog-CSDN Blog

 3. Configure callback address and asynchronous address

Configure it as localhost:8080? It is indeed possible, because the project runs on this machine, but what needs to be considered is that the buyer is all over the world and cannot access these two pages after payment. Why can JD.com be defended from all over the world because it has a domain name, so we A domain name is needed to map the localhost:8080 of the local machine so that the external network can access the internal network. Here is an introduction to internal network penetration.

    // Server asynchronous notification page path requires a complete path in http:// format. Custom parameters such as ?id=123 cannot be added. It must be accessible from the external network.
    public static String notify_url = "http://localhost:8080/alipay .trade.page.pay-JAVA-UTF-8/notify_url.jsp";

    // The page jump synchronization notification page path needs the complete path in http:// format. Custom parameters such as ?id=123 cannot be added. It must be accessible from the external network.
    public static String return_url = "http://localhost:8080 /alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

4. Intranet penetration

(1) Introduction

The intranet penetration function allows us to use the URL of the external network to access the host;
The normal external network needs to access our project process is:
1. Buy a server and have a fixed public IP
2. Buy a domain name and map it to the IP of the server
3. Domain names need to be registered and reviewed.

(2) Usage scenarios

1. Development and testing (WeChat, Alipay)
2. Smart Internet
3. Remote control
4. Private cloud

(3) Several commonly used software for intranet penetration

1. natapp : https://natapp.cn/ Discount code: 022B93FD ( 10 % off) [ first time use only ]
2. Peanut shell: https://www.oray.com/

(4) Use natapp

Register on the website and download the client: NATAPP - Intranet penetration domestic high-speed intranet mapping tool based on ngrok

Tutorial for beginners: NATAPP 1-minute quick graphic tutorial for beginners - NATAPP - Intranet penetration domestic high-speed intranet mapping tool based on ngrok 

Download config.ini and place it in the same directory as the client. After configuring authToken, double-click to start the exe client. The Forwarding line is the domain name -> ip: port.

Once done configure it into your code

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
	public static String app_id = "9021015688664745";
	
	// 商户私钥,您的PKCS8格式RSA2私钥
    public static String merchant_private_key = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCYVu3TUNAskQBtOk3Ghqr7QCMl47SdMgsFHgDtCO0j8WuMX7c1dr6Lrn0FenJk12P2PZ72ei1pYWjNU73nshKQUttJ0ZJ8rKKclMvUCPfFQyXtwd1m9r/ZUpFzhHcvuVeKyfTKEGKsdZu1unHf2a9BC/lOeXOsa7nU0Kr+KZHoRRQRra5rXhrYDCk9xvr45gJl1eWyR3vFEBLmKlJF6B5noUgs8QkCKcO4s6tZ2W64j5E6v/CJkOUHE9fz7XdgAzOEiDwFworgty+U4Zy6oYUnGbaPit2zqTQBItB1JAoGBAJb/mZwW8Atu9uaT6ooFFgR7y9MwD2PcjugKnvf1Ll+eiRg3qMQGrNhxNRQ2jCD6rQUYgjnLgd7WFY5RYok0tQfEHP4aNK7nN0Hd150oMwTTa5c44XipM1+G2QrzBtIEKTEQbx0mL2HkFqvstONKWDhKFexMxmqJbzixygriKvzBAoGACE+3kyPXCsOCQCxmaJuJovm9dmyMgktEtrPxhFDRfsYqOc6xyKd84LgzFNNKmcuhMVI2cTphHQw0M5l2wDhOQbKSh26t2urwZIGbHSa3v2tb/dKpkXi0gu63Y7PpsNYx1ZOKuSAStz8gv5TnqoCrPFynJKFWMhW4C0VqLVsLSvg=";
	
	// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0wnAk9KNZf8hkPzI0KwEXu8ebXRgiRs8UXOd9O8LYScDHBBNTqTgexHaGJHeOXtZf8WLo6rBFfJRFedMOTcFk9S9j7arLdvqnAew7DUzE7bWl4jgPzcs5FH1CV2nCsURwrUKUvtx9cbRTCA82hDvC0uPDO6IDkj40tfYxJtL1IjIlMzfwbh4cMRXbZxo0VetjTe/BMG7JuQBokdnXpy84dGTOK8oJC/gJCOai65l57KcuSKXcG3EmlhqUZaq8HF4Rg9A7ScdSQ7Xu7bAp6XxOIkrw2VFEyA+93zEj2x6fWr3RTNsYez3Xjy1QhXoqeaZQQckolvc3huTfsT8eV2QVQIDAQAB";

	// 服务器异步通知页面路径  需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String notify_url = "http://内网穿透域名/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";

	// 页面跳转同步通知页面路径 需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
	public static String return_url = "http://内网穿透域名/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";

	// 签名方式
	public static String sign_type = "RSA2";
	
	// 字符编码格式
	public static String charset = "utf-8";
	
	// 支付宝网关
	public static String gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
	
	// 支付宝网关
	public static String log_path = "";

Rerun and the test is over.

Guess you like

Origin blog.csdn.net/m0_62946761/article/details/133013491