poster.js 7.8 KB

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