|
@@ -4,96 +4,216 @@
|
|
|
<meta charset="UTF-8">
|
|
|
<meta http-equiv="Access-Control-Allow-Origin" content="*" />
|
|
|
<title>测试用页面</title>
|
|
|
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
|
|
- <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
|
|
|
+ <!-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> -->
|
|
|
+ <!-- <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script> -->
|
|
|
+ <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
|
|
|
+ <script src="http://tjs.sjs.sinajs.cn/open/thirdpart/js/jsapi/mobile.js" charset="utf-8"></script>
|
|
|
+
|
|
|
<script>
|
|
|
- (function() {
|
|
|
//初始化用户信息数据
|
|
|
window.user_info = {
|
|
|
+ uid: 0,
|
|
|
logo:'http://img5q.duitang.com/uploads/item/201502/25/20150225060808_wuANL.jpeg',//用户头像
|
|
|
nickname:'不羡鸳鸯',//用户昵称,
|
|
|
textmsg:'GOOD GOOD STUDY,DAY DAY UP'//寄语
|
|
|
};
|
|
|
|
|
|
+ var URLParams = new Array();
|
|
|
+
|
|
|
+ var params = document.location.search.substr(1).split('&');
|
|
|
var ua = navigator.userAgent.toLowerCase() , url = "" , type = 0;
|
|
|
+ for (i=0; i < params.length ; i++){
|
|
|
+ var aParam = params[i].split('=');
|
|
|
+ URLParams[aParam[0]] = aParam[1];
|
|
|
+ }
|
|
|
+
|
|
|
if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
|
|
|
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
|
|
- console.log(123)
|
|
|
- alert('123')
|
|
|
- alert("微信浏览器中打开");
|
|
|
type = 0;
|
|
|
url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
|
+"appid=wx749c84daac654e1e&"
|
|
|
+"redirect_uri=http://wx.ttkuaiban.com/minigame&"
|
|
|
+"response_type=code&"
|
|
|
- +"scope=snsapi_userinfo&"
|
|
|
- +"state=STATE#wechat_redirect";
|
|
|
+ +"scope=snsapi_userinfo&"//snsapi_userinfo
|
|
|
+ +"state=1#wechat_redirect";
|
|
|
+ getMsg();
|
|
|
}
|
|
|
|
|
|
if (ua.match(/WeiBo/i) == "weibo") {
|
|
|
- alert("在新浪微博客户端打开");
|
|
|
type = 1;
|
|
|
- url = "https://api.weibo.cn/oauth2/authorize?"
|
|
|
+ //url = "https://api.weibo.cn/oauth2/authorize?"
|
|
|
+ url = "https://api.weibo.com/oauth2/authorize?"
|
|
|
+"client_id=2141531565&"
|
|
|
- +"display=mobile&"
|
|
|
+ //+"display=mobile&"
|
|
|
+"response_type=code&"
|
|
|
- +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
|
|
|
- +"scope=snsapi_base";
|
|
|
+ +"redirect_uri=http://wx.ttkuaiban.com/minigame/index.html"
|
|
|
+ //+"scope=snsapi_base";
|
|
|
+ getMsg();
|
|
|
}
|
|
|
} else {
|
|
|
var ua = navigator.userAgent.toLowerCase();
|
|
|
if (ua.match(/MicroMessenger/i) == "micromessenger") {
|
|
|
- console.log(245)
|
|
|
- alert('234')
|
|
|
- alert("微信浏览器中打开");
|
|
|
type = 0;
|
|
|
url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
|
|
|
+"appid=wx749c84daac654e1e&"
|
|
|
+"redirect_uri=http://wx.ttkuaiban.com/minigame&"
|
|
|
+"response_type=code&"
|
|
|
- +"scope=snsapi_userinfo&"
|
|
|
- +"state=STATE#wechat_redirect";
|
|
|
+ +"scope=snsapi_userinfo&"//snsapi_userinfo
|
|
|
+ +"state=1#wechat_redirect";
|
|
|
+ getMsg();
|
|
|
}
|
|
|
}
|
|
|
- var URLParams = new Array();
|
|
|
- var params = document.location.search.substr(1).split('&');
|
|
|
- for (i=0; i < params.length ; i++){
|
|
|
- var aParam = params[i].split('=');
|
|
|
- URLParams[aParam[0]] = aParam[1];
|
|
|
+
|
|
|
+ // 获取登陆信息
|
|
|
+ function getMsg(){
|
|
|
+ if(URLParams['uid']){
|
|
|
+ var uid = URLParams['uid'];
|
|
|
+ var xhr=null;
|
|
|
+ try{
|
|
|
+ xhr=new XMLHttpRequest();
|
|
|
+ }catch(e){
|
|
|
+ xhr=new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
+ }
|
|
|
+ xhr.open("post","news/show",true);
|
|
|
+ xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
|
|
|
+ xhr.send("id="+uid);
|
|
|
+ xhr.onreadystatechange=function(){
|
|
|
+ if(xhr.readyState==4){
|
|
|
+ if(xhr.status==200){
|
|
|
+ var msg = JSON.parse(xhr.response);
|
|
|
+ if(msg.code == "ok") {
|
|
|
+ window.user_info.uid = msg.data.id;
|
|
|
+ window.user_info.logo = msg.data.headerPic;
|
|
|
+ window.user_info.nickname = msg.data.nickName;
|
|
|
+ window.user_info.textmsg = msg.data.message;
|
|
|
+ }
|
|
|
+ //if(URLParams['act']=='hbshare'){
|
|
|
+ document.close();
|
|
|
+ document.write('<h1>这里是海报页</h1>');
|
|
|
+ document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
|
|
|
+ document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
|
|
|
+ document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
|
|
|
+ document.write('<a onclick="saveText()" style="font-size:30px;">生成我的菜单</a>');
|
|
|
+ //}else{
|
|
|
+ // document.write('<h1>这是首页哦</h1>');
|
|
|
+ //}
|
|
|
+ }else{
|
|
|
+ console.log("错误"+xhr.status)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(URLParams['code']){
|
|
|
+ var code = URLParams['code'];
|
|
|
+ var xhr=null;
|
|
|
+ try{
|
|
|
+ xhr=new XMLHttpRequest();
|
|
|
+ }catch(e){
|
|
|
+ xhr=new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
+ }
|
|
|
+ xhr.open("post","user/weiXinLogin",true);
|
|
|
+ xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
|
|
|
+ xhr.send("code="+code+"&type="+type);
|
|
|
+ xhr.onreadystatechange=function(){
|
|
|
+ if(xhr.readyState==4){
|
|
|
+ if(xhr.status==200){
|
|
|
+ var msg = JSON.parse(xhr.response);
|
|
|
+ if(msg.code == "ok") {
|
|
|
+ window.user_info.uid = msg.data.id;
|
|
|
+ window.user_info.logo = msg.data.headerPic;
|
|
|
+ window.user_info.nickname = msg.data.nickName;
|
|
|
+ }
|
|
|
+ //if(URLParams['act']=='hbshare'){
|
|
|
+ document.write('<h1>这里是海报页</h1>');
|
|
|
+ document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
|
|
|
+ document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
|
|
|
+ document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
|
|
|
+ document.write('<span style="font-size:30px;">填写寄语 </span> <br> <textarea style="width:300px;height:200px;" id="textarea">'+ window.user_info.textmsg +'</textarea> <br> <a onclick="saveText()" style="font-size:30px;">保存寄语</a>');
|
|
|
+ //}else{
|
|
|
+ // document.write('<h1>这是首页哦</h1>');
|
|
|
+ //}
|
|
|
+ saveText(window.user_info.textmsg);
|
|
|
+ }else{
|
|
|
+ console.log("错误"+xhr.status)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ window.location.href = url;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if(URLParams['code']){
|
|
|
- var code = URLParams['code'];
|
|
|
- <!-- $.get("http://118.190.47.230/minigame/user/weiXinLogin",{ -->
|
|
|
- <!-- code:code, -->
|
|
|
- <!-- type:type -->
|
|
|
- <!-- },function(result){ -->
|
|
|
- <!-- console.log(result) -->
|
|
|
- <!-- }); -->
|
|
|
-
|
|
|
- $.ajax({
|
|
|
- url:"http://118.190.47.230/minigame/user/weiXinLogin",
|
|
|
- type:"POST",//请求方式
|
|
|
- data:{"code":code,"type":type},
|
|
|
- dataType:"json", //数据格式设置为jsonp
|
|
|
- success:function (data) {//请求成功后调用的函数
|
|
|
- alert("succ:"+data);
|
|
|
- if(URLParams['act']=='hbshare'){
|
|
|
- document.write('<h1>这里是海报页</h1>');
|
|
|
- document.write('头像<img src="'+window.user_info.logo+'" width=40 height=40 /><br>');
|
|
|
- document.write('昵称:'+window.user_info.nickname+'<br>');
|
|
|
- document.write('寄语:'+window.user_info.textmsg);
|
|
|
+
|
|
|
+ // 获取填写寄语
|
|
|
+ function saveText(text){
|
|
|
+ var value = document.getElementById('textarea').value;
|
|
|
+ if (text) {
|
|
|
+ value = text;
|
|
|
+ }
|
|
|
+
|
|
|
+ var xhr=null;
|
|
|
+ try{
|
|
|
+ xhr=new XMLHttpRequest();
|
|
|
+ }catch(e){
|
|
|
+ xhr=new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
+ }
|
|
|
+ xhr.open("post","news/addNews",true);
|
|
|
+ xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
|
|
|
+ xhr.send("message="+value+"&userId="+window.user_info.uid);
|
|
|
+ xhr.onreadystatechange=function(){
|
|
|
+ if(xhr.readyState==4){
|
|
|
+ if(xhr.status==200){
|
|
|
+ var msg = JSON.parse(xhr.response) , href = document.location.href;
|
|
|
+ if(msg.code == "ok") {
|
|
|
+ window.user_info.uid = msg.data.id;
|
|
|
+ window.user_info.logo = msg.data.headerPic;
|
|
|
+ window.user_info.nickname = msg.data.nickName;
|
|
|
+ window.user_info.textmsg = msg.data.message;
|
|
|
+ href = document.location.href + "&uid=" + msg.data.id;
|
|
|
+ }
|
|
|
+ //if(URLParams['act']=='hbshare'){
|
|
|
+ document.close();
|
|
|
+ document.write('<h1>这里是海报页</h1>');
|
|
|
+ document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
|
|
|
+ document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
|
|
|
+ document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
|
|
|
+ document.write('<span style="font-size:30px;">填写寄语 </span> <br> <textarea style="width:200px;height:100px;" id="textarea"></textarea> <br> <a onclick="saveText()" style="font-size:30px;">保存寄语</a>');
|
|
|
+ //}else{
|
|
|
+ // document.write('<h1>这是首页哦</h1>');
|
|
|
+ //}
|
|
|
+
|
|
|
+ if(href != document.location.href){
|
|
|
+ console.log(href)
|
|
|
+ history.pushState("", "Title", href);
|
|
|
+ //window.location.href = href;
|
|
|
+ }
|
|
|
}else{
|
|
|
- document.write('<h1>这是首页哦</h1>');
|
|
|
+ console.log("错误"+xhr.status)
|
|
|
}
|
|
|
- },
|
|
|
- error:function (textStatus) {//请求失败后调用的函数
|
|
|
- alert("fail");
|
|
|
- }
|
|
|
- })
|
|
|
- }else{
|
|
|
- window.location.href = url;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- })()
|
|
|
+
|
|
|
+ // 判断微信分享
|
|
|
+ document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
|
|
|
+ // 发送给好友
|
|
|
+ WeixinJSBridge.on('menu:share:appmessage', function(argv){
|
|
|
+ alert('发送给好友')
|
|
|
+ window.location.href = url
|
|
|
+ });
|
|
|
+ // 分享到朋友圈
|
|
|
+ WeixinJSBridge.on('menu:share:timeline', function(argv){
|
|
|
+ alert('分享到朋友圈')
|
|
|
+ });
|
|
|
+ }, false);
|
|
|
+
|
|
|
+ // 判断微博分享
|
|
|
+ document.addEventListener('WeiboJSBridgeReady', function onBridgeReady() {
|
|
|
+ WeiboJSBridgeReady.on('menu:share', function(argv){
|
|
|
+ alert('微博分享')
|
|
|
+ window.location.href = url
|
|
|
+ });
|
|
|
+ }, false);
|
|
|
</script>
|
|
|
</head>
|
|
|
<body>
|