如何使用ngrok通过微信公众号url认证并在本地开发调试

1:安装ngrok

  自己动手解决

2:启动ngrok

2.1:配置token 从ngrok官网获取
ngrok config add-authtoken <TOKEN>
2.2:启动ngrok 映射本地端口 我这里映射9999
ngrok http 9999 --scheme http
  --scheme http 让生成的url是http 否则默认https
  也可以--scheme http,https 全都要

3:远程服务器安装nginx

  自己动手解决

4:nginx配置并启动

server {
    listen       80;

    #省略n多

    location / {
        proxy_pass http://5844-175-153-161-236.ngrok-free.app;
    }
}
  监听80是因为小程序要求 下面意思是把请求都往ngrok的url转 这里改为你上面生成的  

5:注意

  现在请求服务器ip 就会转到本地的9999端口服务上

  也意味着可以去微信公众号后台配置服务器url了

  ngrok的--scheme不建议使用https,因为可能出现这个

You are about to visit:

c725-183-220-16-6.ngrok-free.app

Website IP: 183.220.16.6

This website is served for free through ngrok.com.
You should only visit this website if you trust whoever sent the link to you.
Be careful about disclosing personal or financial information like passwords, phone numbers, or credit cards.
Visit Site
Are you the developer?
We display this page to prevent abuse. Visitors to your site will only see it once.

To remove this page:
Set and send an ngrok-skip-browser-warning request header with any value.
Or, set and send a custom/non-standard browser User-Agent request header.
Or, please upgrade to any paid ngrok account.

凑字数 顺便方便被搜索到

  出现这个会导致微信那里配置好url后它的验证get请求过去后返回的是上图页面的html代码

  虽然图里给出了解决方案 但是意味着还需要去修改nginx配置添加请求头 并且实践下来发现还有    别的问题

  所以测试嘛 能用就行 老老实实http

  最后,如果第二天打开电脑重新启动ngrok了,记得去nginx修改配置并重载 能用就行了 懒得再    去折腾更方便的办法了

  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值