index.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="Access-Control-Allow-Origin" content="*" />
  6. <title>测试用页面</title>
  7. <!-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> -->
  8. <!-- <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script> -->
  9. <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
  10. <script src="http://tjs.sjs.sinajs.cn/open/thirdpart/js/jsapi/mobile.js" charset="utf-8"></script>
  11. <script>
  12. //初始化用户信息数据
  13. window.user_info = {
  14. uid: 0,
  15. logo:'http://img5q.duitang.com/uploads/item/201502/25/20150225060808_wuANL.jpeg',//用户头像
  16. nickname:'不羡鸳鸯',//用户昵称,
  17. textmsg:'GOOD GOOD STUDY,DAY DAY UP'//寄语
  18. };
  19. var URLParams = new Array();
  20. var params = document.location.search.substr(1).split('&');
  21. var ua = navigator.userAgent.toLowerCase() , url = "" , type = 0;
  22. for (i=0; i < params.length ; i++){
  23. var aParam = params[i].split('=');
  24. URLParams[aParam[0]] = aParam[1];
  25. }
  26. if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  27. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  28. type = 0;
  29. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  30. +"appid=wx749c84daac654e1e&"
  31. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  32. +"response_type=code&"
  33. +"scope=snsapi_userinfo&"//snsapi_userinfo
  34. +"state=1#wechat_redirect";
  35. getMsg();
  36. }
  37. if (ua.match(/WeiBo/i) == "weibo") {
  38. type = 1;
  39. //url = "https://api.weibo.cn/oauth2/authorize?"
  40. url = "https://api.weibo.com/oauth2/authorize?"
  41. +"client_id=2141531565&"
  42. //+"display=mobile&"
  43. +"response_type=code&"
  44. +"redirect_uri=http://wx.ttkuaiban.com/minigame/index.html"
  45. //+"scope=snsapi_base";
  46. getMsg();
  47. }
  48. } else {
  49. var ua = navigator.userAgent.toLowerCase();
  50. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  51. type = 0;
  52. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  53. +"appid=wx749c84daac654e1e&"
  54. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  55. +"response_type=code&"
  56. +"scope=snsapi_userinfo&"//snsapi_userinfo
  57. +"state=1#wechat_redirect";
  58. getMsg();
  59. }
  60. }
  61. // 获取登陆信息
  62. function getMsg(){
  63. if(URLParams['uid']){
  64. var uid = URLParams['uid'];
  65. var xhr=null;
  66. try{
  67. xhr=new XMLHttpRequest();
  68. }catch(e){
  69. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  70. }
  71. xhr.open("post","news/show",true);
  72. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  73. xhr.send("id="+uid);
  74. xhr.onreadystatechange=function(){
  75. if(xhr.readyState==4){
  76. if(xhr.status==200){
  77. var msg = JSON.parse(xhr.response);
  78. if(msg.code == "ok") {
  79. window.user_info.uid = msg.data.id;
  80. window.user_info.logo = msg.data.headerPic;
  81. window.user_info.nickname = msg.data.nickName;
  82. window.user_info.textmsg = msg.data.message;
  83. }
  84. //if(URLParams['act']=='hbshare'){
  85. document.close();
  86. document.write('<h1>这里是海报页</h1>');
  87. document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
  88. document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
  89. document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
  90. document.write('<a onclick="saveText()" style="font-size:30px;">生成我的菜单</a>');
  91. //}else{
  92. // document.write('<h1>这是首页哦</h1>');
  93. //}
  94. }else{
  95. console.log("错误"+xhr.status)
  96. }
  97. }
  98. }
  99. }else {
  100. if(URLParams['code']){
  101. var code = URLParams['code'];
  102. var xhr=null;
  103. try{
  104. xhr=new XMLHttpRequest();
  105. }catch(e){
  106. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  107. }
  108. xhr.open("post","user/weiXinLogin",true);
  109. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  110. xhr.send("code="+code+"&type="+type);
  111. xhr.onreadystatechange=function(){
  112. if(xhr.readyState==4){
  113. if(xhr.status==200){
  114. var msg = JSON.parse(xhr.response);
  115. if(msg.code == "ok") {
  116. window.user_info.uid = msg.data.id;
  117. window.user_info.logo = msg.data.headerPic;
  118. window.user_info.nickname = msg.data.nickName;
  119. }
  120. //if(URLParams['act']=='hbshare'){
  121. document.write('<h1>这里是海报页</h1>');
  122. document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
  123. document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
  124. document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
  125. 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>');
  126. //}else{
  127. // document.write('<h1>这是首页哦</h1>');
  128. //}
  129. saveText(window.user_info.textmsg);
  130. }else{
  131. console.log("错误"+xhr.status)
  132. }
  133. }
  134. }
  135. } else {
  136. window.location.href = url;
  137. }
  138. }
  139. }
  140. // 获取填写寄语
  141. function saveText(text){
  142. var value = document.getElementById('textarea').value;
  143. if (text) {
  144. value = text;
  145. }
  146. var xhr=null;
  147. try{
  148. xhr=new XMLHttpRequest();
  149. }catch(e){
  150. xhr=new ActiveXObject("Microsoft.XMLHTTP");
  151. }
  152. xhr.open("post","news/addNews",true);
  153. xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
  154. xhr.send("message="+value+"&userId="+window.user_info.uid);
  155. xhr.onreadystatechange=function(){
  156. if(xhr.readyState==4){
  157. if(xhr.status==200){
  158. var msg = JSON.parse(xhr.response) , href = document.location.href;
  159. if(msg.code == "ok") {
  160. window.user_info.uid = msg.data.id;
  161. window.user_info.logo = msg.data.headerPic;
  162. window.user_info.nickname = msg.data.nickName;
  163. window.user_info.textmsg = msg.data.message;
  164. href = document.location.href + "&uid=" + msg.data.id;
  165. }
  166. //if(URLParams['act']=='hbshare'){
  167. document.close();
  168. document.write('<h1>这里是海报页</h1>');
  169. document.write('<span style="font-size:30px;">头像:</span><img src="'+window.user_info.logo+'"/><br>');
  170. document.write('<span style="font-size:30px;">昵称:'+window.user_info.nickname+'</span><br>');
  171. document.write('<span style="font-size:30px;">寄语:'+window.user_info.textmsg+'</span><br>');
  172. 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>');
  173. //}else{
  174. // document.write('<h1>这是首页哦</h1>');
  175. //}
  176. if(href != document.location.href){
  177. console.log(href)
  178. history.pushState("", "Title", href);
  179. //window.location.href = href;
  180. }
  181. }else{
  182. console.log("错误"+xhr.status)
  183. }
  184. }
  185. }
  186. }
  187. // 判断微信分享
  188. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  189. // 发送给好友
  190. WeixinJSBridge.on('menu:share:appmessage', function(argv){
  191. console.log(argv)
  192. alert('发送给好友')
  193. //window.location.href = url
  194. });
  195. // 分享到朋友圈
  196. WeixinJSBridge.on('menu:share:timeline', function(argv){
  197. alert('分享到朋友圈')
  198. });
  199. // 分享到微博
  200. WeixinJSBridge.on('menu:share:weibo', function(argv){
  201. alert('分享到微博')
  202. });
  203. }, false);
  204. // 判断微博分享
  205. document.addEventListener('WeiboJSBridgeReady', function onBridgeReady() {
  206. WeiboJSBridgeReady.on('menu:share', function(argv){
  207. alert('微博分享')
  208. window.location.href = url
  209. });
  210. }, false);
  211. </script>
  212. </head>
  213. <body>
  214. </body>
  215. </html>