美文网首页
申请微信公众号测试账号

申请微信公众号测试账号

作者: 阿畅_ | 来源:发表于2019-04-01 10:58 被阅读0次

    最近在搞微信公众号,在申请测试账号时遇到一些问题,记录一下。
    在开发微信公众号过成中,一般要先申请一个测试账号,来本地测试开发公众号,


    image.png
    1. 先申请一个测试账号,微信会给你 appID,appsecret 账号信息

    2. 配置接口信息,微信会验证你的 token
      URL: 填写域名,必须是公网的地址
      Token: 可以随便填写

      • 如果没有域名,服务器,想用本地操作,可以用代理的方式,把本地的 localhost 代理到公网上
      • 我这里用的是 ngrok
      • 终端进入到下载的 ngrok 地址
        执行 ./ngrok http http://localhost:3000
        image.png
    • 接着验证 token
      这里我用的是 node.js
      const sha1 = require('sha1')
      // npm i sha1 -S  下载 sha1
    
     const config = {
        wechat: {
          appid: 'wx11235653342',
          appsecret: 'c7qn324y893n4u131',
          token: 'ceshi'
        }
      }
      module.exports =  (router) => {
        router.get('/verify', async(ctx) => {
          const token = config.wechat.token
          const signature = ctx.query.signature
          const nonce = ctx.query.nonce
          const timestamp = ctx.query.timestamp
          const echostr = ctx.query.echostr
          const str = [token, timestamp, nonce].sort().join('')
          const sha = sha1(str)
    
          if (sha === signature) {
            ctx.body = echostr + ''
          }else {
            ctx.body = 'error'
          }
      })
    
    • 然后点击提交验证
      注意: 这里的信息不要填写错误
      URL: http://35d19f1a.ngrok.io/verify
      Token:ceshi
    • 如果失败,看一下是否哪里写错了,提示成功,说明已经验证通过
    1. 填写域名,可以是本地的地址


      image.png
    2. 配置授权回调页面的域名


      image.png
    image.png

    遇到的错误

    1. redirect_uri 参数错误
      如果调用微信回调时报redirect_uri 参数错误,看一下上面的域名写的是否正确

    2. 如果不是本地域名,线上域名怎么配置
      需要把 JS 安全域名和授权回调页面域名配成一直的,不要加 http或https

    相关文章

      网友评论

          本文标题:申请微信公众号测试账号

          本文链接:https://www.haomeiwen.com/subject/hkumbqtx.html