chengkun
2025-05-23 a6f7b382623096b6a00924f418447cf5204e825e
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
<?php
 
class trtc_model extends model{
 
    /**
     * 获取进视频面试房间参数
     */
    function getUserSig($data = array()){
        
        $return  =  array();
        
        if (!empty($data['uid'])){
            
            $trtc  =  $this->select_once('trtc', array('uid'=>$data['uid']));
            
            if(!empty($trtc) && $trtc['extime'] > 0 && $trtc['extime'] > time()){
                
                if (!empty($trtc['roomid']) && $data['usertype'] == 2){
                    // 企业用户有自己的房间号
                    $roomid  =  $trtc['roomid'];
                    $wid     =  $trtc['wid'];
                }else{
                    // 个人用户要查对方的房间号
                    $fuser   =  $this->select_once('trtc', array('uid'=>$data['fuid']));
                    
                    if (!empty($fuser)){
                        
                        $roomid  =  $fuser['roomid'];
                        $wid     =  $fuser['wid'];
                        
                    }else{
                        
                        // 对方没有数据,需重新查询
                        $ndata['uid']       =  $data['fuid'];
                        $ndata['usertype']  =  2;
                        
                        $result  =  $this->getRoomInfo($ndata);
                        
                        if (!empty($result['errcode'])){
                            
                            return $result;
                        }
                        $roomid  =  $result['roomid'];
                        $wid     =  $result['sarr']['wid'];
                    }
                }
                
                $return  =  array('usersig'=>$trtc['usersig'], 'appid'=> $trtc['appid'], 'roomid'=>$roomid, 'csroomid'=>$trtc['roomid'], 'wid'=>$wid);
                
            }else{
                
                $result  =  $this->getRoomInfo($data);
                
                if (!empty($result['errcode'])){
                    
                    return $result;
                }
                $sarr    =  $result['sarr'];
                
                $return  =  array('usersig'=>$sarr['usersig'],'appid'=>$sarr['appid'], 'roomid'=>$result['roomid'], 'csroomid'=>$sarr['roomid'], 'wid'=>$sarr['wid']);
            }
        }
        return $return;
    }
    /**
     * 从都需上查询视频面试房间信息
     */
    private function getRoomInfo($data = array()){
        
        if (!empty($this->config['sy_spview_appkey']) && !empty($this->config['sy_spview_appsecret'])){
            
            $postjson['buid']       =  $data['uid'];
            $postjson['appKey']     =  $this->config['sy_spview_appkey'];
            $postjson['appSecret']  =  $this->config['sy_spview_appsecret'];
            
            $url  =  'https://trtc.phpyun.com/zphnetv/index.php?m=trtc&c=getUserSig';
            
            $result      =     CurlPost($url,$postjson);
            $reponse  =     json_decode($result, true);
            
            if (empty($reponse['data'])){
                
                return array('errcode'=>8,'msg'=>$reponse['msg']);
            }
            $douxu    =  $reponse['data'];
            
        }else{
            
            return array('errcode'=>8,'msg'=>'视频面试秘钥未配置');
        }
        
        $sarr     =  array(
            'uid'      =>  $data['uid'],
            'usersig'  =>  $douxu['code'],
            'extime'   =>  $douxu['expire'],
            'appid'    =>  $douxu['appid'],
            'roomid'   =>  $douxu['roomid'],
            'wid'      =>  $douxu['wid']
        );
        
        if ($data['usertype'] == 2){
            // 企业用户有自己的房间号
            $roomid  =  $douxu['roomid'];
            
        }else{
            // 个人用户要查对方的房间号
            $fuser   =  $this->select_once('trtc', array('uid'=>$data['fuid']));
            
            if (!empty($fuser)){
                // 对方已有数据
                $roomid  =  $fuser['roomid'];
                
            }else{
                // 对方没有数据,需重新查询
                $ndata['uid']       =  $data['fuid'];
                $ndata['usertype']  =  2;
                
                $result  =  $this->getRoomInfo($ndata);
                
                if (!empty($result['errcode'])){
                    
                    return $result;
                }
                $roomid  =  $result['roomid'];
            }
        }
        
        if (!empty($trtc)){
            
            $this->update_once('trtc', $sarr, array('id'=>$trtc['id']));
            
        }else{
            
            $this->insert_into('trtc', $sarr);
        }
        return array('sarr'=>$sarr, 'roomid'=>$roomid);
    }
    /**
     * 查询视频面试房间所需参数
     * @param array $data
     * @param string $codePlat
     */
    function getTrcInfo($data = array(), $needRtc = false, $codePlat = ''){
        
        // 查询对方数据
        if ($data['usertype'] == 1){
            
            $info  =  $this->select_once('company', array('uid'=>$data['fuid']), '`uid`,`name`,`shortname`,`logo`');
            
            $return  =  array(
                'name'    =>  !empty($info['shortname']) ? $info['shortname'] : $info['name'],
                'logo'    =>  checkpic($info['logo'], $this->config['sy_unit_icon'])
            );
        }else{
            
            $info  =  $this->select_once('resume', array('uid'=>$data['fuid']), '`uid`,`name`,`sex`,`photo`');
            
            $base    =  $info['sex'] == 1 ? $this->config['sy_member_icon'] : $this->config['sy_member_iconv'];
            $return  =  array(
                'name'    =>  $info['name'],
                'logo'    =>  checkpic($info['photo'], $base)
            );
        }
        
        // app 里面还要查自己的数据
        if ($codePlat == 'app'){
            
            // 查询对方信息
            if ($data['usertype'] == 2){
                
                $minfo  =  $this->select_once('company', array('uid'=>$data['uid']), '`name`,`shortname`,`logo`');
                
                $return['myname']  =  !empty($minfo['shortname']) ? $minfo['shortname'] : $minfo['name'];
                $return['mylogo']  =  checkpic($minfo['logo'], $this->config['sy_unit_icon']);
                
            }else{
                
                $minfo  =  $this->select_once('resume', array('uid'=>$data['uid']), '`name`,`sex`,`photo`');
                
                $mbase  =  $minfo['sex'] == 1 ? $this->config['sy_member_icon'] : $this->config['sy_member_iconv'];
                $return['myname']  =  $minfo['name'];
                $return['mylogo']  =  checkpic($minfo['photo'], $mbase);
            }
        }
        if ($needRtc){
            
            $trtc   =  $this->getUserSig(array('uid'=>$data['uid'], 'fuid'=>$info['uid'], 'usertype'=>$data['usertype']));
            
            if (!empty($trtc['appid'])){
                
                $return['sdkAppId']   =  $trtc['appid'];
                $return['userSig']    =  $trtc['usersig'];
                $return['roomId']     =  $trtc['roomid'];
                $return['commentID']  =  $trtc['wid'] .'_'.$info['uid'];
                $return['userId']     =  $trtc['wid'] .'_'.$data['uid'];
                $return['spWait']     =  $this->config['sy_spview_wait'];
                $return['spLong']     =  $this->config['sy_spview_time'];
                
            }else{
                
                $return  =  $trtc;
            }
        }
        
        return $return;
    }
    /**
     * 通过接口查询是否可以视频面试
     */
    function trtcCanAdd(){
        
        if (!empty($this->config['sy_spview_appkey']) && !empty($this->config['sy_spview_appsecret'])){
            
            $postjson['appKey']     =  $this->config['sy_spview_appkey'];
            $postjson['appSecret']  =  $this->config['sy_spview_appsecret'];
            
            $url  =  'https://trtc.phpyun.com/zphnetv/index.php?m=trtc&c=canAdd';
            
            $result      =     CurlPost($url,$postjson);
            $reponse  =     json_decode($result, true);
            
            if (empty($reponse['data'])){
                
                return array('errcode'=>8,'msg'=>$reponse['msg']);
            }
            return $reponse['data'];
            
        }else{
            
            return array('errcode'=>8,'msg'=>'视频面试秘钥未配置');
        }
    }
}
?>