Table of contents
3.1 Download and install cpolar intranet penetration
5. Configure a fixed second-level subdomain name
5.1 Reserve a second-level subdomain name
5.2 Configure the second-level subdomain name
6. Use fixed second-level subdomain names for access
1. Test environment
- Maven
- Spring boot
- Jdk 1.8
2. Local configuration
Obtain Alipay payment Java SDK. For maven projects, you can choose the maven version. Ordinary java projects can be downloaded from GitHub. Here we take maven as an example.
SDK download address: Ant Financial Open Platform-Document Center
Choose the latest SDK version
Copy the maven coordinates and import them into the spring boot project pom file
Open the development document: Mini Program Document-Alipay Document Center
This is just a separate test of the computer website payment unified collection order and payment page interface.
Write an interface to facilitate demonstration, create a get request, and write the order information in the code
//支付宝支付接口
@Controller
@RequestMapping("/pay")
public class AlipayTest {
private String serverUrl="https://openapi.alipaydev.com/gateway.do";
private String appId="2021000122601685";
private String privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCCk5evhVhZL3kaWEN4ACD+xHoTfn0RqR7aoh2esSTHeca8bV77z4KYUYXH/76uG1ufeYX8CsI68fMTTIxTcvA1F/vctjCkyAS3fjo+DTPpQ5tZpXvJjbNhwXJwrNov/44Dsy727N+b6CAmz5C6vkNipTdekUlHO+6EJmNgMo+ZgYuoEvinP/1JLST6IpcYj/QjGtG8cYStDlx6C3P2Xk7Jv//rOsMbem6bO5v7zZU4E29lVn5mZucxyPqDfRgyz2H++EaNxDRRh6cdVxwntEImpn9Tap+Jv1tTEddI7pOnXqsOwy5lOEJ6r36g48OyXWOLum2x9bxZUs/6tg96VAgMBAAECggEAN7StlqTltHuJNQ2hBe9eQSjKRJmI3y8gQc5C6ZLLNSHXzselaEQHNd6mMjarPhg6zUV8wPH/wuvbsFOcF9tmMkFmxBiyjnGwV1pjYVmafMkpwh7jWkLk9UBLPTEbKN2+wqbuq08Pjc7et2cywRXjn8SrhQ6F47dZBspgkTDQ+PTpQ4unHjUeQVz55K2VitReDZuTNWPCj2DT7UHDaItFTVtG0oNd1mVtcmeS+4Na7WS/3dusUef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58jYuViTqpBCnot+cEOnEZcfP3TxeKReAH379bHUVQOz7h3uH0eDcFmi3GjwPBB9lmcJdTI6qD/XObiWJID1e+XYzVgNKC+DXfJ2YN8NEuyRH5Zr862s3C6xd8BAYU1VW9ZfyAssQxILCOwQZ0qDOOq48GAhzDWwPG8oteJX7+lcH1TrnG01SmPiZqkHX6uUW2ye+fZkbW9qjtyujNnADIWNb/D1R2qgAcHsuOVV4hniRQIDAQAB";
//创建订单接口
@ResponseBody
@GetMapping("/create")
public String create(){
//创建连接
AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,privateKey,"json", "UTF-8",alipayPublicKey,"RSA2");
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//订单信息
JSONObject bizContent = new JSONObject();
bizContent.put("out_trade_no", "202100012260165");
bizContent.put("total_amount", 5.00);
bizContent.put("subject", "测试");
bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
request.setBizContent(bizContent.toString());
AlipayTradePagePayResponse response = null;
try {
response = alipayClient.pageExecute(request);
} catch (AlipayApiException e) {
e.printStackTrace();
}
if(response.isSuccess()){
//成功
return response.getBody();
} else {
//失败
return "调用失败";
}
}
}
Bash
Copy
Pay attention to the configuration parameters:
- The value of the serverUrl parameter:
- Value of appId parameter:
- The values of privateKey and alipayPublicKey:
After configuring the parameter values, we then start the springboot project. The tomcat configured here uses port 8080.
After the startup is successful, open the browser and access the interface address we wrote above: http://localhost:8080/pay/create . The Alipay interface appears to indicate success. If it fails, check the configured parameters!
3. Intranet penetration
The above service that calls SDK to create payment orders runs locally. The limitation is that only local projects can call the test payment interface. If you want to call it remotely, you need to expose the service to the public network.
Cpolar is an intranet penetration tool that supports http/https/tcp protocols, does not limit traffic, is simple to operate, does not require a public IP address, or a router, and can easily expose services to the public network for access.
cpolar official website: cpolar - secure intranet penetration tool
3.1 Download and install cpolar intranet penetration
Visit the cpolar official website, register an account, and download and install the cpolar client. For details, please refer to the documentation tutorial to download and install.
3.2 Create tunnel
After cpolar is successfully installed, we access the local 9200 port on the browser and log in to Cpolar's web ui interface: http://localhost:9200 .
Click Tunnel Management on the left dashboard - Create Tunnel. Since port 8080 is configured in tomcat, we need to create an http tunnel pointing to port 8080:
- Tunnel name: Customizable, be careful not to duplicate the name of an existing tunnel
- Protocol: http protocol
- Local address: 8080
- Domain name type: Choose a random domain name for free
- Region: Select China top
Click创建
Click the status of the dashboard on the left - online tunnel list. You can see that the tunnel you just created has generated a corresponding public network address, an http protocol and an https protocol (avoiding the tedious steps of configuring the SSL certificate). Copy and think about it
4. Test public network access
Open the browser and enter the copied code 公网地址+接口路径
to access. The Alipay page appears indicating that the access is successful.
5. Configure a fixed second-level subdomain name
Since the tunnel created using cpolar above uses a random public network address, the address will change within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it. This address is a fixed address and will not change randomly [ps: cpolar.cn has been filed]
Note that you need to upgrade the cpolar package to the basic package or above. [cpolar.cn has been registered]
5.1 Reserve a second-level subdomain name
Visit the Cpolar official website , log in to the cpolar official website backend, click Reserve on the left, and find the reserved second-level subdomain name:
- Region: Select China VIP
- Second-level domain name: can be customized
- Description: Notes, which can be customized
Click保留
Prompt that the subdomain name is reserved successfully, copy the reserved second-level subdomain name
5.2 Configure the second-level subdomain name
Visit http://127.0.0.1:9200/ , log in to the cpolar web UI management interface, click Tunnel Management - Tunnel List on the left dashboard, find the payment interface test tunnel, and click Edit on the right
Modify the tunnel information and configure the successfully reserved second-level subdomain name into the tunnel.
- Domain name type: Select a second-level subdomain name
- Sub Domain: Fill in the successfully reserved second-level subdomain name
Click更新
After the update, open the online tunnel list again. At this time, you can see that the tunnel has become a fixed second-level subdomain name. Copy the domain name.
6. Use fixed second-level subdomain names for access
Open the browser and enter the configuration you just configured successfully to 固定二级子域名+接口路径
access. The Alipay page appears indicating that the access is successful.
Fill in the account name and payment password to test, log in to the console with the account name and payment password to view
Select the balance of the test account to make payment. The payment password can be seen on the console.
payment successful
Reprinted from cpolar pole cloud article: Java Alipay sandbox environment payment, SDK interface remote debugging [intranet penetration]