• roller1
    了解作者
  • PHP
    开发工具
  • 3.8MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2019-03-29 20:52
    上传日期
一个轻量级小说网站解决方案,基于ThinkPHP+MySQL的技术开发。
ptcms.rar
内容介绍
<?php if(!defined('API_ROOT_PATH')){ define('API_ROOT_PATH', dirname(__FILE__)); } require_once(API_ROOT_PATH . '/lib/BaeBase.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageConstant.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageAnnotate.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageComposite.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageQRCode.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageTransform.class.php'); require_once(API_ROOT_PATH . '/images/BaeImageVCode.class.php'); require_once(API_ROOT_PATH . '/lib/RequestCore.class.php'); class BaeImageService extends BaeBase{ const METHOD = 'method'; const HOST = 'host'; const PRODUCT = 'imageui'; const SIGN = 'sign'; const ACCESS_TOKEN = 'access_token'; const SECRET_KEY = 'client_secret'; const ACCESS_KEY = 'client_id'; const DEFAULT_HOST = 'image.duapp.com'; const TIMESTAMP = 'timestamp'; const EXPIRES = 'expires'; const VERSION = 'v'; const RESOURCE = 'resource'; private $_requestId; private $_clientId; private $_clientSecret; private $_host; private $paramArr; private $ProcType_Annotate = 1; private $ProcType_Composite = 2; private $ProcType_QRCode = 0; private $_arrayErrorMap = array( '0' => 'php sdk error', BaeImageConstant::BAE_IMAGEUI_SDK_SYS => 'php sdk error', BaeImageConstant::BAE_IMAGEUI_SDK_INIT_FAIL => 'php sdk init error', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM => 'param invalid', BaeImageConstant::BAE_IMAGEUI_SDK_HTTP_STATUS_ERROR_AND_RESULT_ERROR => 'http status is error, and the body returned is not a json string', BaeImageConstant::BAE_IMAGEUI_SDK_HTTP_STATUS_OK_BUT_RESULT_ERROR => 'http status is ok, but the body returned is not a json string', ); public function getRequestId() { return $this->_requestId; } public function __construct($accessKey, $secretKey, $host) { $this->paramArr = array(); if (is_null($accessKey) || $this->_checkString($accessKey, 1, 64)) { $this->_clientId = $accessKey; } else { throw new BaeException("invalid param - access key[${accessKey}], which must be a 1 - 64 length string", BaeImageConstant::BAE_IMAGEUI_SDK_INIT_FAIL); } if (is_null($secretKey) || $this->_checkString($secretKey, 1, 64)) { $this->_clientSecret = $secretKey; } else { throw new BaeException("invalid param - secret key[${secretKey}], which must be a 1 - 64 length string", BaeImageConstant::BAE_IMAGEUI_SDK_INIT_FAIL); } if (is_null($host) || $this->_checkString($host, 1, 1024)) { if (!is_null($host)) { $this->_host = $host; } } else { throw new BaeException("invalid param - host[${host}], which must be a 1 - 1024 length string", BaeImageConstant::BAE_IMAGEUI_SDK_INIT_FAIL); } $this->_resetErrorStatus(); } private function _get_ak_sk_host(&$opt, $opt_key, $member, $g_key, $env_key, $min, $max) { $dis = array( 'client_id' => 'access_key', 'client_secret' => 'secret_key', 'host' => 'host' ); global $$g_key; if (isset($opt[$opt_key])) { if (!$this->_checkString($opt[$opt_key], $min, $max)) { throw new BaeException('invalid ' . $dis[$opt_key] . ' in $optinal(' . $opt[$opt_key] . '), which must be a ' . $min . ' - ' . $max . ' length string', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } return; } if ($this->_checkString($member, $min, $max)) { $opt[$opt_key]= $member; return; } if (isset($$g_key)) { if (!$this->_checkString($$g_key, $min, $max)) { throw new BaeException('invalid ' . $g_key . ' in global area(' . $$g_key . '), which must be a ' . $min . ' - ' . $max . ' length string', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } $opt[$opt_key]= $$g_key; return; } if (false !== getenv($env_key)) { if (! $this->_checkString(getenv($env_key), $min, $max)) { throw new BaeException('invalid ' . $env_key . ' in environment variable(' . getenv($env_key). '), which must be a ' . $min . ' - ' . $max . ' length string', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } $opt[$opt_key]= getenv($env_key); return; } if ($opt_key === self::HOST) { $opt[$opt_key]= self::DEFAULT_HOST; return; } throw new BaeException('no param(' . $dis[$opt_key] . ')was found', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } private function _adjustOpt(&$opt) { if (! isset($opt) || empty($opt) || !is_array($opt)) { throw new BaeException('no params are set', BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } if (!isset($opt[self::TIMESTAMP])) { $opt[self::TIMESTAMP]= time(); } $this->_get_ak_sk_host($opt, self::ACCESS_KEY, $this->_clientId, 'g_accessKey', 'HTTP_BAE_ENV_AK', 1, 64); $this->_get_ak_sk_host($opt, self::SECRET_KEY, $this->_clientSecret, 'g_secretKey', 'HTTP_BAE_ENV_SK', 1, 64); $this->_get_ak_sk_host($opt, self::HOST, $this->_host, 'g_host', 'HTTP_BAE_ENV_ADDR_BUS', 1, 1024); } private function _getSign(&$opt, &$arrContent, $arrNeed = array()) { $arrData = array(); $arrContent = array(); $arrNeed[] = self::TIMESTAMP; $arrNeed[] = self::METHOD; $arrNeed[] = self::ACCESS_KEY; if (isset($opt[self::EXPIRES])) { $arrNeed[] = self::EXPIRES; } if (isset($opt[self::VERSION])) { $arrNeed[] = self::VERSION; } $arrExclude = array(self::HOST, self::SECRET_KEY); foreach ($arrNeed as $key) { if (!isset($opt[$key]) || (!is_integer($opt[$key]) && empty($opt[$key]))) { throw new BaeException("lack param(${key})", BaeImageConstant::BAE_IMAGEUI_SDK_PARAM); } if (in_array($key, $arrExclude)) { continue; } $arrData[$key] = $opt[$key]; $arrContent[$key] = $opt[$key]; } foreach ($opt as $key => $value) { if (!in_array($key, $arrNeed) && !in_array($key, $arrExclude)) { $arrData[$key]= $value; $arrContent[$key]= $value; } } ksort($arrData); $url = 'http://' . $opt[self::HOST] . '/rest/2.0/' . self::PRODUCT . '/'; if (isset($opt[self::RESOURCE]) && !is_null($opt[self::RESOURCE])){ $url .= $opt[self::RESOURCE]; $arrContent[self::RESOURCE]= $opt[self::RESOURCE]; }else { $url .= self::RESOURCE; } $basicString = 'POST' . $url; foreach ($arrData as $key => $value) { $basicString .= $key . '=' . $value; } $basicString .= $opt[self::SECRET_KEY]; $sign = md5(urlencode($basicString)); $arrContent[self::SIGN] = $sign; $arrContent[self::HOST] = $opt[self::HOST]; } private function _baseControl($opt) { $content = ''; $resource = self::RESOURCE; if (isset($opt[self::RESOURCE]) && !is_null($opt[self::RESOURCE])) { $resource = $opt[self::RESOURCE]; } $host = $opt[self::HOST]; unset($opt[self::HOST]); foreach ($opt as $k => $v) { if (is_string($v)) { $v = urlencode($v); } $content .= $k . '=' . $v . '&'; } $content = substr($content, 0, strlen($content)- 1); $url = 'http://' . $host . '/rest/2.0/' . self::PRODUCT . '/'; $url .= $resource; $request = new RequestCore($url); $headers['Content-Type'] = 'application/x-www-form-urlencoded'; $headers['User-Agent'] = 'Baidu ImageUi Phpsdk Client'; foreach ($headers as $headerKey => $headerValue) { $headerValue = str_replace(array("\r", "\n"), '', $headerValue); if ($headerValue !== '') { $request->add_header($headerKey, $headerValue); } } $request->set_method('POST'); $request->set_body($content); $request->send_request(); return new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code()); } private function _commonProce
评论
    相关推荐
    • 打包.zip
      分享一些网站源码 解压需要密码 已打包了
    • googlemap(demo).rar
      javascript操作GOOGLEMAP地图所有演示程序
    • Web_Crawler.zip
      c++ spider 源代码 网络爬虫 适合研究搜索引擎
    • swish-efiles.1.3.2.tar.gz
      用C语言写的搜索引擎,包含多种建立索引的方式
    • Internet蜘蛛程序.zip
      Internet蜘蛛程序 所谓蜘蛛即SPIDER! 相信大家都知道是什么意思
    • xunlong0.6.rar
      完整的.net搜索引擎采用LUCENE.net为索引核心,分布式架构.包含wordnet,分词,spider,简单webserver等
    • VM303TXP.rar
      摄像头驱动的重要文件,在安装时可能会提示需要此文件进行安装
    • JQuery_1.4.2_API.rar
      jQuery的1.4.2发布了!jQuer1.4.2版本修复了1.4版本的一些错误和优化了一些不错的改进。
    • websearch.zip
      简单的全路径全文搜索的程序
    • javascript.rar
      一个不错的javascript教程 很适合初学者。 从基础讲其,带实例。很适用