微信公众号绑定用户进行消息推送

   getCode () {
      const AppId = '你的微信公众号appid'
      const code = this.getQueryVariable('code')
      const local = window.location.href
      if (code == null || code === '') {
        window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + AppId + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
      } else {
        this.code = code
      }
    },
    getQueryVariable (variable) {
      let query = window.location.search.substring(1)
      let vars = query.split('&')
      let index = vars.findIndex(item => {
        let pair = item.split('=')
        return pair[0] === variable
      })
      if (index !== -1) {
        return vars[index].split('=')[1]
      } else {
        return null
      }
    },

 实现效果

可参考:https://www.jianshu.com/p/b7e2100b56e4

posted @ 2020-01-08 16:55  把我当做一棵树叭  阅读(452)  评论(0)    收藏  举报