Пример #1
0
 public function mobileAction(Request $request)
 {
     $operationMobile = $this->getSettingService()->get('operation_mobile', array());
     $courseGrids = $this->getSettingService()->get('operation_course_grids', array());
     $settingMobile = $this->getSettingService()->get('mobile', array());
     $default = array('enabled' => 1, 'ver' => 1, 'about' => '', 'logo' => '', 'appname' => '', 'appabout' => '', 'applogo' => '', 'appcover' => '', 'notice' => '', 'splash1' => '', 'splash2' => '', 'splash3' => '', 'splash4' => '', 'splash5' => '');
     $mobile = array_merge($default, $settingMobile);
     if ($request->getMethod() == 'POST') {
         $settingMobile = $request->request->all();
         $mobile = array_merge($settingMobile, $operationMobile, $courseGrids);
         $this->getSettingService()->set('operation_mobile', $operationMobile);
         $this->getSettingService()->set('operation_course_grids', $courseGrids);
         $this->getSettingService()->set('mobile', $mobile);
         $this->getLogService()->info('system', 'update_settings', "更新移动客户端设置", $mobile);
         $this->setFlashMessage('success', '移动客户端设置已保存!');
     }
     $result = CloudAPIFactory::create('leaf')->get('/me');
     if (array_key_exists('ver', $mobile) && $mobile['ver']) {
         $mobileCode = array_key_exists("mobileCode", $result) && !empty($result["mobileCode"]) ? $result["mobileCode"] : "edusohov3";
     } else {
         $mobileCode = array_key_exists("mobileCode", $result) && !empty($result["mobileCode"]) ? $result["mobileCode"] : "edusoho";
     }
     //是否拥有定制app
     $hasMobile = $result['hasMobile'] ? $result['hasMobile'] : 0;
     return $this->render('TopxiaAdminBundle:System:mobile.setting.html.twig', array('mobile' => $mobile, 'mobileCode' => $mobileCode, 'hasMobile' => $hasMobile));
 }
Пример #2
0
 public function smsSend($smsType, $userIds, $description, $parameters = array())
 {
     if (!$this->isOpen($smsType)) {
         throw new \RuntimeException("云短信相关设置未开启!");
     }
     $users = $this->getUserService()->findUsersByIds($userIds);
     $to = '';
     if (!empty($users)) {
         $verifiedMobiles = ArrayToolkit::column($users, 'verifiedMobile');
         $to = implode(',', $verifiedMobiles);
         try {
             $api = CloudAPIFactory::create('leaf');
             $result = $api->post("/sms/send", array('mobile' => $to, 'category' => $smsType, 'description' => $description, 'parameters' => $parameters));
         } catch (\RuntimeException $e) {
             throw new \RuntimeException("发送失败!");
         }
         $message = '对';
         foreach ($users as $user) {
             $message .= 'userId: ' . $user['id'] . ';nickname: ' . $user['nickname'] . ';mobile: ' . $user['verifiedMobile'] . ';';
         }
         $message .= '发送用于' . $smsType . '的通知短信';
         $this->getLogService()->info('sms', $smsType, $message, $verifiedMobiles);
     }
     return true;
 }
