当前位置: 首页 > 编程日记 > 正文

workerman结合laravel开发在线聊天应用的示例代码

项目背景:

最近由于公司的业务需求,需要用到聊天功能。而且有比较多的个性化需求需要定制。之前使用别人的聊天组件是基于微擎的。如果要移植到普通的H5在逻辑修改还有定制上存在比较多的困难。为此只能克服困难,自己搭建一个吧

什么是Workerman?

Workerman是一款 开源 高性能异步 PHP socket即时通讯框架 。支持高并发,超高稳定性,被广泛的用于手机app、移动通讯,微信小程序,手游服务端、网络游戏、PHP聊天室、硬件通讯、智能家居、车联网、物联网等领域的开发。 支持TCP长连接,支持Websocket、HTTP等协议,支持自定义协议。拥有异步Mysql、异步Redis、异步Http、MQTT物联网客户端、异步消息队列等众多高性能组件。

开始实战吧!

1.第一步我们先把workerman里需要用到的扩展composer下来吧

?
1
2
3
"workerman/gateway-worker": "^3.0",
"workerman/gatewayclient": "^3.0",
"workerman/workerman": "^3.5",

2.第二步我们到官方网站把demo全部下载下来,然后放到我们项目中的目录

图片中我就把整个项目都放在了HTTP/Controller/Workerman中。

3.第三步我们需要把把以下3个文件的引用部分修改为以下。不然会报路径错误

start_businessworker,start_gateway,start_register

?
1
require_once __DIR__ . '/../../../../../vendor/autoload.php';

4.修改完成后我们就可以在liunx直接运行对应的启动文件

?
1
php start.php start -d

如果你是在window下就双击start_for_win.bat运行

5.运行成功后,你就应该可以看到以下的界面

到此我们搭建基于workerman的通信环境就已经完成。接下来我们就可以根据自己的项目需求进行开发。在此向大家重点说明。我们所有的聊天是逻辑都在目录中的Events.php进行修改。

---------------------------------华丽分割线---------------------------------------------------

下面我给大家贴一下我编写的部分份代码。

Event.php

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
 * This file is part of workerman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link http://www.workerman.net/
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */
/**
 * 用于检测业务代码死循环或者长时间阻塞等问题
 * 如果发现业务卡死,可以将下面declare打开(去掉//注释),并执行php start.php reload
 * 然后观察一段时间workerman.log看是否有process_timeout异常
 */
//declare(ticks=1);
/**
 * 聊天主逻辑
 * 主要是处理 onMessage onClose
 */
