Under development environment, in order to dock with the micro letter backstage, need access to the public Internet URL address of the server machine (only use port 80/443). Therefore, it is necessary to map the local address to the public Internet using mapping tools.
1. NATAPP
① purchase tunnel
- Address: https://natapp.cn/
- Click After registration
登录
and purchase tunnel
| Note: free tunnel will replace the mapping address each time window starts.
- Fill 80 -port / 443 ports (micro-channel support only two port numbers)
- Then enter the tunnel just remember to buy your
authtoken
② Mapping
- download apps
- Create a new
config.ini
document reads as follows
| willauthtoken
change the value of a field as a tunnel just purchasedauthtoken
.
1 |
|
- The client programs and
config.ini
files in the same folder - Start the command line enter the folder input
natapp -authtoken=你的authtoken
to obtain the following results
Note again! ! For the tunnel for free, every time you start
natapp.exe
when mapping, mapping its external network address will change.
③ mapping test
- The construction of
Tomcat
the port number to 80 or port 443 (port number corresponding to the tunnel)
| in Spring Boot project, modify as follows:
| Other engineering modifications:
If this time access
127.0.0.1:80(或localhost:80)
and access映射外网:80
is the same effect, indicating that mapping is successful!
2. The micro-channel mode access Developer
① fill Server Configuration
- Server Address
URL
:所映射的外网地址
/工程校验代码的访问地址
.
| Such as: http://qc95we.natappfree.cc/weixinA. - Token: the developer free to fill generate a signature at the time of access authentication.
| Need to define a string called the Token, this string value corresponding to the filled information, see below in the specific check code.
② verify the validity of the server's address
- After the developer to submit information, micro-channel server sends a GET request to fill in the server address URL, GET request to bring the following four parameters.
signature Micro-channel cryptographic signature timestamp Timestamp nonce random number echostr Random string - Will need to develop token, timestamp, nonce sort these three parameters, and then splice them into strings sha1 encrypted, then the encrypted string with the micro-channel encrypted signature (Signature) were compared with two strings At the same time (the GET request may identify a server from a micro-channel) parameter returns echostr content, then access success developer.
③ specific code
I configured Servlet check code in Spring Boot project. If you do not want to test in the Spring Boot engineering, you can in other web application
web.xml
configuration Servlet own file. But different profiles, check code are the same.
- Project directory structure is as follows:
- I enclose my code
1 |
package com.example.springbootdemo.config; |
④ mapping debugging
- At this point can
映射地址/wenxinA 或 localhost:80/weixinA
access the Servlet
| Note: Because access this verification code needs to pass four parameters, so as to directly access the console quoted null pointer exception, the problem is not configured! !
- Servlet's URL will have access to micro-channel public platform to configure the server URL column
- Finally, fill in
Token
the corresponding value
| check my code, theToken
string value wenxinAAAA .
appendix
- My personal blog: messi1002.top
- If errors or doubts, please contact [email protected]