Пример #3
0
 public function getUrls($targetId, $smsType)
 {
     $lesson = $this->getCourseService()->getLesson($targetId);
     $course = $this->getCourseService()->getCourse($lesson['courseId']);
     $count = 0;
     if ($course['parentId']) {
         $classroom = $this->getClassroomService()->findClassroomByCourseId($course['id']);
         if ($classroom) {
             $count = $this->getClassroomService()->searchMemberCount(array('classroomId' => $classroom['classroomId']));
         }
     } else {
         $count = $this->getCourseService()->searchMemberCount(array('courseId' => $course['id']));
     }
     global $kernel;
     $container = $kernel->getContainer();
     $siteSetting = $this->getSettingService()->get('site');
     $siteSetting['url'] = rtrim($siteSetting['url']);
     $siteSetting['url'] = rtrim($siteSetting['url'], '/');
     $hostName = $siteSetting['url'];
     $api = CloudAPIFactory::create('root');
     for ($i = 0; $i <= intval($count / 1000); $i++) {
         $urls[$i] = $hostName;
         $urls[$i] .= $container->get('router')->generate('edu_cloud_sms_send_callback', array('targetType' => 'lesson', 'targetId' => $targetId));
         $urls[$i] .= '?index=' . $i * 1000;
         $urls[$i] .= '&smsType=' . $smsType;
         $sign = $this->getSignEncoder()->encodeSign($urls[$i], $api->getAccessKey());
         $sign = rawurlencode($sign);
         $urls[$i] .= '&sign=' . $sign;
     }
     return array('count' => $count, 'urls' => $urls);
 }
Пример #4
0
 public function indexAction(Request $request)
 {
     $mobile = $this->setting('mobile', array());
     if (empty($mobile['enabled'])) {
         return $this->createMessageResponse('info', '客户端尚未开启!');
     }
     $result = CloudAPIFactory::create('leaf')->get('/me');
     return $this->render('TopxiaWebBundle:Mobile:index.html.twig', array('host' => $request->getHttpHost(), 'mobileCode' => array_key_exists("mobileCode", $result) && !empty($result["mobileCode"]) ? $result["mobileCode"] : "edusoho", 'mobile' => $mobile));
 }
Пример #5
0
 public function hiddenMenu()
 {
     $result = CloudAPIFactory::create('leaf')->get('/me');
     if (isset($result['thirdCopyright']) and $result['thirdCopyright'] == '1') {
         $this->addMenuCodeToBlackList(array('admin_app'));
     }
     if (isset($result['thirdCopyright']) and $result['thirdCopyright'] == '0') {
         $this->removeMenuCodeToBlackList(array('admin_app'));
     }
 }
Пример #6
0
 public function cloudSearch($type, $conditions = array())
 {
     $api = CloudAPIFactory::create('root');
     $result = $api->get('/search', $conditions);
     if (empty($result['success'])) {
         throw new \RuntimeException("搜索失败,请稍候再试.", 1);
     }
     $resultSet = $result['body']['datas'];
     $counts = $result['body']['count'];
     $resultSet = SearchAdapterFactory::create($type)->adapt($resultSet);
     return array($resultSet, $counts);
 }
Пример #7
0
 protected function refreshCopyright($info = array())
 {
     $settingService = $this->getServiceKernel()->createService('System.SettingService');
     if (empty($info)) {
         $api = CloudAPIFactory::create('leaf');
         $info = $api->get('/me');
     }
     if (isset($info['copyright'])) {
         if ($info['copyright']) {
             $copyright = $settingService->get('copyright', array());
             if (empty($copyright['owned'])) {
                 $copyright['owned'] = 1;
                 $settingService->set('copyright', $copyright);
             }
         } else {
             $settingService->delete('copyright');
         }
     }
 }
