The text as a reply to explain the case was related to Java development micro-channel public number.
First, there must be a personal micro-channel public number
Limited number of individual micro-channel public authority related to the interface, but for personal study and experience enough, as shown:
Then enter the micro-channel public background, click the basic configuration in accordance with the following operation (click enabled, to a setting request url to their background):
Setting server URL, a token, a message encryption key (this can be automatically generated using):
Server URL is critical, I'm here to set up my own domain name http://www.youcongtech.com/wx-api.
The wx-api is behind the corresponding interfaces (for example, I send a keyword, the corresponding return information).
token can set more complex.
Renderings
The above demonstrates the effect of micro-channel public number from the person, and long-term stable operation without any problems
Background routing codes
package com.blog.springboot.controller; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.blog.springboot.wx.service.WxService; import com.blog.springboot.wx.util.SignUtil; import io.swagger.annotations.Api; io.swagger.annotations.ApiOperation Import; / * * * public micro-channel number the API * @author youcong * @date 2019-6-02 * / @RestController @RequestMapping ( " / wx_public_api " ) @Api (Tags = { " micro-channel public No. API " }, Description = " micro channel number public API " ) public class WxPublicApiController the extends of AbstractController { @Autowired Private wxService wxService; / * * * public internet WeChat authentication server configured * @param Request * @param Response * / @GetMapping @ApiOperation ( " micro-channel public platform server configuration validation " ) public void the validate (Request the HttpServletRequest, HttpServletResponse the Response) { // micro-channel encrypted signature, signature combines a timestamp parameters developer token parameters and fill in the request, nonce parameters. Signature request.getParameter = String ( " Signature " ); // timestamp String = request.getParameter timestamp ( " timestamp " ); // random number String = request.getParameter the nonce ( " the nonce " ); // random string String echostr = request.getParameter ( " echostr " ); the PrintWriter OUT = null ; the try { OUT = response.getWriter (); // be verified request by checking signature, if the check is successful it is returned echostr, access failure or IF (SignUtil.checkSignature (Signature, timestamp, the nonce)) { OUT .print (echostr); } } the catch (IOException E) { e.printStackTrace (); logger.error (e.getMessage () ); } The finally { OUT .close (); OUT = null ; } } / * * * Follow push message * @param Request * @param Response * / @PostMapping @ApiOperation ( " Follow push message " ) public void About (the HttpServletRequest Request, Response the HttpServletResponse) { the try { Request.setCharacterEncoding ( " UTF-. 8 " ); } the catch(UnsupportedEncodingException E) { e.printStackTrace (); logger.error (e.getMessage (), E); } the response.setContentType ( " text / HTML; charset = UTF-. 8 " ); // call the central traffic class received message processing message String respMessage = wxService.newMessageRequest (Request); // response message to the PrintWriter OUT = null ; the try { OUT = response.getWriter (); OUT .print (respMessage); } the catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage(),e); } finally { out.close(); out = null; } } }
The complete code
The complete code has been put my personal GitHub repository, address: https://github.com/developers-youcong/blog-springcloud-pro/tree/master/blog-wx-client
This is one of the sub-project, the main function of micro-channel public platform.
In view of the open source project my personal primary maintenance were not disclosed, there are a lot of private information and so on, so will be one of the public micro-channel number of the module extracted into my new open source project blog-springcloud-pro (for this project is currently under development).
Public micro-channel number of the module substantially put his token, appid, appsecret and deployed to the basic line available. Have any questions, you can leave a message.