pin_notify.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <div id="ws-for-push" class="pin_tips_container pin_tips_fadeOut" onclick=''>
  2. <img class="pin_tips_user_pic fl" id="ws-for-avatar" src="https://s17.mogucdn.com/css/images/0.gif">
  3. <div class="pin_tips_info fl">
  4. <span class="fl">最新拼团来自</span>
  5. <span class="pin_tips_info_name fl" id="ws-for-name"></span>
  6. <span class="fl" id="ws-for-miao"></span>
  7. </div>
  8. </div>
  9. <link rel="stylesheet" href="__PUBLIC__/mogu/pinIndex-126e28067f.css">
  10. <script type="text/javascript" src="__PUBLIC__/js/swfobject.js"></script>
  11. <script type="text/javascript" src="__PUBLIC__/js/web_socket.js"></script>
  12. <script>
  13. if (typeof console == "undefined") { this.console = { log: function (msg) { } };}
  14. // 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
  15. WEB_SOCKET_SWF_LOCATION = "__PUBLIC__/swf/WebSocketMain.swf";
  16. // 开启flash的websocket debug
  17. WEB_SOCKET_DEBUG = true;
  18. var ws, name, client_list={};
  19. var domain = document.domain;
  20. var cur_page = 0;
  21. // 连接服务端
  22. function connect() {
  23. // 创建websocket wss
  24. ws = new WebSocket("wss://mall.shiziyu888.com/wss");
  25. // 当socket连接打开时,输入用户名
  26. ws.onopen = onopen;
  27. // 当有消息时根据消息类型显示不同信息
  28. ws.onmessage = onmessage;
  29. ws.onclose = function() {
  30. console.log("连接关闭,定时重连");
  31. connect();
  32. };
  33. ws.onerror = function() {
  34. console.log("出现错误");
  35. };
  36. }
  37. // 连接建立时发送登录信息
  38. function onopen()
  39. {
  40. //document.domain
  41. // 登录
  42. var login_data = '{ "type":"membre_login","domain":"'+domain+'"} ';
  43. console.log("websocket握手成功,发送登录数据:"+login_data);
  44. ws.send(login_data);
  45. //login
  46. }
  47. // 服务端发来消息时
  48. function onmessage(e)
  49. {
  50. var data = eval("("+e.data+")");
  51. console.log(data);
  52. switch(data['type']){
  53. // 服务端ping客户端
  54. case 'ping':
  55. ws.send('{"type":"pong"}');
  56. break;
  57. //array('type'=>'resv_blog','blog_id'=>$blog_id);
  58. case 'member_buy_msg':
  59. on_member_buy_msg(data);
  60. break;
  61. }
  62. }
  63. function on_member_buy_msg(data)
  64. {
  65. //cur_page = data.page;
  66. jarray.push(data);
  67. }
  68. function send_bao_notify(res)
  69. {
  70. var buy_data = '{ "type":"member_buy","avatar":"'+res.avatar+'","miao":"'+res.miao+'","order_id":"'+res.order_id+'","username":"'+res.username+'","order_url":"'+res.order_url+'"} ';
  71. ws.send(buy_data);
  72. }
  73. var jarray=[];
  74. var t;
  75. var d;
  76. var ck_lo_pt = "<?php echo U('Order/notify_order', array('rt' => mt_rand(1,99999))); ?>";
  77. $(function(){
  78. t = setTimeout(shownoticeorder,1000);
  79. connect();
  80. d=setInterval(checknoticeorder,4000);
  81. })
  82. function shownoticeorder()
  83. {
  84. $.ajax({
  85. url:ck_lo_pt,
  86. type:'get',
  87. dataType:'json',
  88. success:function(res){
  89. if(res.ret == 1)
  90. {
  91. send_bao_notify(res);
  92. //send_bao_notify
  93. //show_or(res);
  94. }
  95. }
  96. })
  97. }
  98. function checknoticeorder()
  99. {
  100. if(jarray.length >0)
  101. {
  102. var res = jarray.pop();
  103. show_or(res);
  104. }
  105. }
  106. function show_or(res)
  107. {
  108. $('#ws-for-push').attr('onclick', "location.href='"+res.order_url+"';");
  109. $('#ws-for-avatar').attr('src', res.avatar);
  110. $('#ws-for-name').html(res.username);
  111. $('#ws-for-miao').html(','+res.miao+'秒前');
  112. $('#ws-for-push').removeClass('pin_tips_fadeOut');
  113. $('#ws-for-push').addClass('pin_tips_fadeIn');
  114. clearTimeout(t);
  115. t=setTimeout(hidenoticeorder,2000);
  116. //t=setTimeout("timedCount()",1000)
  117. //clearTimeout(t)
  118. }
  119. function hidenoticeorder()
  120. {
  121. $('#ws-for-push').removeClass('pin_tips_fadeIn');
  122. $('#ws-for-push').addClass('pin_tips_fadeOut');
  123. clearTimeout(t);
  124. t=setTimeout("shownoticeorder()",3000);
  125. }
  126. </script>