美文网首页
网站应用JS微信登录

网站应用JS微信登录

作者: 是我拉叔 | 来源:发表于2019-05-01 21:02 被阅读0次

    https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=e337b24c3e208b5e9b219ed826d63f7d951ad60d&lang=zh_CN

    S微信登录主要用途:网站希望用户在网站内就能完成登录,无需跳转到微信域下登录后再返回,提升微信登录的流畅性与成功率。 

    网站内嵌二维码微信登录JS实现办法:

    步骤1:在页面中先引入如下JS文件(支持https):

    http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js

    代码如下:

    !function(a,b,c){function d(a){var c="default";a.self_redirect===!0?c="true":a.self_redirect===!1&&(c="false");var d=b.createElement("iframe"),e="https://open.weixin.qq.com/connect/qrconnect?appid="+a.appid+"&scope="+a.scope+"&redirect_uri="+a.redirect_uri+"&state="+a.state+"&login_type=jssdk&self_redirect="+c;e+=a.style?"&style="+a.style:"",e+=a.href?"&href="+a.href:"",d.src=e,d.frameBorder="0",d.allowTransparency="true",d.scrolling="no",d.width="300px",d.height="400px";var f=b.getElementById(a.id);f.innerHTML="",f.appendChild(d)}a.WxLogin=d}(window,document);

    整理:

    ! function(win, doc) { function wxlogin(win) { var self_redirect = "default"; win.self_redirect === !0 ? self_redirect = "true" : win.self_redirect === !1 && (self_redirect = "false"); var frame = doc.createElement("iframe"); var url = "https://open.weixin.qq.com/connect/qrconnect?appid=" + win.appid + "&scope=" + win.scope + "&redirect_uri=" + win.redirect_uri + "&state=" + win.state + "&login_type=jssdk&self_redirect=" + self_redirect; url += win.style ? "&style=" + win.style : "", url += win.href ? "&href=" + win.href : "", frame.src = url, frame.frameBorder = "0", frame.allowTransparency = "true", frame.scrolling = "no", frame.width = "300px", frame.height = "400px"; var f = doc.getElementById(win.id); f.innerHTML = "", f.appendChild(frame) } win.WxLogin = wxlogin }(window, document);

    步骤2:在需要使用微信登录的地方实例以下JS对象:

    var obj = new WxLogin({
        self_redirect:true,
         id:"login_container",
         appid: "",
         scope: "",
         redirect_uri: "",
         state: "",
         style: "",
         href: ""
     });

    相关文章

      网友评论

          本文标题:网站应用JS微信登录

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