微信公众号本地开发调试

微信公众号认证本地开发调试

登录微信公众平台 https://mp.weixin.qq.com/ 配置 基础配置
在这里插入图片描述
既然要本地调试,微信要通知你,也就是回调地址 URL,那我们的 Natapp 就派上用处了
Natapp 地址:https://natapp.cn/
怎么用呢,官方给了详细的教程 [NATAPP1分钟快速新手图文教程] (https://natapp.cn/article/natapp_newbie)
在这里插入图片描述
你将会得到一个域名跟域名映射
映射配置看这里
在这里插入图片描述
注意:如果本地服务端口不是Natapp配置端口那么用nginx代理一下
在这里插入图片描述
在这里插入图片描述

测试域名是否可用,本地服务启动起来 把 127.0.0.1 换成这个域名,如果成功那离目的就越来越近了

后台回调接口

@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 "非法请求";
    }
  }

接口对应
在这里插入图片描述
在公众号配置好后提交配置如果后台服务没问题的话就可以认证成功了,接着就可以本地调试公众号关注,取关,消息等功能

后端项目博主用的是第三方的

https://github.com/binarywang
在这里插入图片描述
成功截图
在这里插入图片描述
在这里插入图片描述

最后祝小伙伴们顺利调试

猜你喜欢

转载自blog.csdn.net/hsadfdsahfdsgfds/article/details/130748470