chengkun
2025-04-18 1bb985f32f2efe0f9dd69f3cf29a1c809b1cf96d
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?php
/*
 * $Author :沭云智鑫
 *
 * 官网: http://www.douxu.com
 *
 * 版权所有 2020-2020 南京沭云智鑫科技有限公司,并保留所有权利。
 *
 * 软件声明:未经授权前提下,不得用于商业运营、二次开发以及任何形式的再次发布。
 */
 
class concheck_model extends model
{
    private function addErrorLog($uid,$type='',$content) {
 
        require_once ('errlog.model.php');
 
        $ErrlogM = new errlog_model($this->db, $this->def);
 
        return  $ErrlogM -> addErrorLog($uid, $type, $content);
 
    }
    
    /**
     * 内容检测
     * @param string content 检测文本内容数组,或图片地址字符串
     * @param array  data 其他传参,type=pic为检测图片 ,source 来源
     * @return array
     */
    public function checkContent($content, array $data)
    {
        $return = [];
        $content_v = $content;
        $source = isset($data['source'])?$data['source']:'';
        $action = $data['action'];
        
        
        $open       =   $this->config['sy_concheck_open'];    
        $appkey     =   $this->config['sy_concheck_appkey'];
        $appsecret  =   $this->config['sy_concheck_appsecret'];
        
        if($open==1 && $appkey && $appsecret){
 
 
            if($source==11){
                $source = 1;
            }else if($source==12){
                $source = 2;
            }else if($source==14){
                $source = 13;
            }else if($source==15){
                $source = 3;
            }
 
            if (isset($data['type']) && $data['type'] == 'pic') {
 
                $url    =   'https://u.phpyun.com/imagecensor';
 
                $con_str = $content[0];
                
            } else {
 
                $url    =   'https://u.phpyun.com/textcensor';
 
                $con_str = '';
 
                foreach ($content as $key => $value) {
                    $con_str    .=  $value;
                }
            }
 
            $content_v = serialize($content_v);
            
            $search     =   array(" ", " ", "\n", "\r", "\t");
            $replace    =   array("", "", "", "", "");
            $con_str    =   str_replace($search, $replace, $con_str);
            
            if($source == 13 && $action=='chatlog'){
                //微信小程序的聊天走微信的内容检测
                require_once('xcx.model.php');
                $xcxM  =  new xcx_model($this->db,$this->def);
                $access_token = $xcxM->getWxxcxToken();
                
                if(isset($data['type']) && $data['type'] == 'pic'){
                    $url    =   'https://api.weixin.qq.com/wxa/img_sec_check?access_token='.$access_token;
 
                    $img = file_get_contents($con_str);
            
                    $filename  =  time().rand(1000,9999).'.jpeg';
                    //自定义目录名称
                    $dirName = APP_PATH.'data/upload/'. '/chat/' . date('Ymd');
                    //定义新名称以及目录
                    if (!file_exists($dirName)){
                        mkdir($dirName, 0777, true);
                    }
                    $filePath= $dirName . '/' . $filename;
                    
                    file_put_contents($filePath, $img);
 
                    $fobj    = new \CURLFile(realpath($filePath));
                    $fobj->setMimeType("image/jpeg");
                    $postdata['media'] = $fobj;
                }else{
 
                    $url    =   'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
                    $postdata   =   array(
                        'openid'    =>  $data['openid'],
                        'scene'     =>  4,
                        'version'   =>  2,
                        'content'   =>  $con_str
                    );
                    $postdata = json_encode($postdata);
                }
                
                $file_contents  =   CurlPost($url,$postdata);
 
                $res    =   json_decode($file_contents, true);
            
                $file_contents=[];
                
                $file_contents['code'] = $res['errcode'];
                $file_contents['msg'] = $res['errmsg'];
                
                if($res['errcode']==0){//内容正常
                    $file_contents['code'] = 200;
                    $file_contents['data']['conclusion_type']= 1;
                    $file_contents['data']['msg']= $res['errmsg'];
                    
                }
                
                $file_contents= json_encode($file_contents);
 
            }else{
                //其余走百度检测接口
                $url        .=  '?app_secret=' . $appsecret . '&app_key=' . $appkey . '&content=' . $con_str;
                
                $file_contents  =  CurlGet($url);
 
            }
            
            
 
            if ($file_contents) {
                if (isset($file_contents['curlerror'])) {
                    if ($file_contents['curlerror'] == 28) {
 
                        $return['code'] = 0;
                        $return['msg'] = '检测请求超时';
                    } else {
 
                        $return['code'] = 0;
                        $return['msg'] = '检测请求失败';
                    }
                    $errorLog = true;
                } else {
 
                    $res    =   json_decode($file_contents, true);
 
                    if ($res) {
                        if ($res['code'] == 200) {
 
                            $return['code'] =   isset($res['data']['conclusion_type']) ? $res['data']['conclusion_type'] : 0;
                            $return['msg']  =   isset($res['data']['msg']) ? $res['data']['msg'] : '';
                        } else {
                            $errorLog = true;
                            $return['code'] =   $res['code'];
                            $return['msg']  =   isset($res['msg']) ? $res['msg'] : '';
                        }
                    } else {
                        $errorLog = true;
                        $return['code']     =   0;
                        $return['msg']      =   '检测请求失败';
                    }
                }
            } else {
                $errorLog = true;
                $return['code']     =   0;
                $return['msg']      =   '检测请求失败';
            }
 
 
            $insertData = array(
                'uid'       =>  $data['uid'],
                'usertype'  =>  $data['usertype'],
                'type'      =>  $data['type'] == 'pic'?2:1,
                'ctype'     =>  $data['ctype'],
                'cid'       =>  $data['cid'],
                'content'   =>  $content_v,
                'source'    =>  $source ? $source : 1,
                'url'       =>  $_SERVER['REQUEST_URI'],
                'ctime'     =>  time(),
                'result'    =>  $return['code']=='1'?1:0,
                'message'   =>  $return['msg'],
                'status'    =>  $return['code']=='1'?2:0
            );
 
            $cid = $this->addLog($insertData);
            $return['cid'] = $cid;
            if($errorLog){
                $this->addErrorLog($data['uid'],11, $return['msg']);
            }
        }else{
            $return['code'] = 1;
        }
 
        return $return;
    }
 
