index.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>测试用页面</title>
  6. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  7. <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
  8. <style>
  9. div, a {
  10. font-size: 60px;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div>
  16. <a onclick="getMsgByWX()">获取微信数据</a>
  17. </div>
  18. <br>
  19. <div>
  20. <a onclick="getMsgByWB()">获取微博数据</a>
  21. </div>
  22. <script>
  23. function getMsgByWX() {
  24. }
  25. function getMsgByWB() {
  26. }
  27. (function() {
  28. if (!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/)) {
  29. var ua = navigator.userAgent.toLowerCase() , url = "" , type = 0;
  30. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  31. alert("微信浏览器中打开");
  32. type = 0;
  33. url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
  34. +"appid=wx749c84daac654e1e&"
  35. +"redirect_uri=http://wx.ttkuaiban.com/minigame&"
  36. +"response_type=code&"
  37. +"scope=snsapi_base&"
  38. +"state=STATE#wechat_redirect";
  39. //https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx749c84daac654e1e&redirect_uri=wx.ttkuaiban.com&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
  40. }
  41. if (ua.match(/WeiBo/i) == "weibo") {
  42. alert("在新浪微博客户端打开");
  43. type = 1;
  44. url = "https://api.weibo.cn/oauth2/authorize?"
  45. +"client_id=2141531565&"
  46. +"display=mobile&"
  47. +"response_type=code&"
  48. +"redirect_uri=code&"
  49. +"scope=snsapi_base";
  50. }
  51. var URLParams = new Array();
  52. var params = document.location.search.substr(1).split('&');
  53. for (i=0; i < params.length ; i++){
  54. var aParam = params[i].split('=');
  55. URLParams[aParam[0]] = aParam[1];
  56. }
  57. if(URLParams['code']){
  58. var code = URLParams['code'];
  59. $.post("https://http://118.190.47.230/minigame/user/weiXinLogin.do",{
  60. code:code,
  61. type:type
  62. },function(result){
  63. console.log(result)
  64. });
  65. }else{
  66. window.location.href = url;
  67. }
  68. /* $.get(url ,function(data,status){
  69. console.log("Data: " + data + "nStatus: " + status);
  70. $.post("demo_ajax_gethint.html",{suggest:txt},function(result){
  71. $("span").html(result);
  72. });
  73. }); */
  74. }
  75. })()
  76. </script>
  77. </body>
  78. </html>