Example #1
0
 /**
  *  The main routing function to call in web interceptor/index
  *  The approach is simple as possible
  */
 public static function init()
 {
     /* Catch http request */
     $request = new HttpRequest();
     /* Check if reserved controller 'main' requestes */
     if ($request->queryStartsFrom('/main')) {
         /* Finish here */
         Http::sendError(404);
     }
     /* Choose controller */
     if (!($reference = self::chooseController($request))) {
         /* Or finish here */
         Http::sendError(404);
     }
     /* Route request */
     if (!($response = self::route($reference, $request))) {
         /* Or finish here */
         Http::sendError(404);
     }
     /* Sending final response
      * JSON
      */
     if ($response['type'] === 'json') {
         Http::sendJSON($response['data']);
     }
     /* OR plain html */
     Http::send($response['data']);
 }
Example #2
0
 /**
  * 智能鉴黄-Files
  * @param  string  $pornFile     要进行黄图检测的图片File列表
  */
 public static function pornDetectFile($pornFile)
 {
     $sign = Auth::getPornDetectSign();
     if (false === $sign) {
         $data = array("code" => 9, "message" => "Secret id or key is empty.", "data" => array());
         return $data;
     }
     $data = array('appid' => Conf::APPID, 'bucket' => Conf::BUCKET);
     for ($i = 0; $i < count($pornFile); $i++) {
         if (PATH_SEPARATOR == ';') {
             // WIN OS
             $pornFile[$i] = iconv("UTF-8", "gb2312", $pornFile[$i]);
         }
         $srcPath = realpath($pornFile[$i]);
         if (!file_exists($srcPath)) {
             return array('httpcode' => 0, 'code' => self::IMAGE_FILE_NOT_EXISTS, 'message' => 'file ' . $pornFile[$i] . ' not exists', 'data' => array());
         }
         if (function_exists('curl_file_create')) {
             $data['image[' . (string) $i . ']'] = curl_file_create($srcPath, NULL, $pornFile[$i]);
         } else {
             $data['image[' . (string) $i . ']'] = '@' . $srcPath;
         }
     }
     $req = array('url' => Conf::API_PRONDETECT_URL, 'method' => 'post', 'timeout' => self::TIME_OUT, 'data' => $data, 'header' => array('Authorization:' . $sign));
     $rsp = Http::send($req);
     return $rsp;
 }
Example #3
0
 /**
  * 导入工单
  * @param array $data
  * @throws MissingParametersException
  * @throws ResponseException
  * @return mixed
  */
 public function tickets($data = '')
 {
     $url = 'imports/tickets';
     $this->validatePara('array', $data, 'data', __METHOD__);
     $data = array('ticket' => $data);
     $response = Http::send($this->client, $url, $data, 'POST');
     return $this->validateResponse($response, __METHOD__);
 }
 public function activate(array $params) {
     $endPoint = Http::prepare('/mail/activate.json');
     $response = json_decode(Http::send($this->apicaller, $endPoint, $params, 'GET'));
     if (!is_object($response)) {
         throw new ResponseException(__METHOD__);
     }
     return $response;
 }
Example #5
0
 /**
  * 删除指定客服组
  * @param int $group_id
  * @throws MissingParametersException
  * @throws ResponseException
  * @return mixed
  */
 public function delete($group_id = '')
 {
     $url = 'groups';
     $this->validatePara('int', $group_id, 'group_id', __METHOD__);
     $url = $url . '/' . $group_id;
     Http::send($this->client, $url, '', 'DELETE');
     return $this->validateResponse('', __METHOD__, 'delete');
 }
    public function getDnsRecords(array $params) {

        $endPoint = Http::prepare('domainforward/dns-records.json');
        $response = json_decode(Http::send($this->apicaller, $endPoint, $params, 'GET'));
        if (!is_object($response)) {
            throw new ResponseException(__METHOD__);
        }
        return $response;
    }