Пример #8
0
 public function myCloudOverviewAction(Request $request)
 {
     // @apitodo 需改成leaf
     $api = CloudAPIFactory::create('root');
     $content = $api->get("/users/{$api->getAccessKey()}/overview");
     $info = $api->get('/me');
     if (isset($info['licenseDomains'])) {
         $info['licenseDomainCount'] = count(explode(';', $info['licenseDomains']));
     }
     $isBinded = $this->getAppService()->getBinded();
     $email = isset($isBinded['email']) ? str_replace(substr(substr($isBinded['email'], 0, stripos($isBinded['email'], '@')), -4), '****', $isBinded['email']) : null;
     $eduSohoOpenClient = new EduSohoOpenClient();
     $currentTime = date('Y-m-d', time());
     $account = isset($content['account']) ? $content['account'] : null;
     $day = '';
     if (isset($content['account']['arrearageDate']) && $content['account']['arrearageDate'] != 0) {
         $day = ceil((strtotime($currentTime) - $content['account']['arrearageDate']) / 86400);
     }
     $user = isset($content['user']) ? $content['user'] : null;
     $endDate = isset($content['user']['endDate']) ? str_replace('-', '.', $content['user']['endDate']) : '';
     $startDate = isset($content['user']['startDate']) ? str_replace('-', '.', $content['user']['startDate']) : '';
     $packageDate = isset($content['user']['endDate']) ? ceil((strtotime($content['user']['endDate']) - strtotime($currentTime)) / 86400) : '';
     $tlp = isset($content['service']['tlp']) ? $content['service']['tlp'] : 0;
     $storage = isset($content['service']['storage']) ? $content['service']['storage'] : null;
     $storageDate = isset($content['service']['storage']['expire']) ? ceil(($content['service']['storage']['expire'] - strtotime($currentTime)) / 86400) : '';
     $month = isset($content['service']['storage']['bill']['date']) ? substr($content['service']['storage']['bill']['date'], -2) : '';
     $startYear = isset($content['service']['storage']['startMonth']) ? substr($content['service']['storage']['startMonth'], 0, 4) : '';
     $startMonth = isset($content['service']['storage']['startMonth']) ? substr($content['service']['storage']['startMonth'], -2) : '';
     $endYear = isset($content['service']['storage']['endMonth']) ? substr($content['service']['storage']['endMonth'], 0, 4) : '';
     $endMonth = isset($content['service']['storage']['endMonth']) ? substr($content['service']['storage']['endMonth'], -2) : '';
     $storageStart = $startYear . '.' . $startMonth;
     $storageEnd = $endYear . '.' . $endMonth;
     $live = isset($content['service']['live']) ? $content['service']['live'] : null;
     $liveDate = isset($content['service']['live']['expire']) ? ceil(($content['service']['live']['expire'] - strtotime($currentTime)) / 86400) : '';
     $sms = isset($content['service']['sms']) ? $content['service']['sms'] : null;
     $notices = $eduSohoOpenClient->getNotices();
     $notices = json_decode($notices, true);
     if ($this->getWebExtension()->isTrial()) {
         $trialHtml = $this->getCloudCenterExperiencePage();
     }
     return $this->render('TopxiaAdminBundle:App:my-cloud.html.twig', array('content' => $content, 'packageDate' => $packageDate, 'storageDate' => $storageDate, 'startDate' => $startDate, 'endDate' => $endDate, 'liveDate' => $liveDate, 'storageStart' => $storageStart, 'storageEnd' => $storageEnd, 'day' => $day, 'month' => $month, 'storage' => $storage, 'live' => $live, 'user' => $user, 'sms' => $sms, 'account' => $account, "notices" => $notices, 'info' => $info, 'isBinded' => $isBinded, 'email' => $email, 'tlp' => $tlp, 'trialhtml' => isset($trialHtml['content']) ? $trialHtml['content'] : null));
 }
Пример #9
0
 public function execute($params)
 {
     $smsType = 'sms_live_play_one_hour';
     $dayIsOpen = $this->getSmsService()->isOpen($smsType);
     $parameters = array();
     if ($dayIsOpen) {
         $targetType = $params['targetType'];
         $targetId = $params['targetId'];
         $processor = SmsProcessorFactory::create($targetType);
         $return = $processor->getUrls($targetId, $smsType);
         $callbackUrls = $return['urls'];
         $count = ceil($return['count'] / 1000);
         try {
             $api = CloudAPIFactory::create('leaf');
             $result = $api->post("/sms/sendBatch", array('total' => $count, 'callbackUrls' => $callbackUrls));
         } catch (\RuntimeException $e) {
             throw new \RuntimeException("发送失败!");
         }
     }
 }
