WeChat public account local development and debugging

WeChat public account certification local development and debugging

Log in to WeChat public platformhttps://mp.weixin.qq.com/ Configure basic configuration
Insert image description here
Since you need to debug locally, WeChat will notify you, which is the callback address URL, then our Natapp will come in handy
Natapp address:https:/ /natapp.cn/
How to use it? The official gave a detailed tutorial [NATAPP 1-minute quick novice graphic tutorial] (https://natapp.cn/article/natapp_newbie)
Insert image description here
You will get a domain name and domain name mapping
See here for the mapping configuration
Insert image description here
Note: If the local service The port is not the Natapp configuration port, so use nginx as a proxy
Insert image description here
Insert image description here

Test whether the domain name is available and start the local service. Replace 127.0.0.1 with this domain name. If successful, you will be closer to the goal.

Background callback interface

@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/wx/portal/{appid}")
public class WxPortalController {
    
    
    private final WxMpService wxService;
    private final WxMpMessageRouter messageRouter;

    @GetMapping(produces = "text/plain;charset=utf-8")
    public String authGet(@PathVariable String appid,
                          @RequestParam(name = "signature", required = false) String signature,
                          @RequestParam(name = "timestamp", required = false) String timestamp,
                          @RequestParam(name = "nonce", required = false) String nonce,
                          @RequestParam(name = "echostr", required = false) String echostr) {
    
    

        log.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature,
            timestamp, nonce, echostr);
        if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
    
    
            throw new IllegalArgumentException("请求参数非法,请核实!");
        }

        if (!this.wxService.switchover(appid)) {
    
    
            throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
        }

        if (wxService.checkSignature(timestamp, nonce, signature)) {
    
    
            return echostr;
        }

        return "非法请求";
    }
  }

Interface correspondence
Insert image description here
Submit the configuration after the public account is configured. If there is no problem with the background service, the authentication will be successful. Then you can locally debug the public account following, unblocking, messages, etc. Function

The backend project blogger uses a third party

https://github.com/binarywang
Insert image description here
Successful screenshot
Insert image description here
Insert image description here

Finally, I wish my friends smooth debugging.

Guess you like

Origin blog.csdn.net/hsadfdsahfdsgfds/article/details/130748470