/** * 发起请求 * * data['type'] 上传的文件类型:image, file * data['file1']='@/var/test.jpg' * data['file1[name]']='hello world' * data['file1[type]']='image/jpeg' * data['file1[error]']=0 * data['file1[size]']=13245 * * @param array $post 提交的数据 * @param array $attches 上传的附件储存地址 不参与加密 */ protected function curl($post, $attches) { $config = parent::getConfig(); $post['app_id'] = $config['app_id']; try { $post['hash'] = Utility::encrypt($post, $config['app_secret']); } catch (Exception $e) { return $this->format(self::API_FAIL, $e->getMessage()); } $post += $attches; $handle = curl_init(); //http://rpc.iyunlin.com/cdn/upload/type curl_setopt($handle, CURLOPT_URL, $config['upload'] . $post['type']); curl_setopt($handle, CURLOPT_POSTFIELDS, $post); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($handle); $result = json_decode($result, TRUE); if (!Utility::decrypt($result, $config['app_secret'])) { return $this->format(self::API_FAIL, $this->getHuiLang()->_('cdn.responce.decode.failed')); } return $result; }
protected function preCheck() { try { $huiLang = Front::getInstance()->getHuiLang(); $appId = Param::post('app_id', Param::TYPE_STRING); if (!$appId) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.app_id.null')); } if (empty($_FILES)) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.empty')); } $secret = $this->getAppSecret($appId); $post = $this->remapPostArray($_POST); //字符安全解密 if (!Utility::decrypt($post, $secret)) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.decode.failed')); } $config = $this->getConfig(); //上传文件校验处理 一个有错,全部终止 foreach ($_FILES as $key => $file) { $meta = Param::post($key, Param::TYPE_ARRAY); if (empty($meta['size']) || empty($meta['type']) || empty($meta['name']) || empty($meta['sha1'])) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.error')); } if ($file['error'] || $file['size'] != $meta['size'] || sha1_file($file['tmp_name']) != $meta['sha1']) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.finger.print.error')); } if (!empty($config['max_filesize']) && $file['size'] > $config['max_filesize'] * 1024 * 1024) { return $this->format(self::API_FAIL, $huiLang->_('cdn.upload.files.maxsize.error', $config['max_filesize'])); } } return $this->format(self::API_SUCCESS, 'ok'); } catch (Exception $e) { return $this->format(self::API_FAIL, $e->getMessage()); } }