<?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
没有合适的资源?快使用搜索试试~ 我知道了~
PTCMS美化UI小说系统源码 电脑+手机模板 带采集规则.zip
共2002个文件
jpg:918个
php:217个
png:215个
0 下载量 41 浏览量
2024-06-17
23:12:45
上传
评论
收藏 64.11MB ZIP 举报
温馨提示
PTCMS美化UI小说系统源码 电脑+手机模板 带采集规则
资源推荐
资源详情
资源评论
收起资源包目录
PTCMS美化UI小说系统源码 电脑+手机模板 带采集规则.zip (2002个子文件)
#U6388#U6743#U7801 185B
lighttpd.conf 86B
nginx.conf 72B
web.config 513B
xs.min.css 79KB
layui.css 69KB
layui.css 59KB
layui.css 59KB
layui.css 59KB
layui.css 59KB
layui.css 59KB
layui.css 59KB
layui.css 59KB
sprite-xunshuwang.css 53KB
sprite-xunshuwang.css 53KB
sprite-xunshuwang.css 53KB
sprite-xunshuwang.css 53KB
read.css 50KB
read.css 50KB
read.css 50KB
read.css 50KB
admin.css 46KB
zl_read.min.css 45KB
wap_zl_read.min.css 45KB
mobile.css 41KB
mobile.css 41KB
mobile.css 41KB
mobile.css 41KB
font-awesome.css 39KB
theme.css 35KB
global.css 33KB
font-awesome.min.css 30KB
font-awesome.min.css 30KB
common.css 29KB
common.css 26KB
common.css 26KB
common.css 26KB
font-awesome.css 25KB
global.css 25KB
common.css 25KB
common.css 25KB
common.css 25KB
common.css 25KB
theme.css 24KB
theme.css 24KB
theme.css 24KB
font-awesome.css 23KB
font-awesome.min.css 23KB
theme.css 20KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
font_6ad411.css 18KB
simditor.css 16KB
layer.css 14KB
layer.css 14KB
style.css 13KB
hd.css 11KB
layer.css 11KB
base.css 9KB
base.css 9KB
base.css 9KB
base.css 9KB
base.css 9KB
iconfont.css 8KB
iconfont.css 8KB
iconfont.css 8KB
iconfont.css 8KB
user.css 7KB
user.css 7KB
user.css 7KB
user.css 7KB
user.css 7KB
pageread.css 7KB
pageread.css 7KB
pageread.css 7KB
user.css 6KB
bookcase.css 6KB
bookcase.css 6KB
bookcase.css 6KB
bookcase.css 6KB
bookcase.css 6KB
codemirror.css 6KB
datepicker.css 4KB
sort.css 4KB
sort.css 4KB
sort.css 4KB
sort.css 4KB
sort.css 4KB
message.css 4KB
message.css 4KB
message.css 4KB
message.css 4KB
message.css 4KB
message.css 4KB
message.css 4KB
共 2002 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
酷爱码
- 粉丝: 6817
- 资源: 1148
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功