<template>
	<view></view>
</template>

<script>
	import API from '@/common/js/api.js'
	export default {
		data() {
			return {
				code: '',
				state: '',
				state1:'',
				appId:'',
				redirectUri:''
			}
		},
		onLoad(options) {
			this.checkWeChatCode()
		},
		methods: {
			checkWeChatCode() {
					API.getWxCode({}, res => {
						if (res.code == 1) {
							this.redirectUri = res.data.redirectUri;
							this.appId = res.data.appId;
							this.state = res.data.state;
							this.getCode()
						}
					})
			},
			// 获取code
			getCode () {
				let local = encodeURIComponent('https://intp.xingtongworld.com/wechat/')
				window.location.href = 
				'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId +
				'&redirect_uri=' + local +
				'&response_type=code&scope=snsapi_userinfo&state=' + this.state + '#wechat_redirect';

			// redirect_uri是授权成功后，跳转的url地址，微信会帮我们跳转到该链接，并且通过？的形式拼接code，这里需要用encodeURIComponent对链接进行处理。
			// 如果配置参数一一对应，那么此时已经通过回调地址刷新页面后，你就会再地址栏中看到code了。
			// https://test.yuruantong.com/pages/loginAndRegister/login/loginH5?code=0312nn200ADR1P1BYh100zp2VL32nn2f&state=1
			}
		}
	}
</script>
<style>
</style>