use \GatewayWorker\Lib\Gateway;
class Events
{
  /**
   * 作者:何志伟
   * 当客户端连接上来的时候
   * 创建时间:2018/10/25
   * @param $client_id 此ID为gatewayworker 自动生成ID
   */
  public static function onConnect($client_id)
  {
    Gateway::sendToClient($client_id, json_encode(array(
      'type'   => 'init',
      'client_id' => $client_id
    )));
  }
  /**
   * 有消息时
   * @param int $client_id
   * @param mixed $message
   */
  public static function onMessage($client_id, $message)
  {
    // debug
    echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id session:".json_encode($_SESSION)." onMessage:".$message."\n";
    // 客户端传递的是json数据
    $message_data = json_decode($message, true);
    if(!$message_data)
    {
      return ;
    }
    // 根据类型执行不同的业务
    switch($message_data['type'])
    {
      // 客户端回应服务端的心跳
      case 'pong':
        return;
      // 客户端登录 message格式: {type:login, name:xx, room_id:1} ,添加到客户端,广播给所有客户端xx进入聊天室
      case 'login':
        // 判断是否有房间号
        if(!isset($message_data['room_id']))
        {
          throw new \Exception("\$message_data['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']} \$message:$message");
        }
        // 把房间号昵称放到session中
        $room_id = $message_data['room_id'];
        $client_name = htmlspecialchars($message_data['client_name']);
        $_SESSION['room_id'] = $room_id;
        $_SESSION['client_name'] = $client_name;
        // 获取房间内所有用户列表
        $clients_list = Gateway::getClientSessionsByGroup($room_id);
        foreach($clients_list as $tmp_client_id=>$item)
        {
          $clients_list[$tmp_client_id] = $item['client_name'];
        }
//        $clients_list[$client_id] = $client_name;
        // 转播给当前房间的所有客户端,xx进入聊天室 message {type:login, client_id:xx, name:xx}
        $new_message = array('type'=>$message_data['type'], 'client_id'=>$client_id, 'client_name'=>htmlspecialchars($client_name), 'time'=>date('Y-m-d H:i:s'),'to'=>$message_data['to'],'room_id'=>$message_data['room_id'],
          'from'=>$message_data['from'],'tag'=>$message_data['tag']);
        Gateway::sendToGroup($room_id, json_encode($new_message));
        Gateway::joinGroup($client_id, $room_id);
        // 给当前用户发送用户列表
        $new_message['client_list'] = $clients_list;
        Gateway::sendToCurrentClient(json_encode($new_message));
        return;
      // 客户端发言 message: {type:say, to_client_id:xx, content:xx}
      case 'say':
        // 非法请求
        if(!isset($_SESSION['room_id']))
        {
          throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
        }
        $room_id = $_SESSION['room_id'];
        $client_name = $_SESSION['client_name'];
        // 私聊
//        if($message_data['to_client_id'] != 'all')
//        {
//          $new_message = array(
//            'type'=>'say',
//            'from_client_id'=>$client_id,
//            'from_client_name' =>$client_name,
//            'to_client_id'=>$message_data['to_client_id'],
//            'content'=>"<b>对你说: </b>".nl2br(htmlspecialchars($message_data['content'])),
//            'time'=>date('Y-m-d H:i:s'),
//          );
//          Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message));
//          $new_message['content'] = "<b>你对".htmlspecialchars($message_data['to_client_name'])."说: </b>".nl2br(htmlspecialchars($message_data['content']));
//          return Gateway::sendToCurrentClient(json_encode($new_message));
//        }
        $new_message = array(
          'type'=>'say',
          'from_client_id'=>$client_id,
          'from_client_name' =>$client_name,
          'to_client_id'=>'all',
          'content'=>nl2br(htmlspecialchars($message_data['content'])),
          'time'=>date('Y-m-d H:i:s'),
        );
        return Gateway::sendToGroup($room_id ,json_encode($new_message));
    }
  }
  /**
   * 当客户端断开连接时
   * @param integer $client_id 客户端id
   */
  public static function onClose($client_id)
  {
    // debug
    echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id onClose:''\n";
    // 从房间的客户端列表中删除
    if(isset($_SESSION['room_id']))
    {
      $room_id = $_SESSION['room_id'];
      $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s'));
      Gateway::sendToGroup($room_id, json_encode($new_message));
    }
  }
}

客户端页面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>与{{$to->name}}的对话</title>
  <script type="text/javascript" src="{{asset('js')}}/swfobject.js"></script>
  <script type="text/javascript" src="{{asset('js')}}/web_socket.js"></script>
  <script type="text/javascript" src="{{asset('js')}}/jquery.min.js"></script>
  <link href="{{asset('css')}}/jquery-sinaEmotion-2.1.0.min.css" rel="external nofollow" rel="stylesheet">
  <link href="{{asset('css')}}/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
  <link href="{{asset('css')}}/style.css" rel="external nofollow" rel="stylesheet">
  <script type="text/javascript" src="{{asset('js')}}/jquery-sinaEmotion-2.1.0.min.js"></script>
  {{--<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>--}}
</head>
<style>
  #sinaEmotion {
    z-index: 999;
    width: 373px;
    padding: 10px;
    display: none;
    font-size: 12px;
    background: #fff;
    overflow: hidden;
    position: absolute;
    border: 1px solid #e8e8e8;
    top: 100px;
    left: 542.5px;
  }