Пример #10
0
 public function onCourseLessonPublish(ServiceEvent $event)
 {
     $lesson = $event->getSubject();
     if ($lesson['type'] == 'live') {
         $this->createJob($lesson);
         $smsType = 'sms_live_lesson_publish';
     } else {
         $smsType = 'sms_normal_lesson_publish';
     }
     if ($this->getSmsService()->isOpen($smsType)) {
         $processor = SmsProcessorFactory::create('lesson');
         $return = $processor->getUrls($lesson['id'], $smsType);
         $callbackUrls = $return['urls'];
         $count = ceil($return['count'] / 1000);
         try {
             $api = CloudAPIFactory::create('root');
             $result = $api->post("/sms/sendBatch", array('total' => $count, 'callbackUrls' => $callbackUrls));
         } catch (\RuntimeException $e) {
             throw new \RuntimeException("发送失败!");
         }
     }
 }
Пример #11
0
 public function searchCallBackAction(Request $request)
 {
     $originSign = rawurldecode($request->query->get('sign'));
     $searchSetting = $this->getSettingService()->get('cloud_search');
     $siteSetting = $this->getSettingService()->get('site');
     $siteSetting['url'] = rtrim($siteSetting['url']);
     $siteSetting['url'] = rtrim($siteSetting['url'], '/');
     $url = $siteSetting['url'];
     $url .= $this->generateUrl('edu_cloud_search_callback');
     $api = CloudAPIFactory::create('root');
     $sign = $this->getSignEncoder()->encodeSign($url, $api->getAccessKey());
     if ($originSign != $sign) {
         return $this->createJsonResponse(array('error' => 'sign不正确'));
     }
     $searchSetting['search_enabled'] = 1;
     $searchSetting['status'] = 'ok';
     $this->getSettingService()->set('cloud_search', $searchSetting);
     return $this->createJsonResponse(true);
 }
Пример #12
0
 public function smsCallBackAction(Request $request, $targetType, $targetId)
 {
     $index = $request->query->get('index');
     $smsType = $request->query->get('smsType');
     $originSign = rawurldecode($request->query->get('sign'));
     $siteSetting = $this->getSettingService()->get('site');
     $siteSetting['url'] = rtrim($siteSetting['url']);
     $siteSetting['url'] = rtrim($siteSetting['url'], '/');
     $url = $siteSetting['url'];
     $url .= $this->generateUrl('edu_cloud_sms_send_callback', array('targetType' => $targetType, 'targetId' => $targetId));
     $url .= '?index=' . $index . '&smsType=' . $smsType;
     $api = CloudAPIFactory::create('leaf');
     $sign = $this->getSignEncoder()->encodeSign($url, $api->getAccessKey());
     if ($originSign != $sign) {
         return $this->createJsonResponse(array('error' => 'sign不正确'));
     }
     $processor = SmsProcessorFactory::create($targetType);
     return $this->createJsonResponse($processor->getSmsInfo($targetId, $index, $smsType));
 }
Пример #13
0
 public function ticketAction(Request $request, $id)
 {
     $ticketNo = $request->query->get('ticket');
     $ticket = CloudAPIFactory::create('leaf')->get("/liverooms/{$id}/tickets/{$ticketNo}");
     return $this->createJsonResponse($ticket);
 }
Пример #14
0
 public function createReplayList($liveId, $title, $provider)
 {
     $args = array("liveId" => $liveId, "title" => $title, "provider" => $provider);
     return CloudAPIFactory::create('root')->post('/lives/' . $liveId . '/records', $args);
 }
