52 lines
1.8 KiB
HTML
52 lines
1.8 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>微信通用框架</title>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div id="app">
|
||
|
|
<p>code: {{code}}</p>
|
||
|
|
<hr>
|
||
|
|
<p>openid: {{usertoken.openid}}</p>
|
||
|
|
<p>access token: {{usertoken.access_token}}</p>
|
||
|
|
<hr>
|
||
|
|
<img :src='user.headimgurl'>
|
||
|
|
<p>nickname: {{user.nickname}}</p>
|
||
|
|
<p>province: {{user.province}}</p>
|
||
|
|
<p>city: {{user.city}}</p>
|
||
|
|
</div>
|
||
|
|
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
|
||
|
|
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
|
||
|
|
<script src="js/site.js"></script>
|
||
|
|
<script>
|
||
|
|
new Vue({
|
||
|
|
el:'#app',
|
||
|
|
data: {
|
||
|
|
user:{},
|
||
|
|
usertoken:{},
|
||
|
|
code:'',
|
||
|
|
},
|
||
|
|
created () {
|
||
|
|
var that=this;
|
||
|
|
this.code = GetQueryString('code');
|
||
|
|
$.ajaxSettings.async = false; //同步执行
|
||
|
|
$.getJSON(url + '/wechat/access_token/' + this.code, function(data,status) {
|
||
|
|
if (status == "success"){
|
||
|
|
sessionStorage.setItem('token', JSON.stringify(data));
|
||
|
|
}
|
||
|
|
var userstring=sessionStorage.getItem('token');
|
||
|
|
that.usertoken=JSON.parse(userstring);
|
||
|
|
});
|
||
|
|
$.getJSON(url+'/wechat/userinfo/'+that.usertoken.access_token+'/'+that.usertoken.openid,function(data,status){
|
||
|
|
if(status=="success"){
|
||
|
|
that.user=data;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
$.ajaxSettings.async = true; //恢复异步执行
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|