<template>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				authUrl: 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='+this.config.appId+'&response_type=code&scope=snsapi_userinfo&state=bes&redirect_uri='
			}
		},
		onLoad() {
			let code = this.getUrlParam('code')
			if(code == null || code == '') {
				// 重新获取code
				let url = this.authUrl + location.href
				window.location.href = url
			} else {
				// 发送code           
				this.getAccessToken(code)
			}
		},
		methods: {
			// 解析URL 参数
			getUrlParam(name) {
				let reg = new RegExp('(^|&)'+ name + '=([^&]*)(&|$)')
				let r = window.location.search.substr(1).match(reg)
				if(r!=null){
					return unescape(r[2])
				} 
				return null
			},
			getAccessToken(url) {
				console.log(url)
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>
<style>
</style>