Example #7
0
 /**
  * 导出工单
  * @param array $data
  * @throws MissingParametersException
  * @throws ResponseException
  * @return mixed
  */
 public function tickets($data = '')
 {
     $url = 'exports/tickets';
     if ($data) {
         $this->validatePara('array', $data, 'data', __METHOD__);
         $url = $url . '?' . http_build_query($data);
     }
     $response = Http::send($this->client, $url);
     return $this->validateResponse($response, __METHOD__);
 }
 /**
  * Update one or more settings
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function update(array $params)
 {
     $endPoint = Http::prepare('account/settings.json');
     $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Returns a list of sharing agreements
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function findAll(array $params = array())
 {
     $endPoint = Http::prepare('sharing_agreements.json', null, $params);
     $response = Http::send($this->client, $endPoint);
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Unregister the mobile devices that are receiving push notifications
  *
  * @param array $devices
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return bool
  */
 public function delete(array $devices = array())
 {
     $endPoint = Http::prepare('push_notification_devices/destroy_many.json');
     $response = Http::send($this->client, $endPoint, array("push_notification_devices" => $devices), 'POST');
     if ($this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return true;
 }
Example #11
0
 /**
  * Create multiple new tickets
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function importMany(array $params)
 {
     $endPoint = Http::prepare('imports/tickets/create_many.json');
     $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME_PLURAL => $params), 'POST');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Create a voice or voicemail ticket
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function create(array $params)
 {
     $endPoint = Http::prepare('channels/voice/tickets.json');
     $response = Http::send($this->client, $endPoint, $params, 'POST');
     // note: specify the whole package
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 201) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * List all stats
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function findAll(array $params = array())
 {
     if (!$this->hasAnyKey($params, array('current_queue_activity', 'historical_queue_activity', 'agents_activity'))) {
         throw new MissingParametersException(__METHOD__, array('current_queue_activity', 'historical_queue_activity', 'agents_activity'));
     }
     $endPoint = Http::prepare(isset($params['current_queue_activity']) ? 'channels/voice/stats/current_queue_activity.json' : (isset($params['historical_queue_activity']) ? 'channels/voice/stats/historical_queue_activity.json' : (isset($params['agents_activity']) ? 'channels/voice/stats/agents_activity.json' : '')), null, $params);
     $response = Http::send($this->client, $endPoint);
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Opens a ticket in an agent's browser
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return bool
  */
 public function openTicket(array $params = array())
 {
     if (!$this->hasKeys($params, array('agent_id', 'ticket_id'))) {
         throw new MissingParametersException(__METHOD__, array('agent_id', 'ticket_id'));
     }
     $endPoint = Http::prepare('channels/voice/agents/' . $params['agent_id'] . '/tickets/' . $params['ticket_id'] . '/display.json');
     $response = Http::send($this->client, $endPoint, null, 'POST');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return true;
 }
 /**
  * Submits a request for matching tags
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  * @return mixed
  */
 public function tags(array $params)
 {
     if (!$this->hasKeys($params, array('name'))) {
         throw new MissingParametersException(__METHOD__, array('name'));
     }
     $endPoint = Http::prepare('autocomplete/tags.json');
     $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params['name']), 'POST');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Perform an anonymous search
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function anonymousSearch(array $params)
 {
     if (!$this->hasKeys($params, array('query'))) {
         throw new MissingParametersException(__METHOD__, array('query'));
     }
     $endPoint = Http::prepare('portal/search.json', null, $params);
     $response = Http::send($this->client, $endPoint, $params, 'GET');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Detect the best locale from the supplied list
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function detectBest(array $params)
 {
     if (!$this->hasKeys($params, array('available_locales'))) {
         throw new MissingParametersException(__METHOD__, array('available_locales'));
     }
     $endPoint = Http::prepare('locales/detect_best_locale.json', null, $params);
     $response = Http::send($this->client, $endPoint, array('available_locales' => $params['available_locales']), 'GET');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Create a new satisfaction rating (authorised end user credentials only please!)
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function create(array $params)
 {
     if ($this->client->tickets()->getLastId() != null) {
         $params['ticket_id'] = $this->client->tickets()->getLastId();
         $this->client->tickets()->setLastId(null);
     }
     $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/satisfaction_rating.json');
     $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__, $this->client->getDebug()->lastResponseCode == 403 ? ' (hint: you need to authenticate as a verified end user for this method)' : '');
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Find a specific article by id
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function find(array $params = array())
 {
     if (!$this->hasKeys($params, array('id'))) {
         throw new MissingParametersException(__METHOD__, array('id'));
     }
     $url = sprintf('help_center/%sarticles/%d.json', isset($params['locale']) ? $params['locale'] . '/' : '', $params['id']);
     $endPoint = Http::prepare($url, $this->client->getSideload($params));
     $response = Http::send($this->client, $endPoint);
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Show a specific audit log
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function find(array $params = array())
 {
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasKeys($params, array('id'))) {
         throw new MissingParametersException(__METHOD__, array('id'));
     }
     $endPoint = Http::prepare('audit_logs/' . $params['id'] . '.json');
     $response = Http::send($this->client, $endPoint);
     $this->client->setSideload(null);
     return $response;
 }
Example #21
0
 public static function sendRequest($req)
 {
     $rsp = Http::send($req);
     $info = Http::info();
     $ret = json_decode($rsp, true);
     if ($ret) {
         if (0 === $ret['code']) {
             $ret['httpcode'] = $info['http_code'];
             return $ret;
         } else {
             return array('httpcode' => $info['http_code'], 'code' => $ret['code'], 'message' => $ret['message'], 'data' => array());
         }
     } else {
         return array('httpcode' => $info['http_code'], 'code' => self::COSAPI_NETWORK_ERROR, 'message' => $rsp, 'data' => array());
     }
 }
 /**
  * Find a specific activity
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function find(array $params = array())
 {
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasKeys($params, array('id'))) {
         throw new MissingParametersException(__METHOD__, array('id'));
     }
     $endPoint = Http::prepare('activities/' . $params['id'] . '.json');
     $response = Http::send($this->client, $endPoint);
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Delete a token
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return bool
  */
 public function revoke(array $params = array())
 {
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasKeys($params, array('id'))) {
         throw new MissingParametersException(__METHOD__, array('id'));
     }
     $id = $params['id'];
     $endPoint = Http::prepare('oauth/tokens/' . $id . '.json');
     $response = Http::send($this->client, $endPoint, null, 'DELETE');
     if ($this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return true;
 }
 /**
  * Make the specified comment private
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function makePrivate(array $params = array())
 {
     if ($this->client->tickets()->getLastId() != null) {
         $params['ticket_id'] = $this->client->tickets()->getLastId();
         $this->client->tickets()->setLastId(null);
     }
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasKeys($params, array('id', 'ticket_id'))) {
         throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
     }
     $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/comments/' . $params['id'] . '/make_private.json');
     $response = Http::send($this->client, $endPoint, null, 'PUT');
     if ($this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__, ' (hint: you can\'t make a private ticket private again)');
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Show a specific ticket metric
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function find(array $params = array())
 {
     if ($this->client->tickets()->getLastId() != null) {
         $params['ticket_id'] = $this->client->tickets()->getLastId();
         $this->client->tickets()->setLastId(null);
     }
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasAnyKey($params, array('id', 'ticket_id'))) {
         throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
     }
     $endPoint = Http::prepare(isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/metrics.json' : 'ticket_metrics/' . $params['id'] . '.json');
     $response = Http::send($this->client, $endPoint);
     if (!is_object($response) || $this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
Example #26
0
 public function searchArchived(array $params) {
     $endPoint = Http::prepare('actions/search-archived.json');
     $response = Http::send($this->apicaller, $endPoint, $params, 'GET');
     return $response;
 }
Example #27
0
 public function deleteModerators(array $params) {
     $endPoint = Http::prepare('mail/mailinglist/delete-moderators.json');
     $response = json_decode(Http::send($this->apicaller, $endPoint, $params, 'GET'));
     if (!is_object($response)) {
         throw new ResponseException(__METHOD__);
     }
     return $response;
 }
 /**
  * Delete a topic vote
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return bool
  */
 public function delete(array $params = array())
 {
     if ($this->client->topics()->getLastId() != null) {
         $params['topic_id'] = $this->client->topics()->getLastId();
         $this->client->topics()->setLastId(null);
     }
     if ($this->client->users()->getLastId() != null) {
         $params['user_id'] = $this->client->users()->getLastId();
         $this->client->users()->setLastId(null);
     }
     if (!$this->hasKeys($params, array('topic_id'))) {
         throw new MissingParametersException(__METHOD__, array('topic_id'));
     }
     $endPoint = Http::prepare('topics/' . $params['topic_id'] . '/vote.json' . (isset($params['user_id']) ? '?user_id=' . $params['user_id'] : ''));
     $response = Http::send($this->client, $endPoint, null, 'DELETE');
     if ($this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return true;
 }
 /**
  * Clones an existing form (can't use 'clone' as method name)
  *
  * @param array $params
  *
  * @throws MissingParametersException
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 function cloneForm(array $params = array())
 {
     if ($this->lastId != null) {
         $params['id'] = $this->lastId;
         $this->lastId = null;
     }
     if (!$this->hasKeys($params, array('id'))) {
         throw new MissingParametersException(__METHOD__, array('id'));
     }
     $id = $params['id'];
     $endPoint = Http::prepare('ticket_forms/' . $id . '/clone.json');
     $response = Http::send($this->client, $endPoint, null, 'POST');
     if ($this->client->getDebug()->lastResponseCode != 201) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }
 /**
  * Reorder user fields
  *
  * @param array $params
  *
  * @throws ResponseException
  * @throws \Exception
  *
  * @return mixed
  */
 public function reorder(array $params)
 {
     $endPoint = Http::prepare('user_fields/reorder.json');
     $response = Http::send($this->client, $endPoint, array('user_field_ids' => $params), 'PUT');
     if ($this->client->getDebug()->lastResponseCode != 200) {
         throw new ResponseException(__METHOD__);
     }
     $this->client->setSideload(null);
     return $response;
 }