欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

Vue微信公眾號靜默授權 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網站,軟件還是小程序,都要直接或間接能為您產生價值,我們在追求其視覺表現(xiàn)的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網站成為營銷工具,讓軟件能切實提升企業(yè)內部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 公眾號相關 >

Vue微信公眾號靜默授權

發(fā)表時間:2020-10-19

發(fā)布人:葵宇科技

瀏覽次數(shù):93

首先要注冊一個公眾號
再里面配置自己的安全域名 有兩個地方要配置 開發(fā)-》設置
配置完之后 在微信開發(fā)工具打開,
因為微信那邊的限制 我目前只能在把頁面放到服務器上進行訪問
這個是靜默授權在邏輯是打開頁面時 有一個redirect_uri 這個參數(shù) 是獲取code后的重定向位置 一般就是當前頁面
code 的值 獲取成功后會放到url中 通過 location去獲取就好了

 created() {
                this.getUrl()
            },
getUrl() {
                    let userAgent = navigator.userAgent;
                    if (userAgent.includes("iPhone") || userAgent.includes("iPad")) {
                        sessionStorage.setItem("originUrl", location.href); // 用于ios分享
                    }
                    this.getBaseInfos();
                },

                // 編碼函數(shù)
                getUrlParam(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構造一個含有目標參數(shù)的正則表達式對象
                    var r = window.location.search.substr(1).match(reg); //匹配目標參數(shù)

                    if (r != null) return unescape(r[2]);
                    return null; //返回參數(shù)值
                },

                getBaseInfos() {
                    if (this.isWeiXin()) {
                        const code = this.getUrlParam("code"); // 截取路徑中的code
                        if (code == null || code === "") {
                            let url = "";
                            let userAgent = navigator.userAgent;
                            if (userAgent.includes("iPhone") || userAgent.includes("iPad")) {
                                url = sessionStorage.getItem("originUrl");
                            } else {
                                url = window.location.href;
                            }
                            window.location.href =
                                "https://open.weixin.qq.com/connect/oauth2/authorize?appid=你申請的appkey&redirect_uri=" +
                                encodeURIComponent(url) +
                                "&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect";
                        } else {
                        }

                        if (code != "" && code != null) {
                            this.wxCode = code;
                            console.log(code)
                            this.getOpenid(code)
                        }
                    } else {
                    }
                },

                isWeiXin() {
                    var ua = window.navigator.userAgent.toLowerCase();
                    if (ua.match(/MicroMessenger/i) == "micromessenger") {
                        return true;
                    } else {
                        return false;
                    }
                },

相關案例查看更多