Пример #15
0
 public function clefAction(Request $request, $id, $token)
 {
     $token = $this->getTokenService()->verifyToken('hls.clef', $token);
     if (empty($token)) {
         return $this->makeFakeTokenString();
     }
     if (!empty($token['userId'])) {
         if (!($this->getCurrentUser()->isLogin() && $this->getCurrentUser()->getId() == $token['userId'])) {
             return $this->makeFakeTokenString();
         }
     }
     $dataId = is_array($token['data']) ? $token['data']['id'] : $token['data'];
     if ($dataId != $id) {
         return $this->makeFakeTokenString();
     }
     $file = $this->getUploadFileService()->getFile($id);
     if (empty($file)) {
         return $this->makeFakeTokenString();
     }
     if (empty($file['convertParams']['hlsKey'])) {
         return $this->makeFakeTokenString();
     }
     $api = CloudAPIFactory::create('leaf');
     if (!empty($token['data']['keyencryption'])) {
         $stream = $api->get("/hls/clef/{$file['convertParams']['hlsKey']}/algo/1", array());
         return new Response($stream['key']);
     }
     $stream = $api->get("/hls/clef/{$file['convertParams']['hlsKey']}/algo/0", array());
     return new Response($stream['key']);
 }
 public function streamAction(Request $request, $id, $level, $token)
 {
     $token = $this->getTokenService()->verifyToken('hls.stream', $token);
     if (empty($token)) {
         throw $this->createNotFoundException();
     }
     $dataId = is_array($token['data']) ? $token['data']['id'] : $token['data'];
     if ($dataId != $id . $level) {
         throw $this->createNotFoundException();
     }
     $file = $this->getUploadFileService()->getFile($id);
     if (empty($file)) {
         throw $this->createNotFoundException();
     }
     if (empty($file['metas2'][$level]['key'])) {
         throw $this->createNotFoundException();
     }
     $params = array();
     $params['key'] = $file['metas2'][$level]['key'];
     $mode = is_array($token['data']) ? $token['data']['mode'] : '';
     $timelimit = $this->setting('magic.lesson_watch_time_limit');
     if ($mode == 'preview' && !empty($timelimit)) {
         $params['limitSecond'] = $timelimit;
     }
     $token = $this->getTokenService()->makeToken('hls.clef', array('data' => array('id' => $file['id'], 'mode' => $mode), 'times' => 1, 'duration' => 3600));
     $params['keyUrl'] = $this->generateUrl('hls_clef', array('id' => $file['id'], 'token' => $token['token']), true);
     $hideBeginning = $request->query->get('hideBeginning');
     if (empty($hideBeginning)) {
         $beginning = $this->getVideoBeginning($level);
         if ($beginning['beginningKey']) {
             $params = array_merge($params, $beginning);
         }
     }
     $line = $request->query->get('line');
     if (!empty($line)) {
         $params['line'] = $line;
     }
     $api = CloudAPIFactory::create();
     $stream = $api->get('/hls/stream', $params);
     if (empty($stream['stream'])) {
         return $this->createMessageResponse('error', '生成视频播放地址失败!');
     }
     return new Response($stream['stream'], 200, array('Content-Type' => 'application/vnd.apple.mpegurl', 'Content-Disposition' => 'inline; filename="stream.m3u8"'));
 }
Пример #17
0
 protected function push($title, $content, $from, $to, $body)
 {
     $message = array('title' => $title, 'content' => $content, 'custom' => array('from' => $from, 'to' => $to, 'body' => $body));
     $result = CloudAPIFactory::create('tui')->post('/message/send', $message);
 }
Пример #18
0
 public function keyCopyrightAction(Request $request)
 {
     $api = CloudAPIFactory::create('leaf');
     $info = $api->get('/me');
     $copyright = $this->getSettingService()->get('copyright', array());
     if (isset($info['thirdCopyright']) and $info['thirdCopyright'] == '1') {
         $copyright["thirdCopyright"] = 1;
     } else {
         $copyright["thirdCopyright"] = 0;
     }
     $this->getSettingService()->set('copyright', $copyright);
     if (empty($info['copyright'])) {
         throw $this->createAccessDeniedException('您无权操作!');
     }
     $name = $request->request->get('name');
     $this->getSettingService()->set('copyright', array('owned' => 1, 'name' => $request->request->get('name', '')));
     return $this->createJsonResponse(array('status' => 'ok'));
 }