    private function addLog($data=array()){
 
        $nid    =   $this -> insert_into("concheck_log", $data);
        
        return $nid;
    }
    public function upLog($whereData = array(), $upData = array(), $data = array()){
        $nid                        =   0;
        if (!empty($upData) && !empty($whereData)){
            $nid                    =   $this -> update_once('concheck_log', $upData, $whereData);
        }
        return $nid;
    }
    public function getLogList($whereData, $data = array()){
 
        $field  =  empty($data['field']) ? '*' : $data['field'];
        
        $List   =  $this -> select_all('concheck_log', $whereData, $field);
 
        if(!empty($List)){
            $uid_arr  = array();
            $ruid_arr = array();
            $cuid_arr = array();
            foreach ($List as $key => $val) {
 
                if($val['uid'] && $val['usertype']==1 && !in_array($val['uid'],$ruid_arr)){
                    $ruid_arr[] = $val['uid'];
                }
 
                if($val['uid'] && $val['usertype']==2 && !in_array($val['uid'],$cuid_arr)){
                    $cuid_arr[] = $val['uid'];
                }
 
                if($val['uid'] && !in_array($val['uid'],$uid_arr)){
                    $uid_arr[]  = $val['uid'];
                }
 
            }
 
            $rname_arr = array();
            $cname_arr = array();
            $mname_arr = array();
 
            if(!empty($ruid_arr)){
 
                $ResumeList =   $this -> select_all(
                    'resume',
                    array(
                        'uid'=>array('in',pylode(',',$ruid_arr))
                    ),
                    '`uid`,`name`'
                    );
 
                foreach ($ResumeList as $rk => $rv) {
                    $rname_arr[$rv['uid']] = $rv['name'];
                }
            }
 
            if(!empty($cuid_arr)){
 
                $ComList    =   $this -> select_all(
                    'company',
                    array(
                        'uid'=>array('in',pylode(',',$cuid_arr))
                    ),
                    '`uid`,`name`'
                    );
 
                foreach ($ComList as $ck => $cv) {
                    $cname_arr[$cv['uid']] = $cv['name'];
                }
            }
 
            if(!empty($uid_arr)){
 
                $MemList    =   $this -> select_all(
                    'member',
                    array(
                        'uid'=>array('in',pylode(',',$uid_arr))
                    ),
                    '`uid`,`username`'
                    );
 
                foreach ($MemList as $mk => $mv) {
                    $mname_arr[$mv['uid']] = $mv['username'];
                }
            }
 
            include(CONFIG_PATH."db.data.php");
 
            foreach ($List as $k => $v) {
 
                if($v['uid']){
 
                    $List[$k]['username'] = isset($mname_arr[$v['uid']]) ? $mname_arr[$v['uid']] : '<span style="color:red;">账号已删除</sapn>';
 
                    if($v['usertype']==1){
                        $List[$k]['name'] = isset($rname_arr[$v['uid']]) ? $rname_arr[$v['uid']] : '';
                    }
                    if($v['usertype']==2){
                        $List[$k]['name'] = isset($cname_arr[$v['uid']]) ? $cname_arr[$v['uid']] : '';
                    }
                }
 
                if($v['ctype']==1){
                    $List[$k]['ctype_n'] = '修改简历,简历ID('.$v['cid'].')';
                }elseif($v['ctype']==2){
                    $List[$k]['ctype_n'] = '修改职位,职位ID('.$v['cid'].')';
                }elseif($v['ctype']==3){
                    $List[$k]['ctype_n'] = '修改个人基本信息';
                }elseif($v['ctype']==4){
                    $List[$k]['ctype_n'] = '修改企业基本信息';
                }elseif($v['ctype']==5){
                    $List[$k]['ctype_n'] = $this->config['sy_chat_name'];
                }
 
                $con_arr = unserialize($v['content']);
 
                if($v['type']==1){//文字
                    
                    $body_html                  =   '';
 
                    foreach($con_arr as $conk=>$conv){
                        $con_html = '';
                        if(is_numeric($conk)){
                            $con_html = $conv.'</br>';
                        }else{
                            $con_html = $conk.':'.$conv.'</br>';
                        }
                        $body_html .= $con_html;
                    }
                    $List[$k]['content_n']     =   $body_html;
                }else if($v['type']==2){//图片
                    $List[$k]['content_n'] = checkpic($con_arr[0]);
                }
 
                if($v['ctime']){
                    $List[$k]['ctime_n']     =   date('Y-m-d H:i:s');
                }
                if($v['source']){
                    
                    $List[$k]['source_n'] = $arr_data['source'][$v['source']];
                }
            }
        }
 
        return $List;
    }
    function getInfo($whereData,$data=array()){
        
        $field  =   empty($data['field']) ? '*' : $data['field'];
        if (!empty($whereData)) {
            
            $List  =  $this -> select_once('concheck_log',$whereData, $field);
            return $List;
        }
    }
 
