Browse Source

跳转授权

xuqiaoying 2 năm trước cách đây
mục cha
commit
11a05b1cdd
3 tập tin đã thay đổi với 51 bổ sung13 xóa
  1. 37 0
      pages/index/index.vue
  2. 8 7
      pages2/order/confirm_pay.vue
  3. 6 6
      pages2/order/index.vue

+ 37 - 0
pages/index/index.vue

@@ -293,9 +293,11 @@ export default {
 			subjectList: [],
 			subIndex: 0,
 			courSubjectId: '',
+			optObj: {},
 		};
 	},
 	async onLoad(option) {
+		console.log('onLoadonLoad');
 		this.isLogin = this.$method.isLogin()
 		this.dictObj
 		this.getAdvertising();
@@ -327,6 +329,29 @@ export default {
 		})
 	},
 	async onShow() {
+		// #ifdef H5
+		if (location.search) {
+			let arrs = location.search.slice(1).split("&")
+			for (let i = 0; i < arrs.length; i++) {
+				this.optObj[arrs[i].split('=')[0]] = arrs[i].split('=')[1]
+			}
+			console.log('optObj:', this.optObj);
+			uni.setStorageSync('h5_code', this.optObj.code)
+			this.OfficialLogin()
+		} else {
+			// 没有code,就重定向到地址https://www.xyyxt.net?ask_type=h.xyyxt.net 去获取code,授权后就会把code带上然后访问域名,这时候你就拿到code了
+			if (!uni.getStorageSync('h5_code')) {
+				console.log('跳转');
+				location.replace(
+					"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
+					"&redirect_uri=" +
+					encodeURIComponent('https://www.xyyxt.net/?ask_type=h.xyyxt.net') +
+					"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
+				)
+				return
+			}
+		}
+		// #endif
 		this.getInfo() // 判断有没有关注公众号		
 		this.isClickOff() //关注公众号,每天最多显示1次;当天学员关闭弹窗后,无需再显示
 		uni.removeStorageSync('goPath')
@@ -415,6 +440,18 @@ export default {
 	},
 	methods: {
 		...mapActions(['getUserInfo','appCommonConfig']),
+		// 公众号登录
+		OfficialLogin() {
+			this.$http({
+				url: '/gzh_login',
+				method: 'post',
+				data: {
+					code: this.optObj.code
+				},
+			}).then((res) => {
+				if (res.data.code == 200) {}
+			})
+		},
 		tobuy(item) {
 			if (item.goodsType == 2) {
                 uni.navigateTo({

+ 8 - 7
pages2/order/confirm_pay.vue

@@ -271,14 +271,15 @@ export default {
 				}
 			}); 
 			// #endif
+			
 			// #ifdef H5
-			// https://www.xyyxt.net
-			location.replace(
-				"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
-				"&redirect_uri=" +
-				encodeURIComponent('https://www.xyyxt.net') +
-				"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
-			)
+			// https://www.xyyxt.net/?ask_type=h.xyyxt.net
+			// location.replace(
+			// 	"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
+			// 	"&redirect_uri=" +
+			// 	encodeURIComponent('https://www.xyyxt.net/?ask_type=h.xyyxt.net') +
+			// 	"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
+			// )
 			// #endif
 		},
 		radioChange(e) {

+ 6 - 6
pages2/order/index.vue

@@ -251,12 +251,12 @@ export default {
 			}); 
 			// #endif
 			// #ifdef H5
-			location.replace(
-				"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
-				"&redirect_uri=" +
-				encodeURIComponent('https://www.xyyxt.net') +
-				"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
-			)
+			// location.replace(
+			// 	"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
+			// 	"&redirect_uri=" +
+			// 	encodeURIComponent('https://www.xyyxt.net') +
+			// 	"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
+			// )
 			// #endif
 		},
 		getOpenid(code,item){