Пример #19
0
 protected function getSchoolName()
 {
     $schoolName = $this->setting('cloud_sms.sms_school_name');
     $schoolCandidateName = $this->setting('cloud_sms.sms_school_candidate_name');
     $api = CloudAPIFactory::create('root');
     $result = $api->post("/sms/{$api->getAccessKey()}/applyResult");
     $smsStatus = array();
     if (isset($result['apply']) && isset($result['apply']['status'])) {
         $smsStatus['status'] = $result['apply']['status'];
         if ($smsStatus['status'] == 'passed' && strlen($schoolCandidateName) > 0) {
             $schoolName = $schoolCandidateName;
             $schoolCandidateName = '';
             $this->setCloudSmsKey('sms_school_name', $schoolName);
             $this->setCloudSmsKey('sms_school_candidate_name', '');
         }
         if (isset($result['apply']['message'])) {
             $smsStatus['message'] = $result['apply']['message'];
             if (strlen($smsStatus['message']) > 0) {
                 $smsStatus['message'] = $smsStatus['message'];
             }
         }
         if ($smsStatus['status'] == 'failed') {
             $info = '您新申请的网校名称“' . $schoolCandidateName . '”未通过审核,原因是:';
             if (isset($smsStatus['message']) && $smsStatus['message']) {
                 $info .= $smsStatus['message'];
             } else {
                 $info .= '网校名称不符合规范';
             }
             $smsStatus['schoolNameError'] = $info;
         }
     } else {
         if (isset($result['error'])) {
             $smsStatus['status'] = 'error';
             $smsStatus['message'] = $result['error'];
         }
     }
     return array($smsStatus, array('sms_school_name' => $schoolName, 'sms_school_candidate_name' => $schoolCandidateName));
 }
 protected function deleteGroupMember($grouType, $groupId, $memberId)
 {
     $uri = "/groups/%s-%s/members/%s";
     $result = CloudAPIFactory::create('tui')->delete(sprintf($uri, $grouType, $groupId, $memberId));
 }
Пример #21
0
 public function entryAction(Request $request, $courseId, $lessonId)
 {
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         return $this->createMessageResponse('info', '你好像忘了登录哦?', null, 3000, $this->generateUrl('login'));
     }
     $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId);
     if (empty($lesson)) {
         return $this->createMessageResponse('info', '课时不存在!');
     }
     if (empty($lesson['mediaId'])) {
         return $this->createMessageResponse('info', '直播教室不存在!');
     }
     if ($lesson['startTime'] - time() > 7200) {
         return $this->createMessageResponse('info', '直播还没开始!');
     }
     if ($lesson['endTime'] < time()) {
         return $this->createMessageResponse('info', '直播已结束!');
     }
     $params = array();
     if ($this->getCourseService()->isCourseTeacher($courseId, $user['id'])) {
         $teachers = $this->getCourseService()->findCourseTeachers($courseId);
         $teacher = array_shift($teachers);
         if ($teacher['userId'] == $user['id']) {
             $params['role'] = 'teacher';
         } else {
             $params['role'] = 'speaker';
         }
     } elseif ($this->getCourseService()->isCourseStudent($courseId, $user['id'])) {
         $params['role'] = 'student';
     } else {
         return $this->createMessageResponse('info', '您不是课程学员,不能参加直播!');
     }
     $liveAccount = CloudAPIFactory::create('leaf')->get('/me/liveaccount');
     $params['id'] = $user['id'];
     $params['nickname'] = $user['nickname'];
     return $this->forward('TopxiaWebBundle:Liveroom:_entry', array('id' => $lesson['mediaId']), $params);
     $params['liveId'] = $lesson['mediaId'];
     $params['provider'] = $lesson['liveProvider'];
     $params['user'] = $user['email'];
     $params['nickname'] = $user['nickname'];
     $client = new EdusohoLiveClient();
     $result = $client->entryLive($params);
     if (empty($result) || isset($result['error'])) {
         return $this->createMessageResponse('info', $result['errorMsg']);
     }
     return $this->render("TopxiaWebBundle:LiveCourse:classroom.html.twig", array('courseId' => $courseId, 'lessonId' => $lessonId, 'lesson' => $lesson, 'url' => $this->generateUrl('live_classroom_url', array('courseId' => $courseId, 'lessonId' => $lessonId))));
 }