    public function delConCheck($id,$data=array()){
        if(!empty($id)){
            if(is_array($id)){
 
                $ids                    =   $id;    
                $return['layertype']    =   1;   
            }else{
 
                $ids                    =   @explode(',', $id);
                $return['layertype']    =   0;
            }
            $id             =   pylode(',', $ids);
 
            $return['id']   =   $this -> delete_all('concheck_log',array('id' => array('in',$id)),'');
            
            if($return['id']){
 
                $return['msg']      =  '内容安全检测(ID:'.$id.')删除成功';
                $return['errcode']  =  '9';
            }else{
                
                $return['msg']      =  '内容安全检测(ID:'.$id.')删除失败';
                $return['errcode']  =  '8';
            }
        }else{
            
            $return['msg']          =  '系统繁忙';
            $return['errcode']      =  '8';
            $return['layertype']    =   0;
        }
 
        return $return;
    }
    public function statusConCheck($id, $upData = array())
    {
 
        $ids    =   @explode(',', trim($id));
 
        $return =   array('msg' => '非法操作!', 'errcode' =>  8);
 
        if (!empty($id)) {
 
            $idstr      =   pylode(',', $ids);
 
            $upData     =   array(
 
                'status'        =>  intval($upData['status']),
                'statusbody'    =>  trim($upData['statusbody']),
            );
 
            $result     =   $this -> update_once('concheck_log', $upData, array('id' => array('in', $idstr)));
 
            if ($result) {
 
                $return['msg']      =  '内容检测处理状态(ID:'.$idstr.')设置成功';
                $return['errcode']  =  9;
 
            }else{
 
                $return['msg']      =  '内容检测处理状态(ID:'.$idstr.')设置失败';
                $return['errcode']  =  8;
            }
 
        }else {
 
            $return['msg']          =   '请选择需要处理的内容检测!';
            $return['errcode']      =   8;
        }
 
        return $return;
    }
}