load->model('receiver/receiver_call_model', 'callModel'); $this->load->model('receiver/receiver_call_wechat_model', 'callWechat'); $this->load->model('receiver/receiver_customers_model', 'customers_model'); $this->load->model('app/licheb/app_licheb_users_model', 'app_user_model'); $this->load->model('receiver/receiver_customer_oplogs_model'); $this->load->model('sys/sys_admin_model'); $this->load->library('carHome/callOutWechat'); $this->load->library('qiniu'); } /** * 好车补推送回调 * @return void */ public function index() { $logPath = "callBack.log"; //接收json 数据 $post = $this->input->post(); debug_log("post: " . json_encode($post, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); $json = file_get_contents('php://input'); debug_log("json: " . $json, $logPath, $this->logDir); $data = $json ? json_decode($json, true) : []; try { //处理业务逻辑 if (!$data || !$data['requestId']) { throw new Exception('参数错误'); } $row = $this->callModel->get(['reqId' => $data['requestId']]); if (!$row) { throw new Exception('拨号记录不存在'); } $callData = $data['calldata']; $upData = [ 'sessionId' => $callData['sessionId'] ?: '', 'agentId' => $callData['agentId'] ?: '', 'agentUm' => $callData['agentUm'] ?: '', 'agentPhoneNo' => $callData['agentPhoneNo'] ?: '', 'customerPhoneNo' => $callData['customerPhoneNo'] ?: '', 'agentDispNo' => $callData['agentDispNo'] ?: '', 'customerDispNo' => $callData['customerDispNo'] ?: '', 'voiceId' => $callData['voiceId'] ?: '', 'finishType' => $callData['finishType'], 'callType' => $callData['callType'], 'hangupType' => $callData['hangupType'], 'status' => Receiver_call_wechat_model::STATUS_FINISH, 'telDuration' => $callData['telDuration'] ?: 0, 'ringDuration' => $callData['ringDuration'] ?: 0, 'apiResult' => $json ]; $callData['startTime'] && $upData['startTime'] = $callData['startTime']; $callData['endTime'] && $upData['endTime'] = $callData['endTime']; $this->callModel->update($upData, ['id' => $row['id']]); } catch (Exception $e) { debug_log("错误信息: " . $e->getMessage(), $logPath, $this->logDir); } $data = ['code' => 200, 'msg' => '成功', 'data' => []]; $this->output ->set_content_type('application/json') ->set_output(json_encode($data, JSON_UNESCAPED_UNICODE)); } /** * 拨打电话回调(sadmin后台和小程序) * @return void */ public function app() { $logPath = "callBackApp.log"; //接收json 数据 $post = $this->input->post(); debug_log("post: " . json_encode($post, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); $json = file_get_contents('php://input'); debug_log("json: " . $json, $logPath, $this->logDir); $data = $json ? json_decode($json, true) : []; try { //处理业务逻辑 if (!$data || !$data['requestId']) { throw new Exception('参数错误'); } $row = $this->callWechat->get(['reqId' => $data['requestId']]); if (!$row) { throw new Exception('拨号记录不存在'); } $callData = $data['calldata']; $upData = [ 'orderId' => $callData['orderId'] ?: '', 'sessionId' => $callData['sessionId'] ?: '', 'agentId' => $callData['agentId'] ?: '', 'agentPhoneNo' => $callData['agentPhoneNo'] ?: '', 'customerPhoneNo' => $callData['customerPhoneNo'] ?: '', 'agentDispNo' => $callData['agentDispNo'] ?: '', 'customerDispNo' => $callData['customerDispNo'] ?: '', 'voiceId' => $callData['voiceId'] ?: '', 'finishType' => $callData['finishType'], 'callType' => $callData['callType'], 'hangupType' => $callData['hangupType'], 'recordpath' => $callData['recordpath'] ?: '', 'status' => Receiver_call_wechat_model::STATUS_FINISH, 'apiResult' => $json ]; $callData['agentRingTime'] && $upData['agentRingTime'] = $callData['agentRingTime']; $callData['agentAnswerTime'] && $upData['agentAnswerTime'] = $callData['agentAnswerTime']; $callData['userRingTime'] && $upData['userRingTime'] = $callData['userRingTime']; $callData['userAnswerTime'] && $upData['userAnswerTime'] = $callData['userAnswerTime']; $callData['endTime'] && $upData['endTime'] = $callData['endTime']; if ($callData['hangupType'] == Receiver_call_wechat_model::FINISH_STATUS_FINISH) { if ($callData['endTime'] && $callData['userAnswerTime']) { $upData['telDuration'] = strtotime($callData['endTime']) - strtotime($callData['userAnswerTime']); } } $this->callWechat->update($upData, ['id' => $row['id']]); if ($row['cfId'] && $row['cfPlatform'] == Receiver_call_wechat_model::CF_PLATFORM_WX_APP) { //理车宝 $user = $this->app_user_model->get(['id' => $row['cfUid']]); $cust = $this->customers_model->get(['id' => $row['cfId']]); $this->load->library('receiver/customers_entity'); $visit = 1; $this->customers_entity->add_log_visit($cust['id'], $row['cfUid'], $user['uname'], $row['id'], 2, $visit, [], 'wxapp', Receiver_customer_oplogs_model::SUB_TYPE_AUTO_CALL_OUT_WECHAT); } elseif ($row['cfId'] && $row['cfPlatform'] == Receiver_call_wechat_model::CF_PLATFORM_ADMIN) { //后台 $admin_id = $row['cfUid']; $admin = $this->sys_admin_model->get(['id' => $admin_id]); $addData = array( 'uid' => $admin_id, 'uname' => $admin['username'] ? $admin['username'] : '', 'type' => 2,//类型 0 普通 1短信 2电话 'sub_type' => Receiver_customer_oplogs_model::SUB_TYPE_AUTO_CALL_OUT_WECHAT, 'log' => $row['id'], 'c_time' => time() ); if ($row['cfType'] == Receiver_call_wechat_model::CF_TYPE_CLUE) {//线索拨打电话回调 $this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs'); $addData['clue_id'] = $row['cfId']; } else if ($row['cfType'] == Receiver_call_wechat_model::CF_TYPE_CUSTOMERS) {//客户拨打电话回调 $this->load->model('receiver/receiver_customer_oplogs_model', 'mdOplogs'); $addData['customer_id'] = $row['cfId']; $addData['cf_platform'] = Receiver_call_wechat_model::CF_PLATFORM_ADMIN; } // debug_log("addData: " . json_encode($addData, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); $this->mdOplogs->add($addData); } } catch (Exception $e) { debug_log("错误信息: " . $e->getMessage(), $logPath, $this->logDir); } $data = ['code' => 200, 'msg' => '成功', 'data' => []]; $this->output ->set_content_type('application/json') ->set_output(json_encode($data, JSON_UNESCAPED_UNICODE)); } // 下载录音文件 public function downVideo() { $logPath = "downVideo.log"; $where = array( "recordUrl" => "", "voiceId <> ''" => null ); $count = $this->callWechat->count($where); $failed_num = $success_num = $do_num = 0; if ($count) { $rows = $this->callWechat->select($where, 'id asc', 1, 20, 'id,voiceId,reqId'); $callOutWechat = new CallOutWechat(); foreach ($rows as $key => $val) { try { debug_log("下载录音文件: " . $val['id'], $logPath, $this->logDir); $req = $callOutWechat->getAudio($val['voiceId']); if (!$req->getData()) { throw new Exception('获取录音文件失败'); } $videoData = $req->getData(); $qiniu = new Qiniu(['type' => 'video']); $filename = $qiniu->getFileName($val['reqId'], 'mp3', 'call_out_wechat_video_'); $q_res = $qiniu->save($filename, $videoData); if (!$q_res || !$q_res['url']) { throw new Exception('文件上传七牛失败'); } $recUrl = $q_res['url']; $this->callWechat->update(['recordUrl' => $recUrl], ['id' => $val['id']]); debug_log("录音文件保存成功: " . $recUrl, $logPath, $this->logDir); $success_num++; } catch (Exception $e) { debug_log("错误信息: " . $e->getMessage(), $logPath, $this->logDir); $failed_num++; } $do_num++; } } echo "do_num:{$do_num},success_num:{$success_num},failed_num:{$failed_num}"; } public function test() { $logPath = "test.log"; debug_log("server: " . json_encode($_SERVER, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); $post = $this->input->post(); debug_log("post: " . json_encode($post, JSON_UNESCAPED_UNICODE), $logPath, $this->logDir); echo '333'; } }