(以下所有接口由后臺(tái)提供)
一、微信自動(dòng)登錄
//定義事件 methods:{ //判斷是否微信登陸 是不是微信瀏覽器 isWeiXin() { let ua = window.navigator.userAgent.toLowerCase(); console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1 if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, test(){ if(this.isWeiXin()){ //微信登錄,接口由后臺(tái)定義 this.$http.get('/wx/index/login/type/2').then((res) => { if(res.data.code==0){ //微信登錄成功跳轉(zhuǎn)個(gè)人中心 this.$router.push({ name:'UserHome', }) }else{ //微信登錄失敗,使用填寫(xiě)信息登錄 this.$router.push({ name:'Login', }) } }) } //頁(yè)面加載后執(zhí)行 mounted(){ if(this.isWeiXin()){ //是來(lái)自微信內(nèi)置瀏覽器 // 獲取微信信息,如果之前沒(méi)有使用微信登陸過(guò),將進(jìn)行授權(quán)登錄 this.$http.get(this.$root.api+"/index/index/wx_info").then((res) => { if(res.data.code!=0){ location.href='/wx/index/wxAutoLogin'; } }) } }二、微信分享
methods:{ //判斷是否微信登陸 isWeiXin() { let ua = window.navigator.userAgent.toLowerCase(); console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1 if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, //微信分享使用方法 wxInit(sd){ let links='http://www.kspxzx.com/index/index/wxshare_choiceOk/identity/Student/courseID/'+this.courseID+'/appointment_code/'+this.appointment_code; //分享出去的鏈接 let title='學(xué)車(chē)訓(xùn)練課程分享'; //分享的標(biāo)題 let desc=' 教練名字:'+this.codeName+' 所在駕校:'+this.drive+' 訓(xùn)練日期:'+this.date+' 訓(xùn)練項(xiàng)目:'+this.proje; //分享的詳情介紹 wx.config({ debug: false, appId: sd.appId, timestamp: sd.timestamp, nonceStr: sd.nonceStr, signature: sd.signature, jsApiList: [ 'onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo' ] }); wx.ready(function () { // alert("done") // alert(title) wx.onMenuShareTimeline({ title: title, // 分享標(biāo)題 link:links, // 分享鏈接' imgUrl: sd.cover, // 分享圖標(biāo) success: function () { // 分享紀(jì)錄 shareRecord(); alert("分享到朋友圈成功") }, cancel: function () { alert("分享失敗,您取消了分享!") } }); // wx.onMenuShareAppMessage({ // title: title, // 分享標(biāo)題 // desc: description, // 分享描述 // link: link, // 分享鏈接 // imgUrl: cover, // 分享圖標(biāo) // success: function () { // alert("成功分享給朋友") // }, // cancel: function () { // alert("分享失敗,您取消了分享!") // } // }); //微信分享菜單測(cè)試 wx.onMenuShareAppMessage({ title:title, // 分享標(biāo)題 desc: desc, // 分享描述 link: links, // 分享鏈接 imgUrl: sd.cover, // 分享圖標(biāo) success: function () { // 分享紀(jì)錄 shareRecord(); alert("成功分享給朋友") }, cancel: function () { alert("分享失敗,您取消了分享!") } }); wx.onMenuShareQQ({ title:title, // 分享標(biāo)題 desc: desc, // 分享描述 link:links, // 分享鏈接 imgUrl: sd.cover, // 分享圖標(biāo) success: function () { // 分享紀(jì)錄 shareRecord(); alert("成功分享給QQ") }, cancel: function () { alert("分享失敗,您取消了分享!") } }); wx.onMenuShareWeibo({ title:title, // 分享標(biāo)題 desc: desc, // 分享描述 link: links, // 分享鏈接 imgUrl: sd.cover, // 分享圖標(biāo) success: function () { // 分享紀(jì)錄 shareRecord(); alert("成功分享給朋友") }, cancel: function () { alert("分享失敗,您取消了分享!") } }); }); wx.error(function(res){ // alert("error") // config信息驗(yàn)證失敗會(huì)執(zhí)行error函數(shù),如簽名過(guò)期導(dǎo)致驗(yàn)證失敗,具體錯(cuò)誤信息可以打開(kāi)config的debug模式查看,也可以在返回的res參數(shù)中查看,對(duì)于SPA可以在這里更新簽名。 }); }, },
新聞熱點(diǎn)
疑難解答
圖片精選