Пример #22
0
 public function reconvertOldFile($file, $convertCallback, $pipeline = null)
 {
     if (empty($file['convertParams'])) {
         return;
     }
     $params = array('convertCallback' => $convertCallback, 'convertor' => $file['convertParams']['convertor'], 'convertParams' => $file['convertParams']);
     if ($file['type'] == 'video') {
         $watermarks = $this->getVideoWatermarkImages();
         $file['convertParams']['hasVideoWatermark'] = empty($watermarks) ? 0 : 1;
         $file['convertParams'] = $this->encodeMetas($file['convertParams']);
         $this->getUploadFileDao()->updateFile($file['id'], array('convertParams' => $file['convertParams']));
     }
     if ($pipeline) {
         $params['pipeline'] = $pipeline;
     }
     if ($file['type'] == 'video' && $watermarks) {
         $params['convertParams']['videoWatermarkImages'] = $watermarks;
     }
     $task = array();
     $task['key'] = $file['hashId'];
     $task['processor'] = 'video';
     $task['directives'] = array('videoQuality' => $params['convertParams']['videoQuality'], 'audioQuality' => $params['convertParams']['audioQuality'], 'hlsKey' => $params['convertParams']['hlsKey'], 'hlsKeyUrl' => $params['convertParams']['hlsKeyUrl']);
     if (!empty($params['convertParams']['videoWatermarkImages'])) {
         $task['directives']['watermarks'] = $params['convertParams']['videoWatermarkImages'];
     }
     $task['callbackUrl'] = $convertCallback;
     $api = CloudAPIFactory::create('root');
     $result = $api->post('/processes', $task);
     if (empty($result['taskNo'])) {
         return;
     }
     return $result['taskNo'];
 }