</style>
<body onload="connect();" style="margin: auto; text-align: center;">
<div style="margin: auto;">
  <div style="border: 1px solid red; height: 40px; width: 500px; margin: auto;">
    {{--对话窗口头部--}}
    <div>
      <div style="width: 80px; height: 40px; border: 1px solid blue; float: left">
        <img src="{{$to->heading}}" width="80px" height="40px">
      </div>
      <div style="width: 150px; height: 40px; border: 1px solid blue; float: left">
        {{$to->name}}
      </div>
    </div>
    {{--//对话窗口内容--}}
    <div class="content" style="width: 500px; height: 400px; border: 1px solid green; margin-top: 40px; overflow-y: auto">
      {{--对方的头像与文字--}}
      {{--<div style="min-height: 50px;margin-top: 10px;">--}}
        {{--<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: left">--}}
          {{--<img src="{{$to->heading}}" width="50px" height="50px">--}}
        {{--</div>--}}
        {{--<div style="border: 1px solid red; float: left; min-height: 50px" >dsadsadsadsadsa</div>--}}
      {{--</div>--}}
      {{--我的头像与文字--}}
      {{--<div style= "min-height:50px;margin-top: 10px;">--}}
        {{--<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: right">--}}
          {{--<img src="{{$from->heading}}" width="50px" height="50px">--}}
        {{--</div>--}}
        {{--<div style="border: 1px solid red; float: right; min-height: 50px" >dsadsadsadsadsa</div>--}}
      {{--</div>--}}
    </div>
    {{--对话发送窗口--}}
    <form onsubmit="return onSubmit(); return false;" id="ajaxfrom">
      <input type="hidden" name="to" value="{{$to->id}}">
      <input type="hidden" name="from" value="{{$from->id}}">
      <input type="hidden" name="room_id" value="{{$room}}">
      <input type="hidden" name="tag" value="{{$tag}}">
      <textarea id="textarea" name="content" class="Input_text" style="margin: 0px; width: 501px; height: 213px;"></textarea>
      <div class="say-btn">
        <input type="button" class="btn btn-default face pull-left" value="表情" />
        <button type="submit" class="btn btn-default">发表</button>
      </div>
    </form>
    房间号{{$room}}
  </div>
</div>
</body>
</html>
<script type="text/javascript">
  if (typeof console == "undefined") {  this.console = { log: function (msg) { } };}
  // 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
  WEB_SOCKET_SWF_LOCATION = "/swf/WebSocketMain.swf";
  // 开启flash的websocket debug
  WEB_SOCKET_DEBUG = true;
  var ws, name, client_list={};
  var to_client_id="";
  // 连接服务端初始化函数
  function connect() {
    // 创建websocket 届时可以替换为对应的服务器地址
    ws = new WebSocket("ws://"+document.domain+":7272");
    // 当socket连接打开时,输入用户名
    ws.onopen = onopen;
    // 当有消息时根据消息类型显示不同信息
    ws.onmessage = onmessage;
    //当连接丢失时,调用连接方法尝试重新连接
    ws.onclose = function() {
      console.log("连接关闭,定时重连");
      connect();
    };
    //当操作报错时,返回异常错误
    ws.onerror = function() {
      console.log("出现错误");
    };
    //发送ajax获取当前房间的通话记录
    $.post("/get_record", { "room":"{{$room}}" },
      function(msg){
        $.each(msg,function (v,k) {
          console.log(k);
          //判断
          if(k.tag!="{{$tag}}"){
            $(".content").append(
              '<div style="min-height: 50px;margin-top: 10px;">' +
              '<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: left">'+
              '<img src="{{$to->heading}}" width="50px" height="50px">'+
              '</div>'+
              '<div style="border: 1px solid red; float: left; min-height: 50px" >'+k.content+'</div>'+
              '<div>'
            ).parseEmotion();
          }else{
            $(".content").append(
              '<div style="min-height: 50px;margin-top: 10px;">' +
              '<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: right">'+
              '<img src="{{$from->heading}}" width="50px" height="50px">'+
              '</div>'+
              '<div style="border: 1px solid red; float: right; min-height: 50px" >'+k.content+'</div>'+
              '<div>'
            ).parseEmotion();
          }
        })
      });
  }
  // 连接建立时发送登录信息
  function onopen()
  {
    var login_data='{"type":"login","client_name":"{{$from->name}}","room_id":"{{$room}}","to":"{{$to->id}}","from":"{{$from->id}}","tag":"{{$tag}}"}';
    ws.send(login_data);
    console.log('登录成功')
  }
  // 服务端发来消息时
  function onmessage(e)
  {
    var data = JSON.parse(e.data);
    switch(data['type']){
      // 服务端ping客户端心跳
      case 'ping':
        ws.send('{"type":"pong"}');
        break;
      // 登录 更新用户列表
      case 'login':
        //讲需要的发送ID保存到本地to_client_id变量中
        for(var p in data['client_list']){
          to_client_id=p;
        }
        console.log(to_client_id);
        break;
      // 发言
      case 'say':
        console.log(data);
        say(data['from_client_id'], data['from_client_name'], data['content'], data['time']);
        break;
      // 用户退出 更新用户列表
      case 'logout':
        console.log(data);
        break;
      case 'init':
        //此处可以发送ajax用于绑定不同的用户ID和client
        console.log(data);
        break;
    }
  }
  // 提交对话
  function onSubmit() {
    //先检查当前的对话是否超过20条记录数
    var count=true;
    //发送ajax获取当前房间的通话记录
    $.ajax({
      url: "/check_count",
      type: "post",
      async:false,
      // cache: false,
      // contentType: false,
      // processData: false,
      data:{
      'room':"1",
      },
      success: function (msg) {
        if(msg>10){
          alert('当前的对话已经超过次数,请购买对应服务')
          count=false;
        }
      }
    });
    if(count){
      var neirong=$("#textarea").val().replace(/"/g, '\\"').replace(/\n/g,'\\n').replace(/\r/g, '\\r');
      //ajax先把对应的内容发送到后台录入,回调成功后才把信息发送
      var fm=$("#ajaxfrom")[0];
      var formData = new FormData(fm);
      $.ajax({
        url: "/record",
        type: "post",
        cache: false,
        contentType: false,
        processData: false,
        data: formData,
        beforeSend:function(){
        },
        success: function (msg) {
          if(msg.code=="0"){
            ws.send('{"type":"say","to_client_id":"all","to_client_name":"{{$to->name}}","content":"'+neirong+'"}');
            //清空文本框内容
            $("#textarea").val("");
            //强制定位光标
            $("#textarea").focus();
          }else{
          }
        }
      });
    }
    return false;
  }
  // 发言
  function say(from_client_id, from_client_name, content, time){
    //判断当前的用户名称与发送消息的名称是否一致
    if( "{{$from->name}}" == from_client_name){
      $(".content").append(
        '<div style="min-height: 50px;margin-top: 10px;">' +
        '<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: right">'+
        '<img src="{{$from->heading}}" width="50px" height="50px">'+
        '</div>'+
        '<div style="border: 1px solid red; float: right; min-height: 50px" >'+content+'</div>'+
        '<div>'
      ).parseEmotion();
    }else{
      $(".content").append(
        '<div style="min-height: 50px;margin-top: 10px;">' +
        '<div style="width: 50px;height: 50px; border: 1px solid red; margin-left:10px; float: left">'+
        '<img src="{{$to->heading}}" width="50px" height="50px">'+
        '</div>'+
        '<div style="border: 1px solid red; float: left; min-height: 50px" >'+content+'</div>'+
        '<div>'
      ).parseEmotion();
    }
    // $("#dialog").append('<div class="speech_item"><img src="http://lorempixel.com/38/38/?'+from_client_id+'" class="user_icon" /> '+from_client_name+' <br> '+time+'<div style="clear:both;"></div><p class="triangle-isosceles top">'+content+'</p> </div>').parseEmotion();
  }
  $(function(){
    //全局用户ID
    select_client_id = 'all';
    //如果发送的用户有变化则对应的用户ID进行替换
    $("#client_list").change(function(){
      select_client_id = $("#client_list option:selected").attr("value");
    });
    //表情选择
    $('.face').click(function(event){
      $(this).sinaEmotion();
      event.stopPropagation();
    });
  });
  // document.write('<meta name="viewport" content="width=device-width,initial-scale=1">');
  $("textarea").on("keydown", function(e) {
    //按enter键自动提交
    if(e.keyCode === 13 && !e.ctrlKey) {
      e.preventDefault();
      $('form').submit();
      return false;
    }
    // 按ctrl+enter组合键换行
    if(e.keyCode === 13 && e.ctrlKey) {
      $(this).val(function(i,val){
        return val + "\n";
      });
    }
  });
</script>

转载于:https://www.cnblogs.com/janera/p/10016768.html

相关文章:

复杂系统设计 企业开发的困境

复杂系统设计源自我多年对企业复杂系统的设计的一些思考&#xff0c;类似日记吧&#xff0c;不断完善。 为什么从一个大公司的引入架构师甚至架构师组还是很难架构企业开发中的很多问题&#xff1f; 这些问题表现出架构上的复杂性&#xff0c;和业务上的复杂性。 有时候架构…

数据库服务器跟网站服务器间传输慢的问题

数据库服务器和网站服务器是分开的&#xff0c;现在从网站服务器这边查数据比较慢&#xff0c;什么原因&#xff1f;&#xff1f;&#xff1f; 一、首先确定服务器之间的网络有没有问题 可以简单的在网站服务器上ping数据库服务器&#xff08;反过来也可以&#xff09;&#xf…

【Python】百度贴吧图片的爬虫实现(努力努力再努力)

学会爬取图片以后&#xff0c;第一时间去了张艺兴吧&#xff0c;哈哈哈哈哈哈 一定要放上一张爬取的照片&#xff0c;哼唧 import reimport requestsimport urllibclass Baidutieba():def __init__(self):self.url "http://tieba.baidu.com/p/4876047826?pn{}"#u…

cin、cout的重载

一、cin重载 1.cin为ostream类的成员 2.cin重载应为全局函数&#xff08;毕竟ostream是别人写好的&#xff09; 3.代码 a.核心代码 ostream & operator<<(ostream &os,const A &a)//const A &a是为了避免复制函数的调用 &#xff1b;ostream &o 相当…

第二次冲刺第十天

第二次冲刺今天就结束了&#xff0c;这十天来学会了不少的东西。 简单说一下昨天做的&#xff1a;整合各个部件的功能。 今天&#xff1a;小组进行总结&#xff0c;加强性能。 这十天来遇到的问题&#xff1a; 一&#xff0c;对于网络云端&#xff0c;之前都是其他小组成员在使…

说透泛型类和泛型方法以及Class<T>和Class<?>的差异

泛型类和泛型方法看起来似乎可以实现类似的功能&#xff0c;但是很多人并未真正掌握泛型方法&#xff0c;网上很多文章说了很多还是似是而非&#xff0c;特别是初学者还是搞不明白。 一.关于泛型方法 1.泛型方法可以独立于泛型类 2.泛型方法等效于泛型类里泛型参数方法&…

win10 +python 3.6.4安装scrapy

第一步&#xff1a; 首先&#xff0c;我们先在电脑上安装好python3.6并且配置好环境变量&#xff0c;以可以直接在命令行界面输入python命令可以出现如图的界面为主。 第二步&#xff1a; 升级pip &#xff0c;在cmd窗口中会有提示&#xff0c;没有提示的话就已经是最新版本了…

7 种 Javascript 常用设计模式学习笔记

7 种 Javascript 常用设计模式学习笔记 由于 JS 或者前端的场景限制&#xff0c;并不是 23 种设计模式都常用。 有的是没有使用场景&#xff0c;有的模式使用场景非常少&#xff0c;所以只是列举 7 个常见的模式 本文的脉络&#xff1a; 设计与模式5 大设计原则 7 种常见的设计…

从难免的线上bug说起代码的思考

经常是某司线上又出bug了&#xff0c;然后是给公司造成多少损失&#xff0c;追根究底总是可以找到一些原因&#xff0c;诸如&#xff1a;写代码逻辑考虑不全面&#xff0c;或者代码有硬伤&#xff0c;也有测试不充分&#xff0c;甚至不测试都有&#xff0c;也有是运维的问题等等…

PHP-Fpm应用池配置

//php.net php-fpm配置简介http://php.net/manual/zh/install.fpm.configuration.php//Global Options//pool defined[www]user nobodygroup nobodylisten 127.0.0.1:9000pm dynamicpm.max_children 5pm.start_servers 2pm.min_spare_servers 1pm.max_spare_servers 3s…

【Python】百度首页GIF动画的爬虫

今天百度首页的GIF动画很可爱&#xff0c;就想着用才学的爬虫爬取一下&#xff0c;虽然直接点击“图片另存为”就可以了 import requestsimport urllibclass Gif():def __init__(self):self.url "https://www.baidu.com/"self.headers {"User-Agent": …

CSS题目系列(3)- 实现文字切割效果

描述 有一天逛 Codepen 的时候&#xff0c;看到这么一个效果&#xff1a;将文字上下切开两半。 点进去看了一下代码&#xff0c;发现原理很简单&#xff0c;大概就是通过伪类使用attr()函数获取内容&#xff0c;然后进行定位。 你可以点下方链接查看效果&#xff1a; gd4ark.gi…

Java开发字符串JSON处理

需求很简单就是数据库存json。 数据库字段 varchar 入参request 定义 List<String> 如果不定义这个 而是定义String那么需要加"/转义比较难看 这样就只要入参传这个就行了&#xff1a; "xxxIds": ["33","44"], 数据库也是…

1.JSONObject与JSONArray的使用

参考文献&#xff1a; http://blog.csdn.net/huangwuyi/article/details/5412500 1.JAR包简介 要使程序可以运行必须引入JSON-lib包&#xff0c;JSON-lib包同时依赖于以下的JAR包&#xff1a; commons-lang.jarcommons-beanutils.jarcommons-collections.jarcommons-logging.ja…

【Python】Scrapy爬虫实战(豆瓣电影 Top 250)

今天一天都在弄Scrapy&#xff0c;虽然爬虫起来真的很快&#xff0c;很有效率&#xff0c;但是......捣鼓了一天 豆瓣电影 Top 250&#xff1a;https://movie.douban.com/top250 安装好的scrapy 在你想要的文件夹的目录下输入命令&#xff1a; scrapy startproject douban_m…

vmrun 批量创建vmware虚拟机

1 准备模板机 具体步骤如下&#xff1a; 1. 下载镜像安装系统 https://mirrors.aliyun.com/centos/7.5.1804/isos/x86_64/2. 安装完成配置好IP &#xff0c;关闭SELINUX ,关闭firewalld ,修改网卡名 3. 预设置好修改其他机器IP脚本 1.1 安装系统 略 1.2 模板机的设置 修改网卡名…

暗时间:开发效率为何如此低下

产品 开发 测试 三者都理解不一致。 产品怎么样表达出自己的诉求&#xff0c;是否写清文档就够了。 开发觉得自己沟通了&#xff0c;但是为什么测试一提测又许多问题。 测试的case看似都一起评审了。 而这样的结果必然是重新修修补补&#xff0c;怎么样事前把问题全部解…

【Python】Scrapy爬虫实战(传智播客老师简介)

在文件夹里创建一个爬虫项目 scrapy startproject ITcast 在spiders目录下&#xff1a; scrapy genspider itcast ------------------------------------------------------------------------------------------------------------------------------------------------------…

坑系列 --- 高可用架构的银弹

呵呵&#xff0c;题图是一队困在坑中的鸭子&#xff1a;&#xff09;作为一个搬砖的&#xff0c;我经常被困着。今天高考&#xff0c;想起15年前的今天&#xff08;哦&#xff0c;那时候是七月高考&#xff09;&#xff0c;恩&#xff0c;考完了&#xff0c;还不错&#xff0c;…

【TeeChart Pro ActiveX教程】(八):ADO数据库访问(上)

2019独角兽企业重金招聘Python工程师标准>>> 下载TeeChart Pro ActiveX最新版本 介绍 将TeeChart控件连接到ADO.NET数据库可以在设计时使用TeeChart编辑器完成&#xff0c;并在运行时使用几行代码完成。 任何Series都可以使用TeeChart Editor连接到ADO.NET表或查询。…

代码规范碎碎念

代码规范碎碎念 list条件多于2不要写命名上 controller (model-DTO) service (model) repository层 语义化构造 (entity->model) String转map 语义化数据结构 String转model 从数据库层增强语义 组装模型 DAO ( entity) mapper VO(admin) DTO(client) -------…

RRDTool原理简介

1.概述 RRDtool 代表 “Round Robin Database tool” &#xff0c;作者同时也是 MRTG 软件的发明人。官方站点位于http://oss.oetiker.ch/rrdtool/ 。 所谓的“Round Robin” 其实是一种存储数据的方式&#xff0c;使用固定大小的空间来存储数据&#xff0c;并有一个指针指向最…

【Python】Scrapy爬虫实战(腾讯社会招聘职位检索)

爬虫网页&#xff1a;https://hr.tencent.com/position.php 应用Scrapy框架&#xff0c;具体步骤就不详细说明&#xff0c;前面几篇Scrapy有一定的介绍 因为要涉及到翻页&#xff0c;下面的代码使用拼接的方式获取url&#xff0c;应用在一些没办法提取下一页链接的情况下 直…

一对一直播app源码功能操详解方案分享

一&#xff1a;登录页面&#xff1a;1.快捷登录&#xff1a;可以利用第三方账号进行快捷登录2.手机登录&#xff1a;可以让用户通过输入手机号码和密码进行登录.3.注册&#xff1a;可以使用手机号获取验证码注册账号二&#xff1a;打开一对一直播APP首页打开APP&#xff0c;会显…

从一个需求看问题的无限复杂化和简单化

一个需求 如果你一开始的出发点就错了&#xff0c;那么后续的设计只会非常复杂&#xff0c;而且还会有漏洞&#xff0c;也很难发现&#xff0c;发现了也很难解决。 先看数据结构&#xff1a; A表 主键id 其他各种字段不重要 &#xff0c;重要的就一个字段sort字段 aid1 …

使用自定义材质球,实现NGUI屏幕溶解和灰显

UITexture实现的溶解&#xff1a; 重设UITeture的材质球实现上述效果&#xff0c;把当前屏幕渲染的Texture2D丢给UITexture&#xff0c;即可实现UI屏幕特效&#xff0c;背景模糊等都可以。 难点主要是实时刷新问题 解决的比较粗暴&#xff0c;每次Update重设材质球&#xff0c;…

【Python】Tkinter 体验

import tkinter as tk root tk.Tk() root.title("work hard") #添加一个Label组件&#xff0c;Label组件是GUI程序中最常用的组件之一 #Label组件可以显示文本&#xff0c;图标或图片 #在这里我们让它显示指定文本 theLabel tk.Label(root,text"努力努力再努力…

debian手动安装java两种方法

2019独角兽企业重金招聘Python工程师标准>>> 方法一&#xff1a;下载后修改~/.bashrc文件 方法二&#xff1a;使用update-alternatives进行命令安装 相关配置记录 法一&#xff1a; 官网下载压缩包&#xff0c;解压&#xff0c;然后复制到/usr/lib/jvm目录下&#x…

【Python】Label组件 Button组件 Checkbutton组件

Label组件 Label组件是用于在界面上输出描述的标签。 #导入tkinter模块所有内容 from tkinter import *#创建一个主窗口&#xff0c;可以容纳整个GUI程序 root Tk() root.title("hhh")textLabel Label(root,text"努力努力再努力&#xff01;\n努力努力再努力…

大厂线上案例复盘--代码漏洞

万无一失却实际上是形同虚设的代码逻辑漏洞 这是一则发生在某大厂的真实案例&#xff0c;出于脱敏名字这且不说。 这个系统因为第一次上线&#xff0c;流量非常的大。 所以需要灰度上线&#xff0c;所谓灰度方案很短&#xff0c;比如按照地理位置&#xff0c;先选择某个访问量…