123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //初始化用户信息数据
- 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") {
- type = 0;
- url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
- +"appid=wx749c84daac654e1e&"
- +"redirect_uri=https://wx.ttkuaiban.com/minigame&"
- +"response_type=code&"
- +"scope=snsapi_userinfo&"//snsapi_userinfo
- +"state=1#wechat_redirect";
- getMsg();
- }
- if (ua.match(/WeiBo/i) == "weibo") {
- type = 1;
- //url = "https://api.weibo.cn/oauth2/authorize?"
- url = "https://api.weibo.com/oauth2/authorize?"
- +"client_id=3741162137&"
- //+"display=mobile&"
- +"response_type=code&"
- +"redirect_uri=https://wx.ttkuaiban.com/minigame/index.html"
- //+"scope=snsapi_base";
- getMsg();
- }
- } else {
- var ua = navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == "micromessenger") {
- type = 0;
- url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
- +"appid=wx749c84daac654e1e&"
- +"redirect_uri=https://wx.ttkuaiban.com/minigame&"
- +"response_type=code&"
- +"scope=snsapi_userinfo&"//snsapi_userinfo
- +"state=1#wechat_redirect";
- getMsg();
- }
- }
-
- // 获取登陆信息
- 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> <input style="width:200px;height:100px;" id="input"/> <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;
- }
- }
- }
-
- // 获取填写寄语
- function saveText(text){
- var value = document.getElementById('textarea').value,
- receiver = document.getElementById('input').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("receiver="+receiver+"&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> <input style="width:200px;height:100px;" id="input"/> <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){
- history.pushState("", "Title", href);
- }
-
- if(type == 1) {
- setTimeout(function(){
- window.location.href = url
- }, 0);
- }
- }else{
- console.log("错误"+xhr.status)
- }
- }
- }
- }
-
- // 判断微信分享
- 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('分享到朋友圈')
- window.location.href = url
- });
- }, false);
-
- // 判断微博分享
- document.addEventListener('WeiboJSBridgeReady', function onBridgeReady() {
-
- }, false);
|