Пример #23
0
 public function smsSendAction(Request $request)
 {
     if ($request->getMethod() == 'POST') {
         if ($this->setting('cloud_sms.sms_enabled') != '1') {
             return $this->createJsonResponse(array('error' => '短信服务被管理员关闭了'));
         }
         $currentUser = $this->getCurrentUser();
         $currentTime = time();
         $smsType = $request->request->get('sms_type');
         $this->checkSmsType($smsType, $currentUser);
         if ($smsType != 'sms_user_pay') {
             $captchaNum = strtolower($request->request->get('captcha_num'));
             if ($request->getSession()->get('captcha_code') != $captchaNum) {
                 return $this->createJsonResponse(array('error' => '验证码错误'));
             }
         }
         $targetSession = $request->getSession()->get($smsType);
         $smsLastTime = $targetSession['sms_last_time'];
         $allowedTime = 120;
         if (!$this->checkLastTime($smsLastTime, $currentTime, $allowedTime)) {
             return $this->createJsonResponse(array('error' => '请等待120秒再申请', 'message' => "{$smsLastTime}|{$currentTime}"));
         }
         if (in_array($smsType, array('sms_bind', 'sms_registration'))) {
             $to = $request->request->get('to');
             $hasVerifiedMobile = isset($currentUser['verifiedMobile']) && strlen($currentUser['verifiedMobile']) > 0;
             if ($hasVerifiedMobile && $to == $currentUser['verifiedMobile']) {
                 return $this->createJsonResponse(array('error' => "您已经绑定了该手机号码"));
             }
             if (!$this->getUserService()->isMobileUnique($to)) {
                 return $this->createJsonResponse(array('error' => "该手机号码已被其他用户绑定"));
             }
         }
         if ($smsType == 'sms_forget_password') {
             $targetUser = $this->getUserService()->getUserByVerifiedMobile($request->request->get('to'));
             if (empty($targetUser)) {
                 return $this->createJsonResponse(array('error' => '用户不存在'));
             }
             if (!isset($targetUser['verifiedMobile']) || strlen($targetUser['verifiedMobile']) == 0) {
                 return $this->createJsonResponse(array('error' => '用户没有被绑定的手机号'));
             }
             if ($targetUser['verifiedMobile'] != $request->request->get('to')) {
                 return $this->createJsonResponse(array('error' => '手机与用户名不匹配'));
             }
             $to = $targetUser['verifiedMobile'];
         }
         if (in_array($smsType, array('sms_user_pay', 'sms_forget_pay_password'))) {
             $user = $currentUser->toArray();
             if (!isset($user['verifiedMobile']) || strlen($user['verifiedMobile']) == 0) {
                 return $this->createJsonResponse(array('error' => '用户没有被绑定的手机号'));
             }
             if ($user['verifiedMobile'] != $request->request->get('to')) {
                 return $this->createJsonResponse(array('error' => '您输入的手机号,不是已绑定的手机'));
             }
             $to = $user['verifiedMobile'];
         }
         if (!$this->checkPhoneNum($to)) {
             return $this->createJsonResponse(array('error' => "手机号错误:{$to}"));
         }
         $smsCode = $this->generateSmsCode();
         try {
             $api = CloudAPIFactory::create('leaf');
             $result = $api->post("/sms/{$api->getAccessKey()}/sendVerify", array('mobile' => $to, 'verify' => $smsCode, 'category' => $smsType));
             if (isset($result['error'])) {
                 return $this->createJsonResponse(array('error' => "发送失败, {$result['error']}"));
             }
         } catch (\RuntimeException $e) {
             $message = $e->getMessage();
             return $this->createJsonResponse(array('error' => "发送失败, {$message}"));
         }
         $result['to'] = $to;
         $result['smsCode'] = $smsCode;
         $result['userId'] = $currentUser['id'];
         if ($currentUser['id'] != 0) {
             $result['nickname'] = $currentUser['nickname'];
         }
         $this->getLogService()->info('sms', $smsType, "userId:{$currentUser['id']},对{$to}发送用于{$smsType}的验证短信{$smsCode}", $result);
         $request->getSession()->set($smsType, array('to' => $to, 'sms_code' => $smsCode, 'sms_last_time' => $currentTime));
         return $this->createJsonResponse(array('ACK' => 'ok'));
     }
     return $this->createJsonResponse(array('error' => 'GET method'));
 }
Пример #24
0
 public function systemStatusAction()
 {
     $apps = array();
     $systemVersion = "";
     $error = "";
     $apps = $this->getAppService()->checkAppUpgrades();
     $appsAll = $this->getAppService()->getCenterApps();
     $codes = ArrayToolkit::column($appsAll, 'code');
     $installedApps = $this->getAppService()->findAppsByCodes($codes);
     $unInstallAppCount = count($appsAll) - count($installedApps);
     $appCount = count($apps);
     if (isset($apps['error'])) {
         $error = "error";
     }
     $mainAppUpgrade = null;
     foreach ($apps as $key => $value) {
         if (isset($value['code']) && $value['code'] == "MAIN") {
             $mainAppUpgrade = $value;
         }
     }
     $api = CloudAPIFactory::create('leaf');
     $liveCourseStatus = $api->get('/lives/account');
     return $this->render('TopxiaAdminBundle:Default:system.status.html.twig', array("apps" => $apps, "error" => $error, "mainAppUpgrade" => $mainAppUpgrade, "app_count" => $appCount, "unInstallAppCount" => $unInstallAppCount, "liveCourseStatus" => $liveCourseStatus));
 }