first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1 @@
0dbc5c80-c763-478b-8ede-97452122e553

View File

@@ -0,0 +1 @@
bb40ecc1-a6c7-44b5-acda-40b4b09e89ee

View File

@@ -0,0 +1 @@
f0ea1879-7175-4d22-b8e0-4de68140a40c

View File

@@ -0,0 +1,140 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
abstract class AcsRequest
{
protected $version;
protected $product;
protected $actionName;
protected $regionId;
protected $acceptFormat;
protected $method;
protected $protocolType = "http";
protected $content;
protected $queryParameters = array();
protected $headers = array();
function __construct($product, $version, $actionName)
{
$this->headers["x-sdk-client"] = "php/2.0.0";
$this->product = $product;
$this->version = $version;
$this->actionName = $actionName;
}
public abstract function composeUrl($iSigner, $credential, $domain);
public function getVersion()
{
return $this->version;
}
public function setVersion($version)
{
$this->version = $version;
}
public function getProduct()
{
return $this->product;
}
public function setProduct($product)
{
$this->product = $product;
}
public function getActionName()
{
return $this->actionName;
}
public function setActionName($actionName)
{
$this->actionName = $actionName;
}
public function getAcceptFormat()
{
return $this->acceptFormat;
}
public function setAcceptFormat($acceptFormat)
{
$this->acceptFormat = $acceptFormat;
}
public function getQueryParameters()
{
return $this->queryParameters;
}
public function getHeaders()
{
return $this->headers;
}
public function getMethod()
{
return $this->method;
}
public function setMethod($method)
{
$this->method = $method;
}
public function getProtocol()
{
return $this->protocolType;
}
public function setProtocol($protocol)
{
$this->protocolType = $protocol;
}
public function getRegionId()
{
return $this->regionId;
}
public function setRegionId($region)
{
$this->regionId = $region;
}
public function getContent()
{
return $this->content;
}
public function setContent($content)
{
$this->content = $content;
}
public function addHeader($headerKey, $headerValue)
{
$this->headers[$headerKey] = $headerValue;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class AcsResponse
{
private $code;
private $message;
public function getCode()
{
return $this->code;
}
public function setCode($code)
{
$this->code = $code;
}
public function getMessage()
{
return $this->message;
}
public function setMessage($message)
{
$this->message = $message;
}
}

View File

@@ -0,0 +1 @@
aa8a5356-b2ec-407f-8612-bcb4768e20b4

View File

@@ -0,0 +1,87 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class Credential
{
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
private $refreshDate;
private $expiredDate;
private $accessKeyId;
private $accessSecret;
private $securityToken;
function __construct($accessKeyId, $accessSecret)
{
$this->accessKeyId = $accessKeyId;
$this->accessSecret = $accessSecret;
$this->refreshDate = date($this->dateTimeFormat);
}
public function isExpired()
{
if($this->expiredDate == null)
{
return false;
}
if(strtotime($this->expiredDate)>date($this->dateTimeFormat))
{
return false;
}
return true;
}
public function getRefreshDate()
{
return $this->refreshDate;
}
public function getExpiredDate()
{
return $this->expiredDate;
}
public function setExpiredDate($expiredHours)
{
if($expiredHours>0)
{
return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
}
}
public function getAccessKeyId()
{
return $this->accessKeyId;
}
public function setAccessKeyId($accessKeyId)
{
$this->accessKeyId = $accessKeyId;
}
public function getAccessSecret()
{
return $this->accessSecret;
}
public function setAccessSecret($accessSecret)
{
$this->accessSecret = $accessSecret;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
interface ISigner
{
public function getSignatureMethod();
public function getSignatureVersion();
public function signString($source, $accessSecret);
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ShaHmac1Signer implements ISigner
{
public function signString($source, $accessSecret)
{
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true));
}
public function getSignatureMethod() {
return "HMAC-SHA1";
}
public function getSignatureVersion() {
return "1.0";
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ShaHmac256Signer implements ISigner
{
public function signString($source, $accessSecret)
{
return base64_encode(hash_hmac('sha256', $source, $accessSecret, true));
}
public function getSignatureMethod() {
return "HMAC-SHA256";
}
public function getSignatureVersion() {
return "1.0";
}
}

View File

@@ -0,0 +1 @@
d82ab142-3106-4855-9676-f80c85cd5ed0

View File

@@ -0,0 +1,50 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
spl_autoload_register("Autoloader::autoload");
class Autoloader
{
private static $autoloadPathArray = array(
"core",
"core/Auth",
"core/Http",
"core/Profile",
"core/Regions",
"core/Exception"
);
public static function autoload($className)
{
foreach (self::$autoloadPathArray as $path) {
$file = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$className.".php";
$file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
if(is_file($file)){
include_once $file;
break;
}
}
}
public static function addAutoloadPath($path)
{
array_push(self::$autoloadPathArray, $path);
}
}
?>

View File

@@ -0,0 +1,47 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once 'Autoloader/Autoloader.php';
//Autoloader::addAutoloadPath("../core");
include_once 'Regions/EndpointConfig.php';
//config sdk auto load path.
//Autoloader::addAutoloadPath("aliyun-php-sdk-ecs");
//Autoloader::addAutoloadPath("aliyun-php-sdk-batchcompute");
//Autoloader::addAutoloadPath("aliyun-php-sdk-sts");
//Autoloader::addAutoloadPath("aliyun-php-sdk-push");
//Autoloader::addAutoloadPath("aliyun-php-sdk-ram");
//Autoloader::addAutoloadPath("aliyun-php-sdk-ubsms");
//Autoloader::addAutoloadPath("aliyun-php-sdk-ubsms-inner");
//Autoloader::addAutoloadPath("aliyun-php-sdk-green");
//Autoloader::addAutoloadPath("aliyun-php-sdk-dm");
//Autoloader::addAutoloadPath("aliyun-php-sdk-iot");
//Autoloader::addAutoloadPath("aliyun-php-sdk-jaq");
//Autoloader::addAutoloadPath("aliyun-php-sdk-cs");
//Autoloader::addAutoloadPath("aliyun-php-sdk-live");
//Autoloader::addAutoloadPath("aliyun-php-sdk-vpc");
//Autoloader::addAutoloadPath("aliyun-php-sdk-kms");
//Autoloader::addAutoloadPath("aliyun-php-sdk-rds");
//Autoloader::addAutoloadPath("../slb");
//config http proxy
define('ENABLE_HTTP_PROXY', FALSE);
define('HTTP_PROXY_IP', '127.0.0.1');
define('HTTP_PROXY_PORT', '8888');

View File

@@ -0,0 +1,128 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class DefaultAcsClient implements IAcsClient
{
public $iClientProfile;
function __construct($iClientProfile)
{
$this->iClientProfile = $iClientProfile;
}
public function getAcsResponse($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3)
{
$httpResponse = $this->doAction($request, $iSigner, $credential, $autoRetry, $maxRetryNumber);
$respObject = $this->parseAcsResponse($httpResponse->getBody(), $request->getAcceptFormat());
if(false == $httpResponse->isSuccess())
{
$this->buildApiException($respObject, $httpResponse->getStatus());
}
return $respObject;
}
public function doAction($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3)
{
if(null == $this->iClientProfile && (null == $iSigner || null == $credential
|| null == $request->getRegionId() || null == $request->getAcceptFormat()))
{
throw new ClientException("No active profile found.", "SDK.InvalidProfile");
}
if(null == $iSigner)
{
$iSigner = $this->iClientProfile->getSigner();
}
if(null == $credential)
{
$credential = $this->iClientProfile->getCredential();
}
$request = $this->prepareRequest($request);
$domain = EndpointProvider::findProductDomain($request->getRegionId(), $request->getProduct());
if(null == $domain)
{
throw new ClientException("Can not find endpoint to access.", "SDK.InvalidRegionId");
}
$requestUrl = $request->composeUrl($iSigner, $credential, $domain);
if(count($request->getDomainParameter())>0){
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders());
} else {
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(),$request->getContent(), $request->getHeaders());
}
$retryTimes = 1;
while (500 <= $httpResponse->getStatus() && $autoRetry && $retryTimes < $maxRetryNumber) {
$requestUrl = $request->composeUrl($iSigner, $credential,$domain);
if(count($request->getDomainParameter())>0){
$httpResponse = HttpHelper::curl($requestUrl, $request->getDomainParameter(), $request->getHeaders());
} else {
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders());
}
$retryTimes ++;
}
return $httpResponse;
}
private function prepareRequest($request)
{
if(null == $request->getRegionId())
{
$request->setRegionId($this->iClientProfile->getRegionId());
}
if(null == $request->getAcceptFormat())
{
$request->setAcceptFormat($this->iClientProfile->getFormat());
}
if(null == $request->getMethod())
{
$request->setMethod("GET");
}
return $request;
}
private function buildApiException($respObject, $httpStatus)
{
if(500 <= $httpStatus)
{
throw new ServerException($respObject->Message, $respObject->Code);
}
else
{
throw new ClientException($respObject->Message, $respObject->Code);
}
}
private function parseAcsResponse($body, $format)
{
if ("JSON" == $format)
{
$respObject = json_decode($body);
}
else if("XML" == $format)
{
$respObject = @simplexml_load_string($body);
}
else if("RAW" == $format)
{
$respObject = $body;
}
return $respObject;
}
}

View File

@@ -0,0 +1 @@
d530e5f6-33ac-4ad4-88a0-9af9da801c3e

View File

@@ -0,0 +1,65 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ClientException extends Exception
{
function __construct($errorMessage, $errorCode)
{
parent::__construct($errorMessage);
$this->errorMessage = $errorMessage;
$this->errorCode = $errorCode;
$this->setErrorType("Client");
}
private $errorCode;
private $errorMessage;
private $errorType;
public function getErrorCode()
{
return $this->errorCode;
}
public function setErrorCode($errorCode)
{
$this->errorCode = $errorCode;
}
public function getErrorMessage()
{
return $this->errorMessage;
}
public function setErrorMessage($errorMessage)
{
$this->errorMessage = $errorMessage;
}
public function getErrorType()
{
return $this->errorType;
}
public function setErrorType($errorType)
{
$this->errorType = $errorType;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ServerException extends ClientException
{
function __construct($errorMessage, $errorCode)
{
parent::__construct($errorMessage, $errorCode);
$this->setErrorType("Server");
}
}

View File

@@ -0,0 +1 @@
f58b4829-8de0-47ea-86b8-0079f06bdead

View File

@@ -0,0 +1,83 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class HttpHelper
{
public static $connectTimeout = 30000;//30 second
public static $readTimeout = 80000;//80 second
public static function curl($url, $httpMethod = "GET", $postFields = null,$headers = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
if(ENABLE_HTTP_PROXY) {
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP);
curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
if (self::$readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
}
if (self::$connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
}
//https request
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (is_array($headers) && 0 < count($headers))
{
$httpHeaders =self::getHttpHearders($headers);
curl_setopt($ch,CURLOPT_HTTPHEADER,$httpHeaders);
}
$httpResponse = new HttpResponse();
$httpResponse->setBody(curl_exec($ch));
$httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if (curl_errno($ch))
{
throw new ClientException("Speicified endpoint or uri is not valid.".curl_error($ch), "SDK.ServerUnreachable");
}
curl_close($ch);
return $httpResponse;
}
static function getPostHttpBody($postFildes){
$content = "";
foreach ($postFildes as $apiParamKey => $apiParamValue)
{
$content .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
}
return substr($content, 0, -1);
}
static function getHttpHearders($headers)
{
$httpHeader = array();
foreach ($headers as $key => $value)
{
array_push($httpHeader, $key.":".$value);
}
return $httpHeader;
}
}

View File

@@ -0,0 +1,53 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class HttpResponse
{
private $body;
private $status;
public function getBody()
{
return $this->body;
}
public function setBody($body)
{
$this->body = $body;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status)
{
$this->status = $status;
}
public function isSuccess()
{
if(200 <= $this->status && 300 > $this->status)
{
return true;
}
return false;
}
}

View File

@@ -0,0 +1,23 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
interface IAcsClient
{
public function doAction($requst);
}

View File

@@ -0,0 +1 @@
69128600-8913-49cb-81a6-ecef5246a658

View File

@@ -0,0 +1,148 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// include_once 'IClientProfile.php';
class DefaultProfile implements IClientProfile
{
private static $profile;
private static $endpoints;
private static $credential;
private static $regionId;
private static $acceptFormat;
private static $isigner;
private static $iCredential;
private function __construct($regionId,$credential)
{
self::$regionId = $regionId;
self::$credential = $credential;
}
public static function getProfile($regionId, $accessKeyId, $accessSecret)
{
$credential =new Credential($accessKeyId, $accessSecret);
self::$profile = new DefaultProfile($regionId, $credential);
return self::$profile;
}
public function getSigner()
{
if(null == self::$isigner)
{
self::$isigner = new ShaHmac1Signer();
}
return self::$isigner;
}
public function getRegionId()
{
return self::$regionId;
}
public function getFormat()
{
return self::$acceptFormat;
}
public function getCredential()
{
if(null == self::$credential && null != self::$iCredential)
{
self::$credential = self::$iCredential;
}
return self::$credential;
}
public static function getEndpoints()
{
if(null == self::$endpoints)
{
self::$endpoints = EndpointProvider::getEndpoints();
}
return self::$endpoints;
}
public static function addEndpoint($endpointName, $regionId, $product, $domain)
{
if(null == self::$endpoints)
{
self::$endpoints = self::getEndpoints();
}
$endpoint = self::findEndpointByName($endpointName);
if(null == $endpoint)
{
self::addEndpoint_($endpointName, $regionId, $product, $domain);
}
else
{
self::updateEndpoint($regionId, $product, $domain, $endpoint);
}
}
public static function findEndpointByName($endpointName)
{
foreach (self::$endpoints as $key => $endpoint)
{
if($endpoint->getName() == $endpointName)
{
return $endpoint;
}
}
}
private static function addEndpoint_($endpointName,$regionId, $product, $domain)
{
$regionIds = array($regionId);
$productsDomains = array(new ProductDomain($product, $domain));
$endpoint = new Endpoint($endpointName, $regionIds, $productDomains);
array_push(self::$endpoints, $endpoint);
}
private static function updateEndpoint($regionId, $product, $domain, $endpoint)
{
$regionIds = $endpoint->getRegionIds();
if(!in_array($regionId,$regionIds))
{
array_push($regionIds, $regionId);
$endpoint->setRegionIds($regionIds);
}
$productDomains = $endpoint->getProductDomains();
if(null == self::findProductDomain($productDomains, $product, $domain))
{
array_push($productDomains, new ProductDomain($product, $domain));
}
$endpoint->setProductDomains($productDomains);
}
private static function findProductDomain($productDomains, $product, $domain)
{
foreach ($productDomains as $key => $productDomain)
{
if($productDomain->getProductName() == $product && $productDomain->getDomainName() == $domain)
{
return $productDomain;
}
}
return null;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
interface IClientProfile
{
public function getSigner();
public function getRegionId();
public function getFormat();
public function getCredential();
}

View File

@@ -0,0 +1 @@
1e6f8cfa-38ee-4789-890d-ab787da78fd4

View File

@@ -0,0 +1,62 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class Endpoint
{
private $name;
private $regionIds;
private $productDomains;
function __construct($name, $regionIds, $productDomains)
{
$this->name = $name;
$this->regionIds = $regionIds;
$this->productDomains = $productDomains;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getRegionIds()
{
return $this->regionIds;
}
public function setRegionIds($regionIds)
{
$this->regionIds = $regionIds;
}
public function getProductDomains()
{
return $this->productDomains;
}
public function setProductDomains($productDomains)
{
$this->productDomains = $productDomains;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// include_once 'ProductDomain.php';
// include_once 'Endpoint.php';
// include_once 'EndpointProvider.php';
$endpoint_filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "endpoints.xml";
$xml = simplexml_load_string(file_get_contents($endpoint_filename));
$json = json_encode($xml);
$json_array = json_decode($json, TRUE);
$endpoints = array();
foreach ($json_array["Endpoint"] as $json_endpoint) {
# pre-process RegionId & Product
if (!array_key_exists("RegionId", $json_endpoint["RegionIds"])) {
$region_ids = array();
} else {
$json_region_ids = $json_endpoint['RegionIds']['RegionId'];
if (!is_array($json_region_ids)) {
$region_ids = array($json_region_ids);
} else {
$region_ids = $json_region_ids;
}
}
if (!array_key_exists("Product", $json_endpoint["Products"])) {
$products = array();
} else {
$json_products = $json_endpoint["Products"]["Product"];
if (array() === $json_products or !is_array($json_products)) {
$products = array();
} else if (array_keys($json_products) !== range(0, count($json_products) - 1)) {
# array is not sequential
$products = array($json_products);
} else {
$products = $json_products;
}
}
$product_domains = array();
foreach ($products as $product) {
$product_domain = new ProductDomain($product['ProductName'], $product['DomainName']);
array_push($product_domains, $product_domain);
}
$endpoint = new Endpoint($region_ids[0], $region_ids, $product_domains);
array_push($endpoints, $endpoint);
}
EndpointProvider::setEndpoints($endpoints);

View File

@@ -0,0 +1,67 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class EndpointProvider
{
private static $endpoints;
public static function findProductDomain($regionId, $product)
{
if(null == $regionId || null == $product || null == self::$endpoints)
{
return null;
}
foreach (self::$endpoints as $key => $endpoint)
{
if(in_array($regionId, $endpoint->getRegionIds()))
{
return self::findProductDomainByProduct($endpoint->getProductDomains(), $product);
}
}
return null;
}
private static function findProductDomainByProduct($productDomains, $product)
{
if(null == $productDomains)
{
return null;
}
foreach ($productDomains as $key => $productDomain)
{
if($product == $productDomain->getProductName())
{
return $productDomain->getDomainName();
}
}
return null;
}
public static function getEndpoints()
{
return self::$endpoints;
}
public static function setEndpoints($endpoints)
{
self::$endpoints = $endpoints;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ProductDomain
{
private $productName;
private $domainName;
function __construct($product, $domain) {
$this->productName = $product;
$this->domainName = $domain;
}
public function getProductName() {
return $this->productName;
}
public function setProductName($productName) {
$this->productName = $productName;
}
public function getDomainName() {
return $this->domainName;
}
public function setDomainName($domainName) {
$this->domainName = $domainName;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
abstract class RoaAcsRequest extends AcsRequest
{
protected $uriPattern;
private $pathParameters = array();
private $domainParameters = array();
private $dateTimeFormat ="D, d M Y H:i:s \G\M\T";
private static $headerSeparator = "\n";
private static $querySeprator = "&";
function __construct($product, $version, $actionName)
{
parent::__construct($product, $version, $actionName);
$this->setVersion($version);
$this->initialize();
}
private function initialize()
{
$this->setMethod("RAW");
}
public function composeUrl($iSigner, $credential, $domain)
{
$this->prepareHeader($iSigner);
$signString = $this->getMethod().self::$headerSeparator;
if(isset($this->headers["Accept"]))
{
$signString = $signString.$this->headers["Accept"];
}
$signString = $signString.self::$headerSeparator;
if(isset($this->headers["Content-MD5"]))
{
$signString = $signString.$this->headers["Content-MD5"];
}
$signString = $signString.self::$headerSeparator;
if(isset($this->headers["Content-Type"]))
{
$signString = $signString.$this->headers["Content-Type"];
}
$signString = $signString.self::$headerSeparator;
if(isset($this->headers["Date"]))
{
$signString = $signString.$this->headers["Date"];
}
$signString = $signString.self::$headerSeparator;
$uri = $this->replaceOccupiedParameters();
$signString = $signString.$this->buildCanonicalHeaders();
$queryString = $this->buildQueryString($uri);
$signString .= $queryString;
$this->headers["Authorization"] = "acs ".$credential->getAccessKeyId().":"
.$iSigner->signString($signString, $credential->getAccessSecret());
$requestUrl = $this->getProtocol()."://".$domain.$queryString;
return $requestUrl;
}
private function prepareHeader($iSigner)
{
date_default_timezone_set("GMT");
$this->headers["Date"] = date($this->dateTimeFormat);
if(null == $this->acceptFormat)
{
$this->acceptFormat = "RAW";
}
$this->headers["Accept"] = $this->formatToAccept($this->getAcceptFormat());
$this->headers["x-acs-signature-method"] = $iSigner->getSignatureMethod();
$this->headers["x-acs-signature-version"] = $iSigner->getSignatureVersion();
$this->headers["x-acs-region-id"] = $this->regionId;
$content = $this->getDomainParameter();
if ($content != null) {
$this->headers["Content-MD5"] = base64_encode(md5(json_encode($content),true));
}
$this->headers["Content-Type"] = "application/octet-stream;charset=utf-8";
}
private function replaceOccupiedParameters()
{
$result = $this->uriPattern;
foreach ($this->pathParameters as $pathParameterKey => $apiParameterValue)
{
$target = "[".$pathParameterKey."]";
$result = str_replace($target,$apiParameterValue,$result);
}
return $result;
}
private function buildCanonicalHeaders()
{
$sortMap = array();
foreach ($this->headers as $headerKey => $headerValue)
{
$key = strtolower($headerKey);
if(strpos($key, "x-acs-") === 0)
{
$sortMap[$key] = $headerValue;
}
}
ksort($sortMap);
$headerString = "";
foreach ($sortMap as $sortMapKey => $sortMapValue)
{
$headerString = $headerString.$sortMapKey.":".$sortMapValue.self::$headerSeparator;
}
return $headerString;
}
private function splitSubResource($uri)
{
$queIndex = strpos($uri, "?");
$uriParts = array();
if(null != $queIndex)
{
array_push($uriParts, substr($uri,0,$queIndex));
array_push($uriParts, substr($uri,$queIndex+1));
}
else
{
array_push($uriParts,$uri);
}
return $uriParts;
}
private function buildQueryString($uri)
{
$uriParts = $this->splitSubResource($uri);
$sortMap = $this->queryParameters;
if(isset($uriParts[1]))
{
$sortMap[$uriParts[1]] = null;
}
$queryString = $uriParts[0];
if(count($uriParts))
{
$queryString = $queryString."?";
}
ksort($sortMap);
foreach ($sortMap as $sortMapKey => $sortMapValue)
{
$queryString = $queryString.$sortMapKey;
if(isset($sortMapValue))
{
$queryString = $queryString."=".$sortMapValue;
}
$queryString = $queryString.$querySeprator;
}
if(null==count($sortMap))
{
$queryString = substr($queryString, 0, strlen($queryString)-1);
}
return $queryString;
}
private function formatToAccept($acceptFormat)
{
if($acceptFormat == "JSON")
{
return "application/json";
}
elseif ($acceptFormat == "XML") {
return "application/xml";
}
return "application/octet-stream";
}
public function getPathParameters()
{
return $this->pathParameters;
}
public function putPathParameter($name, $value)
{
$this->pathParameters[$name] = $value;
}
public function getDomainParameter()
{
return $this->domainParameters;
}
public function putDomainParameters($name, $value)
{
$this->domainParameters[$name] = $value;
}
public function getUriPattern()
{
return $this->uriPattern;
}
public function setUriPattern($uriPattern)
{
return $this->uriPattern = $uriPattern;
}
public function setVersion($version)
{
$this->version = $version;
$this->headers["x-acs-version"] = $version;
}
}

View File

@@ -0,0 +1,104 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
abstract class RpcAcsRequest extends AcsRequest
{
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
private $domainParameters = array();
function __construct($product, $version, $actionName)
{
parent::__construct($product, $version, $actionName);
$this->initialize();
}
private function initialize()
{
$this->setMethod("GET");
$this->setAcceptFormat("JSON");
}
public function composeUrl($iSigner, $credential, $domain)
{
$apiParams = parent::getQueryParameters();
$apiParams["RegionId"] = $this->getRegionId();
$apiParams["AccessKeyId"] = $credential->getAccessKeyId();
$apiParams["Format"] = $this->getAcceptFormat();
$apiParams["SignatureMethod"] = $iSigner->getSignatureMethod();
$apiParams["SignatureVersion"] = $iSigner->getSignatureVersion();
$apiParams["SignatureNonce"] = uniqid();
date_default_timezone_set("GMT");
$apiParams["Timestamp"] = date($this->dateTimeFormat);
$apiParams["Action"] = $this->getActionName();
$apiParams["Version"] = $this->getVersion();
$apiParams["Signature"] = $this->computeSignature($apiParams, $credential->getAccessSecret(), $iSigner);
if(parent::getMethod() == "POST") {
$requestUrl = $this->getProtocol()."://". $domain . "/";
foreach ($apiParams as $apiParamKey => $apiParamValue)
{
$this->putDomainParameters($apiParamKey,$apiParamValue);
}
return $requestUrl;
}
else {
$requestUrl = $this->getProtocol()."://". $domain . "/?";
foreach ($apiParams as $apiParamKey => $apiParamValue)
{
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
}
return substr($requestUrl, 0, -1);
}
}
private function computeSignature($parameters, $accessKeySecret, $iSigner)
{
ksort($parameters);
$canonicalizedQueryString = '';
foreach($parameters as $key => $value)
{
$canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value);
}
$stringToSign = parent::getMethod().'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
$signature = $iSigner->signString($stringToSign, $accessKeySecret."&");
return $signature;
}
protected function percentEncode($str)
{
$res = urlencode($str);
$res = preg_replace('/\+/', '%20', $res);
$res = preg_replace('/\*/', '%2A', $res);
$res = preg_replace('/%7E/', '~', $res);
return $res;
}
public function getDomainParameter()
{
return $this->domainParameters;
}
public function putDomainParameters($name, $value)
{
$this->domainParameters[$name] = $value;
}
}

View File

@@ -0,0 +1 @@
f2de2b1e-8fef-4ce9-84a3-2683187439c1

View File

@@ -0,0 +1 @@
e314f297-05cf-4d11-a71a-df84dda8c805

View File

@@ -0,0 +1,37 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class CredentialTest extends PHPUnit_Framework_TestCase
{
public function testCredential()
{
$credential = new Credential("accessKeyId", "accessSecret");
$this->assertEquals("accessKeyId",$credential->getAccessKeyId());
$this->assertEquals("accessSecret",$credential->getAccessSecret());
$this->assertNotNull($credential->getRefreshDate());
$dateNow = date("Y-m-d\TH:i:s\Z");
$credential->setExpiredDate(1);
$this->assertNotNull($credential->getExpiredDate());
$this->assertTrue($credential->getExpiredDate() > $dateNow);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class ShaHmac1SignerTest extends PHPUnit_Framework_TestCase
{
public function testShaHmac1Signer()
{
$signer = new ShaHmac1Signer();
$this->assertEquals("33nmIV5/p6kG/64eLXNljJ5vw84=",$signer->signString("this is a ShaHmac1 test.", "accessSecret"));
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class ShaHmac256SignerTest extends PHPUnit_Framework_TestCase
{
public function testShaHmac256Signer()
{
$signer = new ShaHmac256Signer();
$this->assertEquals("TpF1lE/avV9EHGWGg9Vo/QTd2bLRwFCk9jjo56uRbCo=",
$signer->signString("this is a ShaHmac256 test.", "accessSecret"));
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class BaseTest extends PHPUnit_Framework_TestCase
{
public $client = null;
function setUp()
{
$path = substr(dirname(__FILE__), 0,strripos(dirname(__FILE__),DIRECTORY_SEPARATOR)).DIRECTORY_SEPARATOR;
include_once $path.'Config.php';
include_once 'Ecs/Rquest/DescribeRegionsRequest.php';
include_once 'BatchCompute/ListImagesRequest.php';
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret");
$this->client = new DefaultAcsClient($iClientProfile);
}
function getProperty($propertyKey)
{
$accessKey = "";
$accessSecret = "";
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret");
}
}

View File

@@ -0,0 +1 @@
3492ab7d-5f8a-44e0-8fac-d35d1f635c74

View File

@@ -0,0 +1,31 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace UnitTest\BatchCompute\Request;
class ListImagesRequest extends \RoaAcsRequest
{
function __construct()
{
parent::__construct("BatchCompute", "2013-01-11", "ListImages");
$this->setUriPattern("/images");
$this->setMethod("GET");
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once 'BaseTest.php';
use UnitTest\Ecs\Request as Ecs;
use UnitTest\BatchCompute\Request as BC;
class DefaultAcsClientTest extends BaseTest
{
public function testDoActionRPC()
{
$request = new Ecs\DescribeRegionsRequest();
$response = $this->client->doAction($request);
$this->assertNotNull($response->RequestId);
$this->assertNotNull($response->Regions->Region[0]->LocalName);
$this->assertNotNull($response->Regions->Region[0]->RegionId);
}
public function testDoActionROA()
{
$request = new BC\ListImagesRequest();
$response = $this->client->doAction($request);
$this->assertNotNull($response);
}
}

View File

@@ -0,0 +1 @@
c0d1f3be-4822-45ab-9a7c-6d4ec7578458

View File

@@ -0,0 +1 @@
769efb49-39d9-46e3-8814-c8fc951533c6

View File

@@ -0,0 +1,73 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
namespace UnitTest\Ecs\Request;
class DescribeRegionsRequest extends \RpcAcsRequest
{
function __construct()
{
parent::__construct("Ecs", "2014-05-26", "DescribeRegions");
}
private $ownerId;
private $resourceOwnerAccount;
private $resourceOwnerId;
private $ownerAccount;
public function getOwnerId() {
return $this->ownerId;
}
public function setOwnerId($ownerId) {
$this->ownerId = $ownerId;
$this->queryParameters["OwnerId"]=$ownerId;
}
public function getResourceOwnerAccount() {
return $this->resourceOwnerAccount;
}
public function setResourceOwnerAccount($resourceOwnerAccount) {
$this->resourceOwnerAccount = $resourceOwnerAccount;
$this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount;
}
public function getResourceOwnerId() {
return $this->resourceOwnerId;
}
public function setResourceOwnerId($resourceOwnerId) {
$this->resourceOwnerId = $resourceOwnerId;
$this->queryParameters["ResourceOwnerId"]=$resourceOwnerId;
}
public function getOwnerAccount() {
return $this->ownerAccount;
}
public function setOwnerAccount($ownerAccount) {
$this->ownerAccount = $ownerAccount;
$this->queryParameters["OwnerAccount"]=$ownerAccount;
}
}

View File

@@ -0,0 +1 @@
9aa3ff16-d94c-4c92-ac71-8db190ef6534

View File

@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../BaseTest.php';
class HttpHelperTest extends BaseTest
{
public function testCurl()
{
$httpResponse = HttpHelper::curl("ecs.aliyuncs.com");
$this->assertEquals(400,$httpResponse->getStatus());
$this->assertNotNull($httpResponse->getBody());
}
}

View File

@@ -0,0 +1 @@
18db19e1-46b1-41b4-abec-6808ad0ec6e5

View File

@@ -0,0 +1,65 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class DefaultProfileTest extends PHPUnit_Framework_TestCase
{
public function testGetProfile()
{
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
$this->assertEquals("cn-hangzhou",$profile->getRegionId());
$this->assertEquals("accessId",$profile->getCredential()->getAccessKeyId());
$this->assertEquals("accessSecret",$profile->getCredential()->getAccessSecret());
}
public function testAddEndpoint()
{
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
$profile->addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com");
$endpoints = $profile->getEndpoints();
foreach ($endpoints as $key => $endpoint)
{
if("cn-hangzhou" == $endpoint->getName())
{
$regionIds = $endpoint->getRegionIds();
$this->assertContains("cn-hangzhou",$regionIds);
$productDomains= $endpoint->getProductDomains();
$this->assertNotNull($productDomains);
$productDomain = $this->getProductDomain($productDomains);
$this->assertNotNull($productDomain);
$this->assertEquals("TestProduct",$productDomain->getProductName());
$this->assertEquals("testproduct.aliyuncs.com",$productDomain->getDomainName());
}
}
}
private function getProductDomain($productDomains)
{
foreach ($productDomains as $productDomain)
{
if($productDomain->getProductName() == "TestProduct")
{
return $productDomain;
}
}
return null;
}
}

View File

@@ -0,0 +1 @@
ea12d909-bdfc-4c5b-8cd0-2e1c9c7fda5d

View File

@@ -0,0 +1,30 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
include_once '../../Config.php';
class EndpointProviderTest extends PHPUnit_Framework_TestCase
{
public function testFindProductDomain()
{
$this->assertEquals("ecs.aliyuncs.com",EndpointProvider::findProductDomain("cn-hangzhou", "Ecs"));
}
}

View File

@@ -0,0 +1 @@
677d3603-c9ba-4cb6-ac54-fb7f6af35e5a

View File

@@ -0,0 +1,73 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class AssumeRoleRequest extends \RpcAcsRequest
{
function __construct()
{
parent::__construct("Sts", "2015-04-01", "AssumeRole");
$this->setProtocol("https");
}
private $durationSeconds;
private $policy;
private $roleArn;
private $roleSessionName;
public function getDurationSeconds() {
return $this->durationSeconds;
}
public function setDurationSeconds($durationSeconds) {
$this->durationSeconds = $durationSeconds;
$this->queryParameters["DurationSeconds"]=$durationSeconds;
}
public function getPolicy() {
return $this->policy;
}
public function setPolicy($policy) {
$this->policy = $policy;
$this->queryParameters["Policy"]=$policy;
}
public function getRoleArn() {
return $this->roleArn;
}
public function setRoleArn($roleArn) {
$this->roleArn = $roleArn;
$this->queryParameters["RoleArn"]=$roleArn;
}
public function getRoleSessionName() {
return $this->roleSessionName;
}
public function setRoleSessionName($roleSessionName) {
$this->roleSessionName = $roleSessionName;
$this->queryParameters["RoleSessionName"]=$roleSessionName;
}
}

View File

@@ -0,0 +1 @@
d35f126a-3a1f-46c0-9323-0ad130651687

View File

@@ -0,0 +1,208 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipBodyAnalysis extends AipBase {
/**
* 人体关键点识别 body_analysis api url
* @var string
*/
private $bodyAnalysisUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis';
/**
* 人体检测与属性识别 body_attr api url
* @var string
*/
private $bodyAttrUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_attr';
/**
* 人流量统计 body_num api url
* @var string
*/
private $bodyNumUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_num';
/**
* 手势识别 gesture api url
* @var string
*/
private $gestureUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/gesture';
/**
* 人像分割 body_seg api url
* @var string
*/
private $bodySegUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_seg';
/**
* 驾驶行为分析 driver_behavior api url
* @var string
*/
private $driverBehaviorUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/driver_behavior';
/**
* 人流量统计-动态版 body_tracking api url
* @var string
*/
private $bodyTrackingUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_tracking';
/**
* 人体关键点识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function bodyAnalysis($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->bodyAnalysisUrl, $data);
}
/**
* 人体检测与属性识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* type gender,<br>age,<br>lower_wear,<br>upper_wear,<br>headwear,<br>glasses,<br>upper_color,<br>lower_color,<br>cellphone,<br>upper_wear_fg,<br>upper_wear_texture,<br>lower_wear_texture,<br>orientation,<br>umbrella,<br>bag,<br>smoke,<br>vehicle,<br>carrying_item,<br>upper_cut,<br>lower_cut,<br>occlusion &#124; 1可选值说明<br>gender-性别,<br>age-年龄阶段,<br>lower_wear-下身服饰,<br>upper_wear-上身服饰,<br>headwear-是否戴帽子,<br>glasses-是否戴眼镜,<br>upper_color-上身服饰颜色,<br>lower_color-下身服饰颜色,<br>cellphone-是否使用手机,<br>upper_wear_fg-上身服饰细分类,<br>upper_wear_texture-上身服饰纹理,<br>orientation-身体朝向,<br>umbrella-是否撑伞;<br>bag-背包,<br>smoke-是否吸烟,<br>vehicle-交通工具,<br>carrying_item-是否有手提物,<br>upper_cut-上方截断,<br>lower_cut-下方截断,<br>occlusion-遮挡<br>2type 参数值可以是可选值的组合,用逗号分隔;**如果无此参数默认输出全部20个属性**
* @return array
*/
public function bodyAttr($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->bodyAttrUrl, $data);
}
/**
* 人流量统计接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* area 特定框选区域坐标逗号分隔x1,y1,x2,y2,x3,y3...xn,yn',默认尾点和首点相连做闭合,**此参数为空或无此参数默认识别整个图片的人数**
* show 是否输出渲染的图片,默认不返回,**选true时返回渲染后的图片(base64)**其它无效值或为空则默认false
* @return array
*/
public function bodyNum($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->bodyNumUrl, $data);
}
/**
* 手势识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function gesture($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->gestureUrl, $data);
}
/**
* 人像分割接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* type 可以通过设置type参数自主设置返回哪些结果图避免造成带宽的浪费<br>1可选值说明<br>labelmap - 二值图像,需二次处理方能查看分割效果<br>scoremap - 人像前景灰度图<br>foreground - 人像前景抠图,透明背景<br>2type 参数值可以是可选值的组合用逗号分隔如果无此参数默认输出全部3类结果图
* @return array
*/
public function bodySeg($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->bodySegUrl, $data);
}
/**
* 驾驶行为分析接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* type smoke,cellphone,<br>not_buckling_up,<br>both_hands_leaving_wheel,<br>not_facing_front |识别的属性行为类别,英文逗号分隔,默认所有属性都识别;<br>smoke //吸烟,<br>cellphone //打手机 <br>not_buckling_up // 未系安全带,<br>both_hands_leaving_wheel // 双手离开方向盘,<br>not_facing_front // 视角未看前方
* @return array
*/
public function driverBehavior($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->driverBehaviorUrl, $data);
}
/**
* 人流量统计-动态版接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param string $dynamic - true动态人流量统计返回总人数、跟踪ID、区域进出人数<br>false静态人数统计返回总人数
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* case_id 任务ID通过case_id区分不同视频流自拟不同序列间不可重复即可
* case_init 每个case的初始化信号为true时对该case下的跟踪算法进行初始化为false时重载该case的跟踪状态。当为false且读取不到相应case的信息时直接重新初始化
* show 否返回结果图含统计值和跟踪框渲染默认不返回选true时返回渲染后的图片(base64)其它无效值或为空则默认false
* area 静态人数统计时,只统计区域内的人,缺省时为全图统计。<br>动态人流量统计时,进出区域的人流会被统计。<br>逗号分隔x1,y1,x2,y2,x3,y3...xn,yn'按顺序依次给出每个顶点的xy坐标默认尾点和首点相连形成闭合多边形区域。<br>服务会做范围顶点左边需在图像范围内及个数校验数组长度必须为偶数且大于3个顶点。只支持单个多边形区域建议设置矩形框即4个顶点。**坐标取值不能超过图像宽度和高度比如1280的宽度坐标值最小建议从1开始最大到1279**。
* @return array
*/
public function bodyTracking($image, $dynamic, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data['dynamic'] = $dynamic;
$data = array_merge($data, $options);
return $this->request($this->bodyTrackingUrl, $data);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'AipImageCensor.php';
/**
* 内容审核
*/
class AipContentCensor extends AipImageCensor{
}

View File

@@ -0,0 +1,544 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipFace extends AipBase {
/**
* 人脸检测 detect api url
* @var string
*/
private $detectUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/detect';
/**
* 人脸搜索 search api url
* @var string
*/
private $searchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/search';
/**
* 人脸搜索 M:N 识别 multi_search api url
* @var string
*/
private $multiSearchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/multi-search';
/**
* 人脸注册 user_add api url
* @var string
*/
private $userAddUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add';
/**
* 人脸更新 user_update api url
* @var string
*/
private $userUpdateUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update';
/**
* 人脸删除 face_delete api url
* @var string
*/
private $faceDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/delete';
/**
* 用户信息查询 user_get api url
* @var string
*/
private $userGetUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/get';
/**
* 获取用户人脸列表 face_getlist api url
* @var string
*/
private $faceGetlistUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/getlist';
/**
* 获取用户列表 group_getusers api url
* @var string
*/
private $groupGetusersUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getusers';
/**
* 复制用户 user_copy api url
* @var string
*/
private $userCopyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/copy';
/**
* 删除用户 user_delete api url
* @var string
*/
private $userDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/delete';
/**
* 创建用户组 group_add api url
* @var string
*/
private $groupAddUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/add';
/**
* 删除用户组 group_delete api url
* @var string
*/
private $groupDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/delete';
/**
* 组列表查询 group_getlist api url
* @var string
*/
private $groupGetlistUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getlist';
/**
* 身份验证 person_verify api url
* @var string
*/
private $personVerifyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/person/verify';
/**
* 语音校验码接口 video_sessioncode api url
* @var string
*/
private $videoSessioncodeUrl = 'https://aip.baidubce.com/rest/2.0/face/v1/faceliveness/sessioncode';
/**
* 人脸检测接口
*
* @param string $image - 图片信息(**总数据大小应小于10M**)图片上传方式根据image_type来判断
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* face_field 包括**age,beauty,expression,face_shape,gender,glasses,landmark,landmark72landmark150race,quality,eye_status,emotion,face_type信息** <br> 逗号分隔. 默认只返回face_token、人脸框、概率和旋转角度
* max_face_num 最多处理人脸的数目默认值为1仅检测图片中面积最大的那个人脸**最大值10**,检测图片中面积最大的几张人脸。
* face_type 人脸的类型 **LIVE**表示生活照:通常为手机、相机拍摄的人像图片、或从网络获取的人像图片等**IDCARD**表示身份证芯片照:二代身份证内置芯片中的人像照片 **WATERMARK**表示带水印证件照:一般为带水印的小图,如公安网小图 **CERT**表示证件照片:如拍摄的身份证、工卡、护照、学生证等证件图片 默认**LIVE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* @return array
*/
public function detect($image, $imageType, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data = array_merge($data, $options);
return $this->request($this->detectUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸搜索接口
*
* @param string $image - 图片信息(**总数据大小应小于10M**)图片上传方式根据image_type来判断
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param string $groupIdList - 从指定的group中进行查找 用逗号分隔,**上限20个**
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* max_face_num 最多处理人脸的数目<br>**默认值为1(仅检测图片中面积最大的那个人脸)** **最大值10**
* match_threshold 匹配阈值设置阈值后score低于此阈值的用户信息将不会返回 最大100 最小0 默认80 <br>**此阈值设置得越高,检索速度将会越快,推荐使用默认阈值`80`**
* quality_control 图片质量控制 **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* user_id 当需要对特定用户进行比对时指定user_id进行比对。即人脸认证功能。
* max_user_num 查找后返回的用户数量。返回相似度最高的几个用户默认为1最多返回50个。
* @return array
*/
public function search($image, $imageType, $groupIdList, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data['group_id_list'] = $groupIdList;
$data = array_merge($data, $options);
return $this->request($this->searchUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸搜索 M:N 识别接口
*
* @param string $image - 图片信息(**总数据大小应小于10M**)图片上传方式根据image_type来判断
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param string $groupIdList - 从指定的group中进行查找 用逗号分隔,**上限20个**
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* max_face_num 最多处理人脸的数目<br>**默认值为1(仅检测图片中面积最大的那个人脸)** **最大值10**
* match_threshold 匹配阈值设置阈值后score低于此阈值的用户信息将不会返回 最大100 最小0 默认80 <br>**此阈值设置得越高,检索速度将会越快,推荐使用默认阈值`80`**
* quality_control 图片质量控制 **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* max_user_num 查找后返回的用户数量。返回相似度最高的几个用户默认为1最多返回50个。
* @return array
*/
public function multiSearch($image, $imageType, $groupIdList, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data['group_id_list'] = $groupIdList;
$data = array_merge($data, $options);
return $this->request($this->multiSearchUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸注册接口
*
* @param string $image - 图片信息(总数据大小应小于10M)图片上传方式根据image_type来判断。注组内每个uid下的人脸图片数目上限为20张
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* user_info 用户资料长度限制256B
* quality_control 图片质量控制 **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* action_type 操作方式 APPEND: 当user_id在库中已经存在时对此user_id重复注册时新注册的图片默认会追加到该user_id下,REPLACE : 当对此user_id重复注册时,则会用新图替换库中该user_id下所有图片,默认使用APPEND
* @return array
*/
public function addUser($image, $imageType, $groupId, $userId, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data['group_id'] = $groupId;
$data['user_id'] = $userId;
$data = array_merge($data, $options);
return $this->request($this->userAddUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸更新接口
*
* @param string $image - 图片信息(**总数据大小应小于10M**)图片上传方式根据image_type来判断
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param string $groupId - 更新指定groupid下uid对应的信息
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* user_info 用户资料长度限制256B
* quality_control 图片质量控制 **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* action_type 操作方式 APPEND: 当user_id在库中已经存在时对此user_id重复注册时新注册的图片默认会追加到该user_id下,REPLACE : 当对此user_id重复注册时,则会用新图替换库中该user_id下所有图片,默认使用APPEND
* @return array
*/
public function updateUser($image, $imageType, $groupId, $userId, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data['group_id'] = $groupId;
$data['user_id'] = $userId;
$data = array_merge($data, $options);
return $this->request($this->userUpdateUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸删除接口
*
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param string $faceToken - 需要删除的人脸图片token由数字、字母、下划线组成长度限制64B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function faceDelete($userId, $groupId, $faceToken, $options=array()){
$data = array();
$data['user_id'] = $userId;
$data['group_id'] = $groupId;
$data['face_token'] = $faceToken;
$data = array_merge($data, $options);
return $this->request($this->faceDeleteUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 用户信息查询接口
*
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function getUser($userId, $groupId, $options=array()){
$data = array();
$data['user_id'] = $userId;
$data['group_id'] = $groupId;
$data = array_merge($data, $options);
return $this->request($this->userGetUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 获取用户人脸列表接口
*
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function faceGetlist($userId, $groupId, $options=array()){
$data = array();
$data['user_id'] = $userId;
$data['group_id'] = $groupId;
$data = array_merge($data, $options);
return $this->request($this->faceGetlistUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 获取用户列表接口
*
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* start 默认值0起始序号
* length 返回数量默认值100最大值1000
* @return array
*/
public function getGroupUsers($groupId, $options=array()){
$data = array();
$data['group_id'] = $groupId;
$data = array_merge($data, $options);
return $this->request($this->groupGetusersUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 复制用户接口
*
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* src_group_id 从指定组里复制信息
* dst_group_id 需要添加用户的组id
* @return array
*/
public function userCopy($userId, $options=array()){
$data = array();
$data['user_id'] = $userId;
$data = array_merge($data, $options);
return $this->request($this->userCopyUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 删除用户接口
*
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param string $userId - 用户id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function deleteUser($groupId, $userId, $options=array()){
$data = array();
$data['group_id'] = $groupId;
$data['user_id'] = $userId;
$data = array_merge($data, $options);
return $this->request($this->userDeleteUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 创建用户组接口
*
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function groupAdd($groupId, $options=array()){
$data = array();
$data['group_id'] = $groupId;
$data = array_merge($data, $options);
return $this->request($this->groupAddUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 删除用户组接口
*
* @param string $groupId - 用户组id由数字、字母、下划线组成长度限制128B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function groupDelete($groupId, $options=array()){
$data = array();
$data['group_id'] = $groupId;
$data = array_merge($data, $options);
return $this->request($this->groupDeleteUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 组列表查询接口
*
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* start 默认值0起始序号
* length 返回数量默认值100最大值1000
* @return array
*/
public function getGroupList($options=array()){
$data = array();
$data = array_merge($data, $options);
return $this->request($this->groupGetlistUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 身份验证接口
*
* @param string $image - 图片信息(**总数据大小应小于10M**)图片上传方式根据image_type来判断
* @param string $imageType - 图片类型 **BASE64**:图片的base64值base64编码后的图片数据需urlencode编码后的图片大小不超过2M**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**FACE_TOKEN**: 人脸图片的唯一标识调用人脸检测接口时会为每个人脸图片赋予一个唯一的FACE_TOKEN同一张图片多次检测得到的FACE_TOKEN是同一个
* @param string $idCardNumber - 身份证号(真实身份证号号码)
* @param string $name - utf8姓名真实姓名和身份证号匹配
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* quality_control 图片质量控制 **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
* liveness_control 活体检测控制 **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
* @return array
*/
public function personVerify($image, $imageType, $idCardNumber, $name, $options=array()){
$data = array();
$data['image'] = $image;
$data['image_type'] = $imageType;
$data['id_card_number'] = $idCardNumber;
$data['name'] = $name;
$data = array_merge($data, $options);
return $this->request($this->personVerifyUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 语音校验码接口接口
*
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* appid 百度云创建应用时的唯一标识ID
* @return array
*/
public function videoSessioncode($options=array()){
$data = array();
$data = array_merge($data, $options);
return $this->request($this->videoSessioncodeUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* 在线活体检测 faceverify api url
* @var string
*/
private $faceverifyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceverify';
/**
* 在线活体检测接口
*
* @param array $images
* @return array
*/
public function faceverify($images){
return $this->request($this->faceverifyUrl, json_encode($images), array(
'Content-Type' => 'application/json',
));
}
/**
* 人脸比对 match api url
* @var string
*/
private $matchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/match';
/**
* 人脸比对接口
*
* @param array $images
* @return array
*/
public function match($images){
return $this->request($this->matchUrl, json_encode($images), array(
'Content-Type' => 'application/json',
));
}
}

View File

@@ -0,0 +1,211 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
/**
* 黄反识别
*/
class AipImageCensor extends AipBase{
/**
* antiporn api url
* @var string
*/
private $antiPornUrl = 'https://aip.baidubce.com/rest/2.0/antiporn/v1/detect';
/**
* antiporn gif api url
* @var string
*/
private $antiPornGifUrl = 'https://aip.baidubce.com/rest/2.0/antiporn/v1/detect_gif';
/**
* antiterror api url
* @var string
*/
private $antiTerrorUrl = 'https://aip.baidubce.com/rest/2.0/antiterror/v1/detect';
/**
* @var string
*/
private $faceAuditUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/face_audit';
/**
* @var string
*/
private $imageCensorCombUrl = 'https://aip.baidubce.com/api/v1/solution/direct/img_censor';
/**
* @var string
*/
private $imageCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/user_defined';
/**
* @var string
*/
private $antiSpamUrl = 'https://aip.baidubce.com/rest/2.0/antispam/v2/spam';
/**
* @param string $image 图像读取
* @return array
*/
public function antiPorn($image){
$data = array();
$data['image'] = base64_encode($image);
return $this->request($this->antiPornUrl, $data);
}
/**
* @param string $image 图像读取
* @return array
*/
public function multi_antiporn($images){
$data = array();
foreach($images as $image){
$data[] = array(
'image' => base64_encode($image),
);
}
return $this->multi_request($this->antiPornUrl, $data);
}
/**
* @param string $image 图像读取
* @return array
*/
public function antiPornGif($image){
$data = array();
$data['image'] = base64_encode($image);
return $this->request($this->antiPornGifUrl, $data);
}
/**
* @param string $image 图像读取
* @return array
*/
public function antiTerror($image){
$data = array();
$data['image'] = base64_encode($image);
return $this->request($this->antiTerrorUrl, $data);
}
/**
* @param string $images 图像读取
* @return array
*/
public function faceAudit($images, $configId=''){
// 非数组则处理为数组
if(!is_array($images)){
$images = array(
$images,
);
}
$data = array(
'configId' => $configId,
);
$isUrl = substr(trim($images[0]), 0, 4) === 'http';
if(!$isUrl){
$arr = array();
foreach($images as $image){
$arr[] = base64_encode($image);
}
$data['images'] = implode(',', $arr);
}else{
$urls = array();
foreach($images as $url){
$urls[] = urlencode($url);
}
$data['imgUrls'] = implode(',', $urls);
}
return $this->request($this->faceAuditUrl, $data);
}
/**
* @param string $image 图像读取
* @return array
*/
public function imageCensorComb($image, $scenes='antiporn', $options=array()){
$scenes = !is_array($scenes) ? explode(',', $scenes) : $scenes;
$data = array(
'scenes' => $scenes,
);
$isUrl = substr(trim($image), 0, 4) === 'http';
if(!$isUrl){
$data['image'] = base64_encode($image);
}else{
$data['imgUrl'] = $image;
}
$data = array_merge($data, $options);
return $this->request($this->imageCensorCombUrl, json_encode($data), array(
'Content-Type' => 'application/json',
));
}
/**
* @param string $image 图像
* @return array
*/
public function imageCensorUserDefined($image){
$data = array();
$isUrl = substr(trim($image), 0, 4) === 'http';
if(!$isUrl){
$data['image'] = base64_encode($image);
}else{
$data['imgUrl'] = $image;
}
return $this->request($this->imageCensorUserDefinedUrl, $data);
}
/**
* @param string $content
* @return array
*/
public function antiSpam($content, $options=array()){
$data = array();
$data['content'] = $content;
$data = array_merge($data, $options);
return $this->request($this->antiSpamUrl, $data);
}
}

View File

@@ -0,0 +1,304 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipImageClassify extends AipBase {
/**
* 通用物体识别 advanced_general api url
* @var string
*/
private $advancedGeneralUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general';
/**
* 菜品识别 dish_detect api url
* @var string
*/
private $dishDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/dish';
/**
* 车辆识别 car_detect api url
* @var string
*/
private $carDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car';
/**
* logo商标识别 logo_search api url
* @var string
*/
private $logoSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/logo';
/**
* logo商标识别—添加 logo_add api url
* @var string
*/
private $logoAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add';
/**
* logo商标识别—删除 logo_delete api url
* @var string
*/
private $logoDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete';
/**
* 动物识别 animal_detect api url
* @var string
*/
private $animalDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/animal';
/**
* 植物识别 plant_detect api url
* @var string
*/
private $plantDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/plant';
/**
* 图像主体检测 object_detect api url
* @var string
*/
private $objectDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect';
/**
* 地标识别 landmark api url
* @var string
*/
private $landmarkUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark';
/**
* 通用物体识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function advancedGeneral($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->advancedGeneralUrl, $data);
}
/**
* 菜品识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为5
* filter_threshold 默认0.95,可以通过该参数调节识别效果,降低非菜识别率.
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function dishDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->dishDetectUrl, $data);
}
/**
* 车辆识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为5
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function carDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->carDetectUrl, $data);
}
/**
* logo商标识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* custom_lib 是否只使用自定义logo库的结果默认false返回自定义库+默认库的识别结果
* @return array
*/
public function logoSearch($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->logoSearchUrl, $data);
}
/**
* logo商标识别—添加接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param string $brief - brief检索时带回。此处要传对应的name与code字段name长度小于100Bcode长度小于150B
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoAdd($image, $brief, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data['brief'] = $brief;
$data = array_merge($data, $options);
return $this->request($this->logoAddUrl, $data);
}
/**
* logo商标识别—删除接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoDeleteByImage($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->logoDeleteUrl, $data);
}
/**
* logo商标识别—删除接口
*
* @param string $contSign - 图片签名和image二选一image优先级更高
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function logoDeleteBySign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->logoDeleteUrl, $data);
}
/**
* 动物识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* top_num 返回预测得分top结果数默认为6
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function animalDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->animalDetectUrl, $data);
}
/**
* 植物识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* baike_num 返回百科信息的结果数,默认不返回
* @return array
*/
public function plantDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->plantDetectUrl, $data);
}
/**
* 图像主体检测接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* with_face 如果检测主体是人主体区域是否带上人脸部分0-不带人脸区域,其他-带人脸区域,裁剪类需求推荐带人脸,检索/识别类需求推荐不带人脸。默认取1带人脸。
* @return array
*/
public function objectDetect($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->objectDetectUrl, $data);
}
/**
* 地标识别接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function landmark($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->landmarkUrl, $data);
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipImageProcess extends AipBase {
/**
* 图像无损放大 image_quality_enhance api url
* @var string
*/
private $imageQualityEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/image_quality_enhance';
/**
* 图像去雾 dehaze api url
* @var string
*/
private $dehazeUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/dehaze';
/**
* 图像对比度增强 contrast_enhance api url
* @var string
*/
private $contrastEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/contrast_enhance';
/**
* 图像无损放大接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function imageQualityEnhance($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->imageQualityEnhanceUrl, $data);
}
/**
* 图像去雾接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function dehaze($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->dehazeUrl, $data);
}
/**
* 图像对比度增强接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function contrastEnhance($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->contrastEnhanceUrl, $data);
}
}

View File

@@ -0,0 +1,724 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipImageSearch extends AipBase {
/**
* 相同图检索—入库 same_hq_add api url
* @var string
*/
private $sameHqAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add';
/**
* 相同图检索—检索 same_hq_search api url
* @var string
*/
private $sameHqSearchUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/search';
/**
* 相同图检索—更新 same_hq_update api url
* @var string
*/
private $sameHqUpdateUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/update';
/**
* 相同图检索—删除 same_hq_delete api url
* @var string
*/
private $sameHqDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/delete';
/**
* 相似图检索—入库 similar_add api url
* @var string
*/
private $similarAddUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add';
/**
* 相似图检索—检索 similar_search api url
* @var string
*/
private $similarSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/search';
/**
* 相似图检索—更新 similar_update api url
* @var string
*/
private $similarUpdateUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/update';
/**
* 相似图检索—删除 similar_delete api url
* @var string
*/
private $similarDeleteUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/delete';
/**
* 商品检索—入库 product_add api url
* @var string
*/
private $productAddUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/add';
/**
* 商品检索—检索 product_search api url
* @var string
*/
private $productSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/search';
/**
* 商品检索—更新 product_update api url
* @var string
*/
private $productUpdateUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/update';
/**
* 商品检索—删除 product_delete api url
* @var string
*/
private $productDeleteUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/delete';
/**
* 相同图检索—入库接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function sameHqAdd($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->sameHqAddUrl, $data);
}
/**
* 相同图检索—入库接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function sameHqAddUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->sameHqAddUrl, $data);
}
/**
* 相同图检索—检索接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* tag_logic 检索时tag之间的逻辑 0逻辑and1逻辑or
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function sameHqSearch($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->sameHqSearchUrl, $data);
}
/**
* 相同图检索—检索接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* tag_logic 检索时tag之间的逻辑 0逻辑and1逻辑or
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function sameHqSearchUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->sameHqSearchUrl, $data);
}
/**
* 相同图检索—更新接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function sameHqUpdate($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->sameHqUpdateUrl, $data);
}
/**
* 相同图检索—更新接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function sameHqUpdateUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->sameHqUpdateUrl, $data);
}
/**
* 相同图检索—更新接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function sameHqUpdateContSign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->sameHqUpdateUrl, $data);
}
/**
* 相同图检索—删除接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function sameHqDeleteByImage($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->sameHqDeleteUrl, $data);
}
/**
* 相同图检索—删除接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function sameHqDeleteByUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->sameHqDeleteUrl, $data);
}
/**
* 相同图检索—删除接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function sameHqDeleteBySign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->sameHqDeleteUrl, $data);
}
/**
* 相似图检索—入库接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function similarAdd($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->similarAddUrl, $data);
}
/**
* 相似图检索—入库接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function similarAddUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->similarAddUrl, $data);
}
/**
* 相似图检索—检索接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* tag_logic 检索时tag之间的逻辑 0逻辑and1逻辑or
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function similarSearch($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->similarSearchUrl, $data);
}
/**
* 相似图检索—检索接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* tag_logic 检索时tag之间的逻辑 0逻辑and1逻辑or
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function similarSearchUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->similarSearchUrl, $data);
}
/**
* 相似图检索—更新接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function similarUpdate($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->similarUpdateUrl, $data);
}
/**
* 相似图检索—更新接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function similarUpdateUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->similarUpdateUrl, $data);
}
/**
* 相似图检索—更新接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* tags 1 - 65535范围内的整数tag间以逗号分隔最多2个tag。样例"100,11" ;检索时可圈定分类维度进行检索
* @return array
*/
public function similarUpdateContSign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->similarUpdateUrl, $data);
}
/**
* 相似图检索—删除接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function similarDeleteByImage($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->similarDeleteUrl, $data);
}
/**
* 相似图检索—删除接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function similarDeleteByUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->similarDeleteUrl, $data);
}
/**
* 相似图检索—删除接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function similarDeleteBySign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->similarDeleteUrl, $data);
}
/**
* 商品检索—入库接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。**请注意检索接口不返回原图仅反馈当前填写的brief信息所以调用该入库接口时brief信息请尽量填写可关联至本地图库的图片id或者图片url、图片名称等信息**
* class_id1 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* class_id2 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* @return array
*/
public function productAdd($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->productAddUrl, $data);
}
/**
* 商品检索—入库接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 检索时原样带回,最长256B。**请注意检索接口不返回原图仅反馈当前填写的brief信息所以调用该入库接口时brief信息请尽量填写可关联至本地图库的图片id或者图片url、图片名称等信息**
* class_id1 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* class_id2 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* @return array
*/
public function productAddUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->productAddUrl, $data);
}
/**
* 商品检索—检索接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* class_id1 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* class_id2 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function productSearch($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->productSearchUrl, $data);
}
/**
* 商品检索—检索接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* class_id1 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* class_id2 商品分类维度1支持1-60范围内的整数。检索时可圈定该分类维度进行检索
* pn 分页功能起始位置0。未指定分页时默认返回前300个结果接口返回数量最大限制1000条例如起始位置为900截取条数500条接口也只返回第900 - 1000条的结果共计100条
* rn 分页功能截取条数250
* @return array
*/
public function productSearchUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->productSearchUrl, $data);
}
/**
* 商品检索—更新接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* class_id1 更新的商品分类1支持1-60范围内的整数。
* class_id2 更新的商品分类2支持1-60范围内的整数。
* @return array
*/
public function productUpdate($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->productUpdateUrl, $data);
}
/**
* 商品检索—更新接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* class_id1 更新的商品分类1支持1-60范围内的整数。
* class_id2 更新的商品分类2支持1-60范围内的整数。
* @return array
*/
public function productUpdateUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->productUpdateUrl, $data);
}
/**
* 商品检索—更新接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* brief 更新的摘要信息最长256B。样例{"name":"周杰伦", "id":"666"}
* class_id1 更新的商品分类1支持1-60范围内的整数。
* class_id2 更新的商品分类2支持1-60范围内的整数。
* @return array
*/
public function productUpdateContSign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->productUpdateUrl, $data);
}
/**
* 商品检索—删除接口
*
* @param string $image - 图像数据base64编码要求base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function productDeleteByImage($image, $options=array()){
$data = array();
$data['image'] = base64_encode($image);
$data = array_merge($data, $options);
return $this->request($this->productDeleteUrl, $data);
}
/**
* 商品检索—删除接口
*
* @param string $url - 图片完整URLURL长度不超过1024字节URL对应的图片base64编码后大小不超过4M最短边至少15px最长边最大4096px,支持jpg/png/bmp格式当image字段存在时url字段失效
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function productDeleteByUrl($url, $options=array()){
$data = array();
$data['url'] = $url;
$data = array_merge($data, $options);
return $this->request($this->productDeleteUrl, $data);
}
/**
* 商品检索—删除接口
*
* @param string $contSign - 图片签名
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function productDeleteBySign($contSign, $options=array()){
$data = array();
$data['cont_sign'] = $contSign;
$data = array_merge($data, $options);
return $this->request($this->productDeleteUrl, $data);
}
}

View File

@@ -0,0 +1,189 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipKg extends AipBase {
/**
* 创建任务 create_task api url
* @var string
*/
private $createTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_create';
/**
* 更新任务 update_task api url
* @var string
*/
private $updateTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_update';
/**
* 获取任务详情 task_info api url
* @var string
*/
private $taskInfoUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_info';
/**
* 以分页的方式查询当前用户所有的任务信息 task_query api url
* @var string
*/
private $taskQueryUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_query';
/**
* 启动任务 task_start api url
* @var string
*/
private $taskStartUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_start';
/**
* 查询任务状态 task_status api url
* @var string
*/
private $taskStatusUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_status';
/**
* 创建任务接口
*
* @param string $name - 任务名字
* @param string $templateContent - json string 解析模板内容
* @param string $inputMappingFile - 抓取结果映射文件的路径
* @param string $outputFile - 输出文件名字
* @param string $urlPattern - url pattern
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* limit_count 限制解析数量limit_count为0时进行全量任务limit_count&gt;0时只解析limit_count数量的页面
* @return array
*/
public function createTask($name, $templateContent, $inputMappingFile, $outputFile, $urlPattern, $options=array()){
$data = array();
$data['name'] = $name;
$data['template_content'] = $templateContent;
$data['input_mapping_file'] = $inputMappingFile;
$data['output_file'] = $outputFile;
$data['url_pattern'] = $urlPattern;
$data = array_merge($data, $options);
return $this->request($this->createTaskUrl, $data);
}
/**
* 更新任务接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* name 任务名字
* template_content json string 解析模板内容
* input_mapping_file 抓取结果映射文件的路径
* url_pattern url pattern
* output_file 输出文件名字
* @return array
*/
public function updateTask($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->updateTaskUrl, $data);
}
/**
* 获取任务详情接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function getTaskInfo($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskInfoUrl, $data);
}
/**
* 以分页的方式查询当前用户所有的任务信息接口
*
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* id 任务ID精确匹配
* name 中缀模糊匹配,abc可以匹配abc,aaabc,abcde等
* status 要筛选的任务状态
* page 页码
* per_page 页码
* @return array
*/
public function getUserTasks($options=array()){
$data = array();
$data = array_merge($data, $options);
return $this->request($this->taskQueryUrl, $data);
}
/**
* 启动任务接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function startTask($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskStartUrl, $data);
}
/**
* 查询任务状态接口
*
* @param integer $id - 任务ID
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function getTaskStatus($id, $options=array()){
$data = array();
$data['id'] = $id;
$data = array_merge($data, $options);
return $this->request($this->taskStatusUrl, $data);
}
}

View File

@@ -0,0 +1,409 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
class AipNlp extends AipBase {
/**
* 词法分析 lexer api url
* @var string
*/
private $lexerUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer';
/**
* 词法分析(定制版) lexer_custom api url
* @var string
*/
private $lexerCustomUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer_custom';
/**
* 依存句法分析 dep_parser api url
* @var string
*/
private $depParserUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/depparser';
/**
* 词向量表示 word_embedding api url
* @var string
*/
private $wordEmbeddingUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/word_emb_vec';
/**
* DNN语言模型 dnnlm_cn api url
* @var string
*/
private $dnnlmCnUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/dnnlm_cn';
/**
* 词义相似度 word_sim_embedding api url
* @var string
*/
private $wordSimEmbeddingUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/word_emb_sim';
/**
* 短文本相似度 simnet api url
* @var string
*/
private $simnetUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/simnet';
/**
* 评论观点抽取 comment_tag api url
* @var string
*/
private $commentTagUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag';
/**
* 情感倾向分析 sentiment_classify api url
* @var string
*/
private $sentimentClassifyUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/sentiment_classify';
/**
* 文章标签 keyword api url
* @var string
*/
private $keywordUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/keyword';
/**
* 文章分类 topic api url
* @var string
*/
private $topicUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/topic';
/**
* 文本纠错 ecnet api url
* @var string
*/
private $ecnetUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/ecnet';
/**
* 对话情绪识别接口 emotion api url
* @var string
*/
private $emotionUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/emotion';
/**
* 新闻摘要接口 news_summary api url
* @var string
*/
private $newsSummaryUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/news_summary';
/**
* 格式化结果
* @param $content string
* @return mixed
*/
protected function proccessResult($content){
return json_decode(mb_convert_encoding($content, 'UTF8', 'GBK'), true, 512, JSON_BIGINT_AS_STRING);
}
/**
* 词法分析接口
*
* @param string $text - 待分析文本目前仅支持GBK编码长度不超过65536字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function lexer($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->lexerUrl, $data);
}
/**
* 词法分析(定制版)接口
*
* @param string $text - 待分析文本目前仅支持GBK编码长度不超过65536字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function lexerCustom($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->lexerCustomUrl, $data);
}
/**
* 依存句法分析接口
*
* @param string $text - 待分析文本目前仅支持GBK编码长度不超过256字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* mode 模型选择。默认值为0可选值mode=0对应web模型mode=1对应query模型
* @return array
*/
public function depParser($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->depParserUrl, $data);
}
/**
* 词向量表示接口
*
* @param string $word - 文本内容GBK编码最大64字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function wordEmbedding($word, $options=array()){
$data = array();
$data['word'] = $word;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->wordEmbeddingUrl, $data);
}
/**
* DNN语言模型接口
*
* @param string $text - 文本内容GBK编码最大512字节不需要切词
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function dnnlm($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->dnnlmCnUrl, $data);
}
/**
* 词义相似度接口
*
* @param string $word1 - 词1GBK编码最大64字节
* @param string $word2 - 词1GBK编码最大64字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* mode 预留字段可选择不同的词义相似度模型。默认值为0目前仅支持mode=0
* @return array
*/
public function wordSimEmbedding($word1, $word2, $options=array()){
$data = array();
$data['word_1'] = $word1;
$data['word_2'] = $word2;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->wordSimEmbeddingUrl, $data);
}
/**
* 短文本相似度接口
*
* @param string $text1 - 待比较文本1GBK编码最大512字节
* @param string $text2 - 待比较文本2GBK编码最大512字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* model 默认为"BOW",可选"BOW"、"CNN"与"GRNN"
* @return array
*/
public function simnet($text1, $text2, $options=array()){
$data = array();
$data['text_1'] = $text1;
$data['text_2'] = $text2;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->simnetUrl, $data);
}
/**
* 评论观点抽取接口
*
* @param string $text - 评论内容GBK编码最大10240字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* type 评论行业类型默认为4餐饮美食
* @return array
*/
public function commentTag($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->commentTagUrl, $data);
}
/**
* 情感倾向分析接口
*
* @param string $text - 文本内容GBK编码最大102400字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function sentimentClassify($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->sentimentClassifyUrl, $data);
}
/**
* 文章标签接口
*
* @param string $title - 篇章的标题最大80字节
* @param string $content - 篇章的正文最大65535字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function keyword($title, $content, $options=array()){
$data = array();
$data['title'] = $title;
$data['content'] = $content;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->keywordUrl, $data);
}
/**
* 文章分类接口
*
* @param string $title - 篇章的标题最大80字节
* @param string $content - 篇章的正文最大65535字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function topic($title, $content, $options=array()){
$data = array();
$data['title'] = $title;
$data['content'] = $content;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->topicUrl, $data);
}
/**
* 文本纠错接口
*
* @param string $text - 待纠错文本输入限制511字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* @return array
*/
public function ecnet($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->ecnetUrl, $data);
}
/**
* 对话情绪识别接口接口
*
* @param string $text - 待识别情感文本输入限制512字节
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* scene default默认项-不区分场景talk闲聊对话-如度秘聊天等task任务型对话-如导航对话等customer_service客服对话-如电信/银行客服等)
* @return array
*/
public function emotion($text, $options=array()){
$data = array();
$data['text'] = $text;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->emotionUrl, $data);
}
/**
* 新闻摘要接口接口
*
* @param string $content - 字符串限3000字符数以内字符串仅支持GBK编码长度需小于3000字符数即6000字节请输入前确认字符数没有超限若字符数超长会返回错误。正文中如果包含段落信息请使用"\n"分隔,段落信息算法中有重要的作用,请尽量保留
* @param integer $maxSummaryLen - 此数值将作为摘要结果的最大长度。例如原文长度1000字本参数设置为150则摘要结果的最大长度是150字推荐最优区间200-500字
* @param array $options - 可选参数对象key: value都为string类型
* @description options列表:
* title 字符串限200字符数字符串仅支持GBK编码长度需小于200字符数即400字节请输入前确认字符数没有超限若字符数超长会返回错误。标题在算法中具有重要的作用若文章确无标题输入参数的“标题”字段为空即可
* @return array
*/
public function newsSummary($content, $maxSummaryLen, $options=array()){
$data = array();
$data['content'] = $content;
$data['max_summary_len'] = $maxSummaryLen;
$data = array_merge($data, $options);
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
return $this->request($this->newsSummaryUrl, $data);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,138 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
require_once 'lib/AipBase.php';
/**
* 百度语音
*/
class AipSpeech extends AipBase{
/**
* url
* @var string
*/
public $asrUrl = 'http://vop.baidu.com/server_api';
/**
* url
* @var string
*/
public $ttsUrl = 'http://tsn.baidu.com/text2audio';
/**
* 判断认证是否有权限
* @param array $authObj
* @return boolean
*/
protected function isPermission($authObj)
{
return true;
}
/**
* 处理请求参数
* @param string $url
* @param array $params
* @param array $data
* @param array $headers
*/
protected function proccessRequest($url, &$params, &$data, $headers){
$token = isset($params['access_token']) ? $params['access_token'] : '';
if(empty($data['cuid'])){
$data['cuid'] = md5($token);
}
if($url === $this->asrUrl){
$data['token'] = $token;
$data = json_encode($data);
}else{
$data['tok'] = $token;
}
unset($params['access_token']);
}
/**
* 格式化结果
* @param $content string
* @return mixed
*/
protected function proccessResult($content){
$obj = json_decode($content, true);
if($obj === null){
$obj = array(
'__json_decode_error' => $content
);
}
return $obj;
}
/**
* @param string $speech
* @param string $format
* @param int $rate
* @param array $options
* @return array
*/
public function asr($speech, $format, $rate, $options=array()){
$data = array();
if(!empty($speech)){
$data['speech'] = base64_encode($speech);
$data['len'] = strlen($speech);
}
$data['format'] = $format;
$data['rate'] = $rate;
$data['channel'] = 1;
$data = array_merge($data, $options);
return $this->request($this->asrUrl, $data, array());
}
/**
* @param string $text
* @param string $lang
* @param int $ctp
* @param array $options
* @return array
*/
public function synthesis($text, $lang='zh', $ctp=1, $options=array()){
$data = array();
$data['tex'] = $text;
$data['lan'] = $lang;
$data['ctp'] = $ctp;
$data = array_merge($data, $options);
$result = $this->request($this->ttsUrl, $data, array());
if(isset($result['__json_decode_error'])){
return $result['__json_decode_error'];
}
return $result;
}
}

View File

@@ -0,0 +1,28 @@
{
"name": "baidu/aip-sdk",
"description": "baidu pulic ai php sdk",
"authors": [
{
"name": "baidu"
}
],
"license": "Apache-2.0",
"require": {
"php": ">=5.3.3"
},
"minimum-stability": "stable",
"autoload": {
"files": [
"lib/AipBase.php",
"AipBodyAnalysis.php",
"AipContentCensor.php",
"AipFace.php",
"AipImageClassify.php",
"AipImageSearch.php",
"AipKg.php",
"AipNlp.php",
"AipOcr.php",
"AipSpeech.php"
]
}
}

View File

@@ -0,0 +1 @@
67e6fe11-3667-462b-947e-f5d4d9fe918a

View File

@@ -0,0 +1,345 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
namespace BaiduOcr\lib;
/**
* BCE Util
*/
class AipHttpUtil
{
// 根据RFC 3986除了
// 1.大小写英文字符
// 2.阿拉伯数字
// 3.点'.'、波浪线'~'、减号'-'以及下划线'_'
// 以外都要编码
public static $PERCENT_ENCODED_STRINGS;
//填充编码数组
public static function __init()
{
AipHttpUtil::$PERCENT_ENCODED_STRINGS = array();
for ($i = 0; $i < 256; ++$i) {
AipHttpUtil::$PERCENT_ENCODED_STRINGS[$i] = sprintf("%%%02X", $i);
}
//a-z不编码
foreach (range('a', 'z') as $ch) {
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
}
//A-Z不编码
foreach (range('A', 'Z') as $ch) {
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
}
//0-9不编码
foreach (range('0', '9') as $ch) {
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
}
//以下4个字符不编码
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('-')] = '-';
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('.')] = '.';
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('_')] = '_';
AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('~')] = '~';
}
/**
* 在uri编码中不能对'/'编码
* @param string $path
* @return string
*/
public static function urlEncodeExceptSlash($path)
{
return str_replace("%2F", "/", AipHttpUtil::urlEncode($path));
}
/**
* 使用编码数组编码
* @param string $path
* @return string
*/
public static function urlEncode($value)
{
$result = '';
for ($i = 0; $i < strlen($value); ++$i) {
$result .= AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($value[$i])];
}
return $result;
}
/**
* 生成标准化QueryString
* @param array $parameters
* @return array
*/
public static function getCanonicalQueryString(array $parameters)
{
//没有参数,直接返回空串
if (count($parameters) == 0) {
return '';
}
$parameterStrings = array();
foreach ($parameters as $k => $v) {
//跳过Authorization字段
if (strcasecmp('Authorization', $k) == 0) {
continue;
}
if (!isset($k)) {
throw new \InvalidArgumentException(
"parameter key should not be null"
);
}
if (isset($v)) {
//对于有值的,编码后放在=号两边
$parameterStrings[] = AipHttpUtil::urlEncode($k)
. '=' . AipHttpUtil::urlEncode((string) $v);
} else {
//对于没有值的只将key编码后放在=号的左边,右边留空
$parameterStrings[] = AipHttpUtil::urlEncode($k) . '=';
}
}
//按照字典序排序
sort($parameterStrings);
//使用'&'符号连接它们
return implode('&', $parameterStrings);
}
/**
* 生成标准化uri
* @param string $path
* @return string
*/
public static function getCanonicalURIPath($path)
{
//空路径设置为'/'
if (empty($path)) {
return '/';
} else {
//所有的uri必须以'/'开头
if ($path[0] == '/') {
return AipHttpUtil::urlEncodeExceptSlash($path);
} else {
return '/' . AipHttpUtil::urlEncodeExceptSlash($path);
}
}
}
/**
* 生成标准化http请求头串
* @param array $headers
* @return array
*/
public static function getCanonicalHeaders($headers)
{
//如果没有headers则返回空串
if (count($headers) == 0) {
return '';
}
$headerStrings = array();
foreach ($headers as $k => $v) {
//跳过key为null的
if ($k === null) {
continue;
}
//如果value为null则赋值为空串
if ($v === null) {
$v = '';
}
//trim后再encode之后使用':'号连接起来
$headerStrings[] = AipHttpUtil::urlEncode(strtolower(trim($k))) . ':' . AipHttpUtil::urlEncode(trim($v));
}
//字典序排序
sort($headerStrings);
//用'\n'把它们连接起来
return implode("\n", $headerStrings);
}
}
AipHttpUtil::__init();
class AipSignOption
{
const EXPIRATION_IN_SECONDS = 'expirationInSeconds';
const HEADERS_TO_SIGN = 'headersToSign';
const TIMESTAMP = 'timestamp';
const DEFAULT_EXPIRATION_IN_SECONDS = 1800;
const MIN_EXPIRATION_IN_SECONDS = 300;
const MAX_EXPIRATION_IN_SECONDS = 129600;
}
class AipSampleSigner
{
const BCE_AUTH_VERSION = "bce-auth-v1";
const BCE_PREFIX = 'x-bce-';
//不指定headersToSign情况下默认签名http头包括
// 1.host
// 2.content-length
// 3.content-type
// 4.content-md5
public static $defaultHeadersToSign;
public static function __init()
{
AipSampleSigner::$defaultHeadersToSign = array(
"host",
"content-length",
"content-type",
"content-md5",
);
}
/**
* 签名
* @param array $credentials
* @param string $httpMethod
* @param string $path
* @param array $headers
* @param string $params
* @param array $options
* @return string
*/
public static function sign(
array $credentials,
$httpMethod,
$path,
$headers,
$params,
$options = array()
) {
//设定签名有效时间
if (!isset($options[AipSignOption::EXPIRATION_IN_SECONDS])) {
//默认值1800秒
$expirationInSeconds = AipSignOption::DEFAULT_EXPIRATION_IN_SECONDS;
} else {
$expirationInSeconds = $options[AipSignOption::EXPIRATION_IN_SECONDS];
}
//解析ak sk
$accessKeyId = $credentials['ak'];
$secretAccessKey = $credentials['sk'];
//设定时间戳注意如果自行指定时间戳需要为UTC时间
if (!isset($options[AipSignOption::TIMESTAMP])) {
//默认值当前时间
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
} else {
$timestamp = $options[AipSignOption::TIMESTAMP];
}
//生成authString
$authString = AipSampleSigner::BCE_AUTH_VERSION . '/' . $accessKeyId . '/'
. $timestamp . '/' . $expirationInSeconds;
//使用sk和authString生成signKey
$signingKey = hash_hmac('sha256', $authString, $secretAccessKey);
//生成标准化URI
$canonicalURI = AipHttpUtil::getCanonicalURIPath($path);
//生成标准化QueryString
$canonicalQueryString = AipHttpUtil::getCanonicalQueryString($params);
//填充headersToSign也就是指明哪些header参与签名
$headersToSign = null;
if (isset($options[AipSignOption::HEADERS_TO_SIGN])) {
$headersToSign = $options[AipSignOption::HEADERS_TO_SIGN];
}
//生成标准化header
$canonicalHeader = AipHttpUtil::getCanonicalHeaders(
AipSampleSigner::getHeadersToSign($headers, $headersToSign)
);
//整理headersToSign以';'号连接
$signedHeaders = '';
if ($headersToSign !== null) {
$signedHeaders = strtolower(
trim(implode(";", $headersToSign))
);
}
//组成标准请求串
$canonicalRequest = "$httpMethod\n$canonicalURI\n"
. "$canonicalQueryString\n$canonicalHeader";
//使用signKey和标准请求串完成签名
$signature = hash_hmac('sha256', $canonicalRequest, $signingKey);
//组成最终签名串
$authorizationHeader = "$authString/$signedHeaders/$signature";
return $authorizationHeader;
}
/**
* 根据headsToSign过滤应该参与签名的header
* @param array $headers
* @param array $headersToSign
* @return array
*/
public static function getHeadersToSign($headers, $headersToSign)
{
$arr = array();
foreach ($headersToSign as $value) {
$arr[] = strtolower(trim($value));
}
//value被trim后为空串的header不参与签名
$result = array();
foreach ($headers as $key => $value) {
if (trim($value) !== '') {
$key = strtolower(trim($key));
if (in_array($key, $arr)) {
$result[$key] = $value;
}
}
}
//返回需要参与签名的header
return $result;
}
/**
* 检查header是不是默认参加签名的
* 1.是host、content-type、content-md5、content-length之一
* 2.以x-bce开头
* @param array $header
* @return boolean
*/
public static function isDefaultHeaderToSign($header)
{
$header = strtolower(trim($header));
if (in_array($header, AipSampleSigner::$defaultHeadersToSign)) {
return true;
}
return substr_compare($header, AipSampleSigner::BCE_PREFIX, 0, strlen(AipSampleSigner::BCE_PREFIX)) == 0;
}
}
AipSampleSigner::__init();

View File

@@ -0,0 +1,398 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
namespace BaiduOcr\lib;
//require_once 'AipHttpClient.php';
//require_once 'AipBCEUtil.php';
use BaiduOcr\lib\AipHttpClient as AipHttpClient;
use BaiduOcr\lib\AipBCEUtil as AipBCEUtil;
/**
* Aip Base 基类
*/
class AipBase {
/**
* 获取access token url
* @var string
*/
protected $accessTokenUrl = 'https://aip.baidubce.com/oauth/2.0/token';
/**
* 反馈接口
* @var string
*/
protected $reportUrl = 'https://aip.baidubce.com/rpc/2.0/feedback/v1/report';
/**
* appId
* @var string
*/
protected $appId = '';
/**
* apiKey
* @var string
*/
protected $apiKey = '';
/**
* secretKey
* @var string
*/
protected $secretKey = '';
/**
* 权限
* @var array
*/
protected $scope = 'brain_all_scope';
/**
* @param string $appId
* @param string $apiKey
* @param string $secretKey
*/
public function __construct($appId, $apiKey, $secretKey){
$this->appId = trim($appId);
$this->apiKey = trim($apiKey);
$this->secretKey = trim($secretKey);
$this->isCloudUser = null;
$this->client = new AipHttpClient();
$this->version = '2_2_15';
$this->proxies = array();
}
/**
* 查看版本
* @return string
*
*/
public function getVersion(){
return $this->version;
}
/**
* 连接超时
* @param int $ms 毫秒
*/
public function setConnectionTimeoutInMillis($ms){
$this->client->setConnectionTimeoutInMillis($ms);
}
/**
* 响应超时
* @param int $ms 毫秒
*/
public function setSocketTimeoutInMillis($ms){
$this->client->setSocketTimeoutInMillis($ms);
}
/**
* 代理
* @param array $proxy
* @return string
*
*/
public function setProxies($proxies){
$this->client->setConf($proxies);
}
/**
* 处理请求参数
* @param string $url
* @param array $params
* @param array $data
* @param array $headers
*/
protected function proccessRequest($url, &$params, &$data, $headers){
$params['aipSdk'] = 'php';
$params['aipSdkVersion'] = $this->version;
}
/**
* Api 请求
* @param string $url
* @param mixed $data
* @return mixed
*/
protected function request($url, $data, $headers=array()){
try{
$result = $this->validate($url, $data);
if($result !== true){
return $result;
}
$params = array();
$authObj = $this->auth();
if($this->isCloudUser === false){
$params['access_token'] = $authObj['access_token'];
}
// 特殊处理
$this->proccessRequest($url, $params, $data, $headers);
$headers = $this->getAuthHeaders('POST', $url, $params, $headers);
$response = $this->client->post($url, $data, $params, $headers);
$obj = $this->proccessResult($response['content']);
if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){
$authObj = $this->auth(true);
$params['access_token'] = $authObj['access_token'];
$response = $this->client->post($url, $data, $params, $headers);
$obj = $this->proccessResult($response['content']);
}
if(empty($obj) || !isset($obj['error_code'])){
$this->writeAuthObj($authObj);
}
}catch(Exception $e){
return array(
'error_code' => 'SDK108',
'error_msg' => 'connection or read data timeout',
);
}
return $obj;
}
/**
* Api 多个并发请求
* @param string $url
* @param mixed $data
* @return mixed
*/
protected function multi_request($url, $data){
try{
$params = array();
$authObj = $this->auth();
$headers = $this->getAuthHeaders('POST', $url);
if($this->isCloudUser === false){
$params['access_token'] = $authObj['access_token'];
}
$responses = $this->client->multi_post($url, $data, $params, $headers);
$is_success = false;
foreach($responses as $response){
$obj = $this->proccessResult($response['content']);
if(empty($obj) || !isset($obj['error_code'])){
$is_success = true;
}
if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){
$authObj = $this->auth(true);
$params['access_token'] = $authObj['access_token'];
$responses = $this->client->post($url, $data, $params, $headers);
break;
}
}
if($is_success){
$this->writeAuthObj($authObj);
}
$objs = array();
foreach($responses as $response){
$objs[] = $this->proccessResult($response['content']);
}
}catch(Exception $e){
return array(
'error_code' => 'SDK108',
'error_msg' => 'connection or read data timeout',
);
}
return $objs;
}
/**
* 格式检查
* @param string $url
* @param array $data
* @return mix
*/
protected function validate($url, &$data){
return true;
}
/**
* 格式化结果
* @param $content string
* @return mixed
*/
protected function proccessResult($content){
return json_decode($content, true);
}
/**
* 返回 access token 路径
* @return string
*/
private function getAuthFilePath(){
return dirname(__FILE__) . DIRECTORY_SEPARATOR . md5($this->apiKey);
}
/**
* 写入本地文件
* @param array $obj
* @return void
*/
private function writeAuthObj($obj){
if($obj === null || (isset($obj['is_read']) && $obj['is_read'] === true)){
return;
}
$obj['time'] = time();
$obj['is_cloud_user'] = $this->isCloudUser;
@file_put_contents($this->getAuthFilePath(), json_encode($obj));
}
/**
* 读取本地缓存
* @return array
*/
private function readAuthObj(){
$content = @file_get_contents($this->getAuthFilePath());
if($content !== false){
$obj = json_decode($content, true);
$this->isCloudUser = $obj['is_cloud_user'];
$obj['is_read'] = true;
if($this->isCloudUser || $obj['time'] + $obj['expires_in'] - 30 > time()){
return $obj;
}
}
return null;
}
/**
* 认证
* @param bool $refresh 是否刷新
* @return array
*/
private function auth($refresh=false){
//非过期刷新
if(!$refresh){
$obj = $this->readAuthObj();
if(!empty($obj)){
return $obj;
}
}
$response = $this->client->get($this->accessTokenUrl, array(
'grant_type' => 'client_credentials',
'client_id' => $this->apiKey,
'client_secret' => $this->secretKey,
));
$obj = json_decode($response['content'], true);
$this->isCloudUser = !$this->isPermission($obj);
return $obj;
}
/**
* 判断认证是否有权限
* @param array $authObj
* @return boolean
*/
protected function isPermission($authObj)
{
if(empty($authObj) || !isset($authObj['scope'])){
return false;
}
$scopes = explode(' ', $authObj['scope']);
return in_array($this->scope, $scopes);
}
/**
* @param string $method HTTP method
* @param string $url
* @param array $param 参数
* @return array
*/
private function getAuthHeaders($method, $url, $params=array(), $headers=array()){
//不是云的老用户则不用在header中签名 认证
if($this->isCloudUser === false){
return $headers;
}
$obj = parse_url($url);
if(!empty($obj['query'])){
foreach(explode('&', $obj['query']) as $kv){
if(!empty($kv)){
list($k, $v) = explode('=', $kv, 2);
$params[$k] = $v;
}
}
}
//UTC 时间戳
$timestamp = gmdate('Y-m-d\TH:i:s\Z');
$headers['Host'] = isset($obj['port']) ? sprintf('%s:%s', $obj['host'], $obj['port']) : $obj['host'];
$headers['x-bce-date'] = $timestamp;
//签名
$headers['authorization'] = AipSampleSigner::sign(array(
'ak' => $this->apiKey,
'sk' => $this->secretKey,
), $method, $obj['path'], $headers, $params, array(
'timestamp' => $timestamp,
'headersToSign' => array_keys($headers),
));
return $headers;
}
/**
* 反馈
*
* @param array $feedbacks
* @return array
*/
public function report($feedback){
$data = array();
$data['feedback'] = $feedback;
return $this->request($this->reportUrl, $data);
}
/**
* 通用接口
* @param string $url
* @param array $data
* @param array header
* @return array
*/
public function post($url, $data, $headers=array()){
return $this->request($url, $data, $headers);
}
}

View File

@@ -0,0 +1,215 @@
<?php
/*
* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
namespace BaiduOcr\lib;
/**
* Http Client
*/
class AipHttpClient{
/**
* HttpClient
* @param array $headers HTTP header
*/
public function __construct($headers=array()){
$this->headers = $this->buildHeaders($headers);
$this->connectTimeout = 60000;
$this->socketTimeout = 60000;
$this->conf = array();
}
/**
* 连接超时
* @param int $ms 毫秒
*/
public function setConnectionTimeoutInMillis($ms){
$this->connectTimeout = $ms;
}
/**
* 响应超时
* @param int $ms 毫秒
*/
public function setSocketTimeoutInMillis($ms){
$this->socketTimeout = $ms;
}
/**
* 配置
* @param array $conf
*/
public function setConf($conf){
$this->conf = $conf;
}
/**
* 请求预处理
* @param resource $ch
*/
public function prepare($ch){
foreach($this->conf as $key => $value){
curl_setopt($ch, $key, $value);
}
}
/**
* @param string $url
* @param array $data HTTP POST BODY
* @param array $param HTTP URL
* @param array $headers HTTP header
* @return array
*/
public function post($url, $data=array(), $params=array(), $headers=array()){
$url = $this->buildUrl($url, $params);
$headers = array_merge($this->headers, $this->buildHeaders($headers));
$ch = curl_init();
$this->prepare($ch);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
$content = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($code === 0){
throw new Exception(curl_error($ch));
}
curl_close($ch);
return array(
'code' => $code,
'content' => $content,
);
}
/**
* @param string $url
* @param array $datas HTTP POST BODY
* @param array $param HTTP URL
* @param array $headers HTTP header
* @return array
*/
public function multi_post($url, $datas=array(), $params=array(), $headers=array()){
$url = $this->buildUrl($url, $params);
$headers = array_merge($this->headers, $this->buildHeaders($headers));
$chs = array();
$result = array();
$mh = curl_multi_init();
foreach($datas as $data){
$ch = curl_init();
$chs[] = $ch;
$this->prepare($ch);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
curl_multi_add_handle($mh, $ch);
}
$running = null;
do{
curl_multi_exec($mh, $running);
usleep(100);
}while($running);
foreach($chs as $ch){
$content = curl_multi_getcontent($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result[] = array(
'code' => $code,
'content' => $content,
);
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
return $result;
}
/**
* @param string $url
* @param array $param HTTP URL
* @param array $headers HTTP header
* @return array
*/
public function get($url, $params=array(), $headers=array()){
$url = $this->buildUrl($url, $params);
$headers = array_merge($this->headers, $this->buildHeaders($headers));
$ch = curl_init();
$this->prepare($ch);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
$content = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($code === 0){
throw new Exception(curl_error($ch));
}
curl_close($ch);
return array(
'code' => $code,
'content' => $content,
);
}
/**
* 构造 header
* @param array $headers
* @return array
*/
private function buildHeaders($headers){
$result = array();
foreach($headers as $k => $v){
$result[] = sprintf('%s:%s', $k, $v);
}
return $result;
}
/**
*
* @param string $url
* @param array $params 参数
* @return string
*/
private function buildUrl($url, $params){
if(!empty($params)){
$str = http_build_query($params);
return $url . (strpos($url, '?') === false ? '?' : '&') . $str;
}else{
return $url;
}
}
}

View File

@@ -0,0 +1 @@
{"refresh_token":"25.d3afd58367f9b83c9c1050351a39949c.315360000.1885190493.282335-17393063","expires_in":2592000,"session_key":"9mzdWBXHl3rzZnYwDbIXWIOP13psR1DcWcRYjn9l90\/wnKw0yRpXvLeBgOCseBb0R1Z8CQpSnLPpCvtY1aLNGb9wgQoecQ==","access_token":"24.cea0ed80a1cd81807dbfe827e6de264f.2592000.1572422493.282335-17393063","scope":"public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_antispam_spam brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_nlp_ecnet brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_\u53f0\u6e7e\u901a\u884c\u8bc1 vis-ocr_\u6e2f\u6fb3\u901a\u884c\u8bc1 vis-ocr_\u673a\u52a8\u8f66\u68c0\u9a8c\u5408\u683c\u8bc1\u8bc6\u522b vis-ocr_\u8f66\u8f86vin\u7801\u8bc6\u522b solution_face vis-ocr_\u5b9a\u989d\u53d1\u7968\u8bc6\u522b vis-ocr_\u4fdd\u5355\u8bc6\u522b brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_certificate brain_ocr_insurance_doc wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope","session_secret":"30a863980c0cab64b861f52619711d5d","time":1569830494,"is_cloud_user":false}

View File

@@ -0,0 +1 @@
{"refresh_token":"25.8a38b4f72b23bfd9873904847c09b490.315360000.1900484860.282335-17614601","expires_in":2592000,"session_key":"9mzdCuD\/nrbL3I0WLtbqw3oaxKRdlkjNID355V4Pavpe\/8ILowiVfMTHMqLnRQeC8ENKjnaFUDKbaE8QFmLYBWd3xFv+1w==","access_token":"24.1d3dd93c6453ea6f71009fdf8421170e.2592000.1587716860.282335-17614601","scope":"vis-ocr_\u884c\u7a0b\u5355\u8bc6\u522b brain_ocr_air_ticket public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_\u53f0\u6e7e\u901a\u884c\u8bc1 vis-ocr_\u6e2f\u6fb3\u901a\u884c\u8bc1 vis-ocr_\u673a\u52a8\u8f66\u68c0\u9a8c\u5408\u683c\u8bc1\u8bc6\u522b vis-ocr_\u8f66\u8f86vin\u7801\u8bc6\u522b vis-ocr_\u5b9a\u989d\u53d1\u7968\u8bc6\u522b vis-ocr_\u4fdd\u5355\u8bc6\u522b brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_certificate brain_ocr_insurance_doc wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi qatest_scope1 fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406","session_secret":"4df7ce78d05af9d18d308e000fdf7c03","time":1585124860,"is_cloud_user":false}

View File

@@ -0,0 +1 @@
5caddaaf-3451-49d3-b98a-154bd0a9f851

View File

@@ -0,0 +1,43 @@
<?php
/**
* AOP SDK 入口文件
* 请不要修改这个文件,除非你知道怎样修改以及怎样恢复
* @author wuxiao
*/
/**
* 定义常量开始
* 在include("AopSdk.php")之前定义这些常量,不要直接修改本文件,以利于升级覆盖
*/
/**
* SDK工作目录
* 存放日志AOP缓存数据
*/
if (!defined("AOP_SDK_WORK_DIR"))
{
define("AOP_SDK_WORK_DIR", \Env::get('AOP_SDK_WORK_DIR',realpath(dirname(__FILE__).'/../../runtime/')));
}
/**
* 是否处于开发模式
* 在你自己电脑上开发程序的时候千万不要设为false以免缓存造成你的代码修改了不生效
* 部署到生产环境正式运营后如果性能压力大可以把此常量设定为false能提高运行速度对应的代价就是你下次升级程序时要清一下缓存
*/
if (!defined("AOP_SDK_DEV_MODE"))
{
define("AOP_SDK_DEV_MODE", true);
}
/**
* 定义常量结束
*/
/**
* 找到lotusphp入口文件并初始化lotusphp
* lotusphp是一个第三方php框架其主页在lotusphp.googlecode.com
*/
$lotusHome = dirname(__FILE__) . DIRECTORY_SEPARATOR . "lotusphp_runtime" . DIRECTORY_SEPARATOR;
include($lotusHome . "Lotus.php");
$lotus = new Lotus;
$lotus->option["autoload_dir"] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'aop';
$lotus->devMode = AOP_SDK_DEV_MODE;
$lotus->defaultStoreDir = AOP_SDK_WORK_DIR;
$lotus->init();

View File

@@ -0,0 +1 @@
e652074f-0964-4bc1-a7c8-529c703664c5

View File

@@ -0,0 +1,231 @@
<?php
/**
* 多媒体文件客户端
* @author yikai.hu
* @version $Id: AlipayMobilePublicMultiMediaClient.php, v 0.1 Aug 15, 2014 10:19:01 AM yikai.hu Exp $
*/
//namespace alipay\api ;
include("AlipayMobilePublicMultiMediaExecute.php");
class AlipayMobilePublicMultiMediaClient{
private $DEFAULT_CHARSET = 'UTF-8';
private $METHOD_POST = "POST";
private $METHOD_GET = "GET";
private $SIGN = 'sign'; //get name
private $timeout = 10 ;// 超时时间
private $serverUrl;
private $appId;
private $privateKey;
private $prodCode;
private $format = 'json'; //todo
private $sign_type = 'RSA'; //todo
private $charset;
private $apiVersion = "1.0";
private $apiMethodName = "alipay.mobile.public.multimedia.download";
private $media_id = "L21pZnMvVDFQV3hYWGJKWFhYYUNucHJYP3Q9YW13ZiZ4c2lnPTU0MzRhYjg1ZTZjNWJmZTMxZGJiNjIzNDdjMzFkNzkw575";
//此处写死的,实际开发中,请传入
private $connectTimeout = 3000;
private $readTimeout = 15000;
function __construct($serverUrl = '', $appId = '', $partner_private_key = '', $format = '', $charset = 'GBK'){
$this -> serverUrl = $serverUrl;
$this -> appId = $appId;
$this -> privateKey = $partner_private_key;
$this -> format = $format;
$this -> charset = $charset;
}
/**
* getContents 获取网址内容
* @param $request
* @return text | bin
*/
public function getContents(){
//自己的服务器如果没有 curl可用fsockopen() 等
//1:
//2 私钥格式
$datas = array(
"app_id" => $this -> appId,
"method" => $this -> METHOD_POST,
"sign_type" => $this -> sign_type,
"version" => $this -> apiVersion,
"timestamp" => date('Y-m-d H:i:s') ,//yyyy-MM-dd HH:mm:ss
"biz_content" => '{"mediaId":"'. $this -> media_id .'"}',
"charset" => $this -> charset
);
//要提交的数据
$data_sign = $this -> buildGetUrl( $datas );
$post_data = $data_sign;
//初始化 curl
$ch = curl_init();
//设置目标服务器
curl_setopt($ch, CURLOPT_URL, $this -> serverUrl );
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, $this-> timeout);
if( $this-> METHOD_POST == 'POST'){
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $output;
//分离头部
//list($header, $body) = explode("\r\n\r\n", $output, 2);
$datas = explode("\r\n\r\n", $output, 2);
$header = $datas[0];
if( $httpCode == '200'){
$body = $datas[1];
}else{
$body = '';
}
return $this -> execute( $header, $body, $httpCode );
}
/**
*
* @param $request
* @return text | bin
*/
public function execute( $header = '', $body = '', $httpCode = '' ){
$exe = new AlipayMobilePublicMultiMediaExecute( $header, $body, $httpCode );
return $exe;
}
public function buildGetUrl( $query = array() ){
if( ! is_array( $query ) ){
//exit;
}
//排序参数,
$data = $this -> buildQuery( $query );
// 私钥密码
$passphrase = '';
$key_width = 64;
//私钥
$privateKey = $this -> privateKey;
$p_key = array();
//如果私钥是 1行
if( ! stripos( $privateKey, "\n" ) ){
$i = 0;
while( $key_str = substr( $privateKey , $i * $key_width , $key_width) ){
$p_key[] = $key_str;
$i ++ ;
}
}else{
//echo '一行?';
}
$privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . implode("\n", $p_key) ;
$privateKey = $privateKey ."\n-----END RSA PRIVATE KEY-----";
// echo "\n\n私钥:\n";
// echo( $privateKey );
// echo "\n\n\n";
//私钥
$private_id = openssl_pkey_get_private( $privateKey , $passphrase);
// 签名
$signature = '';
if("RSA2"==$this->sign_type){
openssl_sign($data, $signature, $private_id, OPENSSL_ALGO_SHA256 );
}else{
openssl_sign($data, $signature, $private_id, OPENSSL_ALGO_SHA1 );
}
openssl_free_key( $private_id );
//加密后的内容通常含有特殊字符,需要编码转换下
$signature = base64_encode($signature);
$signature = urlencode( $signature );
//$signature = 'XjUN6YM1Mc9HXebKMv7GTLy7gmyhktyOgKk2/Jf+cz4DtP6udkzTdpkjW2j/Z4ZSD7xD6CNYI1Spz4yS93HPT0a5X9LgFWYY8SaADqe+ArXg+FBSiTwUz49SE//Xd9+LEiIRsSFkbpkuiGoO6mqJmB7vXjlD5lx6qCM3nb41wb8=';
$out = $data .'&'. $this -> SIGN .'='. $signature;
// echo "\n\n 加密后:\n";
// echo( $out );
// echo "\n\n\n";
return $out ;
}
/*
* 查询参数排序 a-z
* */
public function buildQuery( $query ){
if ( !$query ) {
return null;
}
//将要 参数 排序
ksort( $query );
//重新组装参数
$params = array();
foreach($query as $key => $value){
$params[] = $key .'='. $value ;
}
$data = implode('&', $params);
return $data;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* 多媒体文件客户端
* @author yuanwai.wang
* @version $Id: AlipayMobilePublicMultiMediaExecute.php, v 0.1 Aug 15, 2014 10:19:01 AM yuanwai.wang Exp $
*/
//namespace alipay\api ;
class AlipayMobilePublicMultiMediaExecute{
private $code = 200 ;
private $msg = '';
private $body = '';
private $params = '';
private $fileSuffix = array(
"image/jpeg" => 'jpg', //+
"text/plain" => 'text'
);
/*
* @$header : 头部
* */
function __construct( $header, $body, $httpCode ){
$this -> code = $httpCode;
$this -> msg = '';
$this -> params = $header ;
$this -> body = $body;
}
/**
*
* @return text | bin
*/
public function getCode(){
return $this -> code ;
}
/**
*
* @return text | bin
*/
public function getMsg(){
return $this -> msg ;
}
/**
*
* @return text | bin
*/
public function getType(){
$subject = $this -> params ;
$pattern = '/Content\-Type:([^;]+)/';
preg_match($pattern, $subject, $matches);
if( $matches ){
$type = $matches[1];
}else{
$type = 'application/download';
}
return str_replace( ' ', '', $type );
}
/**
*
* @return text | bin
*/
public function getContentLength(){
$subject = $this -> params ;
$pattern = '/Content-Length:\s*([^\n]+)/';
preg_match($pattern, $subject, $matches);
return (int)( isset($matches[1] ) ? $matches[1] : '' );
}
public function getFileSuffix( $fileType ){
$type = isset( $this -> fileSuffix[ $fileType ] ) ? $this -> fileSuffix[ $fileType ] : 'text/plain' ;
if( !$type ){
$type = 'json';
}
return $type;
}
/**
*
* @return text | bin
*/
public function getBody(){
//header('Content-type: image/jpeg');
return $this -> body ;
}
/**
* 获取参数
* @return text | bin
*/
public function getParams(){
return $this -> params ;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,71 @@
<?php
/**
* 加密工具类
*
* User: jiehua
* Date: 16/3/30
* Time: 下午3:25
*/
/**
* 加密方法
* @param string $str
* @return string
*/
function encrypt($str,$screct_key){
//AES, 128 模式加密数据 CBC
$screct_key = base64_decode($screct_key);
$str = trim($str);
$str = addPKCS7Padding($str);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1);
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC);
return base64_encode($encrypt_str);
}
/**
* 解密方法
* @param string $str
* @return string
*/
function decrypt($str,$screct_key){
//AES, 128 模式加密数据 CBC
$str = base64_decode($str);
$screct_key = base64_decode($screct_key);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1);
$encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC);
$encrypt_str = trim($encrypt_str);
$encrypt_str = stripPKSC7Padding($encrypt_str);
return $encrypt_str;
}
/**
* 填充算法
* @param string $source
* @return string
*/
function addPKCS7Padding($source){
$source = trim($source);
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($source) % $block);
if ($pad <= $block) {
$char = chr($pad);
$source .= str_repeat($char, $pad);
}
return $source;
}
/**
* 移去填充算法
* @param string $source
* @return string
*/
function stripPKSC7Padding($source){
$source = trim($source);
$char = substr($source, -1);
$num = ord($char);
if($num==62)return $source;
$source = substr($source,0,-$num);
return $source;
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* TODO 补充说明
*
* User: jiehua
* Date: 16/3/30
* Time: 下午8:55
*/
class EncryptParseItem {
public $startIndex;
public $endIndex;
public $encryptContent;
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* TODO 补充说明
*
* User: jiehua
* Date: 16/3/30
* Time: 下午8:51
*/
class EncryptResponseData {
public $realContent;
public $returnContent;
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: jiehua
* Date: 15/5/2
* Time: 下午6:21
*/
class SignData {
public $signSourceData=null;
public $sign=null;
}

View File

@@ -0,0 +1 @@
08fbd575-ca93-4b0d-941c-83a722a337c7

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.account.exrate.advice.accept request
*
* @author auto create
* @since 1.0, 2016-05-23 14:55:42
*/
class AlipayAccountExrateAdviceAcceptRequest
{
/**
* 标准的兑换交易受理接口
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.account.exrate.advice.accept";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.account.exrate.allclientrate.query request
*
* @author auto create
* @since 1.0, 2016-05-23 14:55:48
*/
class AlipayAccountExrateAllclientrateQueryRequest
{
/**
* 查询客户的所有币种对最新有效汇率
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.account.exrate.allclientrate.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.account.exrate.ratequery request
*
* @author auto create
* @since 1.0, 2017-03-27 18:11:27
*/
class AlipayAccountExrateRatequeryRequest
{
/**
* 对于部分签约境内当面付的商家,为了能够在境外进行推广,因此需要汇率进行币种之间的转换,本接口提供此业务场景下的汇率查询服务
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.account.exrate.ratequery";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,171 @@
<?php
/**
* ALIPAY API: alipay.acquire.cancel request
*
* @author auto create
* @since 1.0, 2014-06-12 17:17:06
*/
class AlipayAcquireCancelRequest
{
/**
* 操作员ID。
**/
private $operatorId;
/**
* 操作员的类型:
0支付宝操作员
1商户的操作员
如果传入其它值或者为空则默认设置为1
**/
private $operatorType;
/**
* 支付宝合作商户网站唯一订单号。
**/
private $outTradeNo;
/**
* 该交易在支付宝系统中的交易流水号。
最短16位最长64位。
如果同时传了out_trade_no和trade_no则以trade_no为准。
**/
private $tradeNo;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->apiParas["operator_id"] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOperatorType($operatorType)
{
$this->operatorType = $operatorType;
$this->apiParas["operator_type"] = $operatorType;
}
public function getOperatorType()
{
return $this->operatorType;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->apiParas["trade_no"] = $tradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function getApiMethodName()
{
return "alipay.acquire.cancel";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* ALIPAY API: alipay.acquire.close request
*
* @author auto create
* @since 1.0, 2014-06-12 17:17:06
*/
class AlipayAcquireCloseRequest
{
/**
* 卖家的操作员ID
**/
private $operatorId;
/**
* 支付宝合作商户网站唯一订单号
**/
private $outTradeNo;
/**
* 该交易在支付宝系统中的交易流水号。
最短16位最长64位。
如果同时传了out_trade_no和trade_no则以trade_no为准
**/
private $tradeNo;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->apiParas["operator_id"] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->apiParas["trade_no"] = $tradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function getApiMethodName()
{
return "alipay.acquire.close";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,550 @@
<?php
/**
* ALIPAY API: alipay.acquire.createandpay request
*
* @author auto create
* @since 1.0, 2016-11-22 19:31:24
*/
class AlipayAcquireCreateandpayRequest
{
/**
* 证书签名
**/
private $alipayCaRequest;
/**
* 对一笔交易的具体描述信息。如果是多种商品请将商品描述字符串累加传给body。
**/
private $body;
/**
* 买家支付宝账号可以为email或者手机号。
**/
private $buyerEmail;
/**
* 买家支付宝账号对应的支付宝唯一用户号。
以2088开头的纯16位数字。
**/
private $buyerId;
/**
* 描述多渠道收单的渠道明细信息json格式具体请参见“4.5 渠道明细说明”。
**/
private $channelParameters;
/**
* 订单金额币种。
目前只支持传入156人民币
如果为空则默认设置为156。
**/
private $currency;
/**
* 动态ID。
**/
private $dynamicId;
/**
* 动态ID类型
&#1048698;
soundwave声波
&#1048698;
qrcode二维码
&#1048698;
barcode条码
&#1048698;
wave_code声波等同soundwave
&#1048698;
qr_code二维码等同qrcode
&#1048698;
bar_code条码等同barcode
建议取值wave_code、qr_code、bar_code。
**/
private $dynamicIdType;
/**
* 用于商户的特定业务信息的传递,只有商户与支付宝约定了传递此参数且约定了参数含义,此参数才有效。
比如可传递声波支付场景下的门店ID等信息以json格式传输具体请参见“4.7 业务扩展参数说明”。
**/
private $extendParams;
/**
* xml或json
**/
private $formatType;
/**
* 描述商品明细信息json格式具体请参见“4.3 商品明细说明”。
**/
private $goodsDetail;
/**
* 设置未付款交易的超时时间,一旦超时,该笔交易就会自动被关闭。
取值范围1m15d。
m-分钟h-小时d-天1c-当天无论交易何时创建都在0点关闭
该参数数值不接受小数点如1.5h可转换为90m。
该功能需要联系支付宝配置关闭时间。
**/
private $itBPay;
/**
* 描述预付卡相关的明细信息json格式具体请参见“4.8 预付卡明细参数说明”。
**/
private $mcardParameters;
/**
* 卖家的操作员ID。
**/
private $operatorId;
/**
* 操作员的类型:
&#1048698;
0支付宝操作员
&#1048698;
1商户的操作员
如果传入其它值或者为空则默认设置为1。
**/
private $operatorType;
/**
* 支付宝合作商户网站唯一订单号。
**/
private $outTradeNo;
/**
* 订单中商品的单价。
如果请求时传入本参数则必须满足total_fee=price×quantity的条件。
**/
private $price;
/**
* 订单中商品的数量。
如果请求时传入本参数则必须满足total_fee=price×quantity的条件。
**/
private $quantity;
/**
* 业务关联ID集合用于放置商户的订单号、支付流水号等信息json格式具体请参见“4.6 业务关联ID集合说明”。
**/
private $refIds;
/**
* 描述分账明细信息json格式具体请参见“4.4 分账明细说明”。
**/
private $royaltyParameters;
/**
* 卖家的分账类型目前只支持传入ROYALTY普通分账类型
**/
private $royaltyType;
/**
* 卖家支付宝账号可以为email或者手机号。
如果seller_id不为空则以seller_id的值作为卖家账号忽略本参数。
**/
private $sellerEmail;
/**
* 卖家支付宝账号对应的支付宝唯一用户号。
以2088开头的纯16位数字。
如果和seller_email同时为空则本参数默认填充partner的值。
**/
private $sellerId;
/**
* 收银台页面上,商品展示的超链接。
**/
private $showUrl;
/**
* 商品的标题/交易标题/订单标题/订单关键字等。
该参数最长为128个汉字。
**/
private $subject;
/**
* 该笔订单的资金总额,取值范围[0.01,100000000]精确到小数点后2位。
**/
private $totalFee;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setAlipayCaRequest($alipayCaRequest)
{
$this->alipayCaRequest = $alipayCaRequest;
$this->apiParas["alipay_ca_request"] = $alipayCaRequest;
}
public function getAlipayCaRequest()
{
return $this->alipayCaRequest;
}
public function setBody($body)
{
$this->body = $body;
$this->apiParas["body"] = $body;
}
public function getBody()
{
return $this->body;
}
public function setBuyerEmail($buyerEmail)
{
$this->buyerEmail = $buyerEmail;
$this->apiParas["buyer_email"] = $buyerEmail;
}
public function getBuyerEmail()
{
return $this->buyerEmail;
}
public function setBuyerId($buyerId)
{
$this->buyerId = $buyerId;
$this->apiParas["buyer_id"] = $buyerId;
}
public function getBuyerId()
{
return $this->buyerId;
}
public function setChannelParameters($channelParameters)
{
$this->channelParameters = $channelParameters;
$this->apiParas["channel_parameters"] = $channelParameters;
}
public function getChannelParameters()
{
return $this->channelParameters;
}
public function setCurrency($currency)
{
$this->currency = $currency;
$this->apiParas["currency"] = $currency;
}
public function getCurrency()
{
return $this->currency;
}
public function setDynamicId($dynamicId)
{
$this->dynamicId = $dynamicId;
$this->apiParas["dynamic_id"] = $dynamicId;
}
public function getDynamicId()
{
return $this->dynamicId;
}
public function setDynamicIdType($dynamicIdType)
{
$this->dynamicIdType = $dynamicIdType;
$this->apiParas["dynamic_id_type"] = $dynamicIdType;
}
public function getDynamicIdType()
{
return $this->dynamicIdType;
}
public function setExtendParams($extendParams)
{
$this->extendParams = $extendParams;
$this->apiParas["extend_params"] = $extendParams;
}
public function getExtendParams()
{
return $this->extendParams;
}
public function setFormatType($formatType)
{
$this->formatType = $formatType;
$this->apiParas["format_type"] = $formatType;
}
public function getFormatType()
{
return $this->formatType;
}
public function setGoodsDetail($goodsDetail)
{
$this->goodsDetail = $goodsDetail;
$this->apiParas["goods_detail"] = $goodsDetail;
}
public function getGoodsDetail()
{
return $this->goodsDetail;
}
public function setItBPay($itBPay)
{
$this->itBPay = $itBPay;
$this->apiParas["it_b_pay"] = $itBPay;
}
public function getItBPay()
{
return $this->itBPay;
}
public function setMcardParameters($mcardParameters)
{
$this->mcardParameters = $mcardParameters;
$this->apiParas["mcard_parameters"] = $mcardParameters;
}
public function getMcardParameters()
{
return $this->mcardParameters;
}
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->apiParas["operator_id"] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOperatorType($operatorType)
{
$this->operatorType = $operatorType;
$this->apiParas["operator_type"] = $operatorType;
}
public function getOperatorType()
{
return $this->operatorType;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setPrice($price)
{
$this->price = $price;
$this->apiParas["price"] = $price;
}
public function getPrice()
{
return $this->price;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
$this->apiParas["quantity"] = $quantity;
}
public function getQuantity()
{
return $this->quantity;
}
public function setRefIds($refIds)
{
$this->refIds = $refIds;
$this->apiParas["ref_ids"] = $refIds;
}
public function getRefIds()
{
return $this->refIds;
}
public function setRoyaltyParameters($royaltyParameters)
{
$this->royaltyParameters = $royaltyParameters;
$this->apiParas["royalty_parameters"] = $royaltyParameters;
}
public function getRoyaltyParameters()
{
return $this->royaltyParameters;
}
public function setRoyaltyType($royaltyType)
{
$this->royaltyType = $royaltyType;
$this->apiParas["royalty_type"] = $royaltyType;
}
public function getRoyaltyType()
{
return $this->royaltyType;
}
public function setSellerEmail($sellerEmail)
{
$this->sellerEmail = $sellerEmail;
$this->apiParas["seller_email"] = $sellerEmail;
}
public function getSellerEmail()
{
return $this->sellerEmail;
}
public function setSellerId($sellerId)
{
$this->sellerId = $sellerId;
$this->apiParas["seller_id"] = $sellerId;
}
public function getSellerId()
{
return $this->sellerId;
}
public function setShowUrl($showUrl)
{
$this->showUrl = $showUrl;
$this->apiParas["show_url"] = $showUrl;
}
public function getShowUrl()
{
return $this->showUrl;
}
public function setSubject($subject)
{
$this->subject = $subject;
$this->apiParas["subject"] = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setTotalFee($totalFee)
{
$this->totalFee = $totalFee;
$this->apiParas["total_fee"] = $totalFee;
}
public function getTotalFee()
{
return $this->totalFee;
}
public function getApiMethodName()
{
return "alipay.acquire.createandpay";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,402 @@
<?php
/**
* ALIPAY API: alipay.acquire.precreate request
*
* @author auto create
* @since 1.0, 2014-05-28 11:57:10
*/
class AlipayAcquirePrecreateRequest
{
/**
* 对一笔交易的具体描述信息。如果是多种商品请将商品描述字符串累加传给body
**/
private $body;
/**
* 描述多渠道收单的渠道明细信息json格式
**/
private $channelParameters;
/**
* 订单金额币种。目前只支持传入156人民币
如果为空则默认设置为156
**/
private $currency;
/**
* 公用业务扩展信息。用于商户的特定业务信息的传递,只有商户与支付宝约定了传递此参数且约定了参数含义,此参数才有效。
比如可传递二维码支付场景下的门店ID等信息以json格式传输。
**/
private $extendParams;
/**
* 描述商品明细信息json格式。
**/
private $goodsDetail;
/**
* 订单支付超时时间。设置未付款交易的超时时间,一旦超时,该笔交易就会自动被关闭。
取值范围1m15d。
m-分钟h-小时d-天1c-当天无论交易何时创建都在0点关闭
该参数数值不接受小数点如1.5h可转换为90m。
该功能需要联系支付宝配置关闭时间。
**/
private $itBPay;
/**
* 操作员的类型:
0支付宝操作员
1商户的操作员
如果传入其它值或者为空则默认设置为1
**/
private $operatorCode;
/**
* 卖家的操作员ID
**/
private $operatorId;
/**
* 支付宝合作商户网站唯一订单号
**/
private $outTradeNo;
/**
* 订单中商品的单价。
如果请求时传入本参数则必须满足total_fee=price×quantity的条件
**/
private $price;
/**
* 订单中商品的数量。
如果请求时传入本参数则必须满足total_fee=price×quantity的条件
**/
private $quantity;
/**
* 分账信息。
描述分账明细信息json格式
**/
private $royaltyParameters;
/**
* 分账类型。卖家的分账类型目前只支持传入ROYALTY普通分账类型
**/
private $royaltyType;
/**
* 卖家支付宝账号可以为email或者手机号。如果seller_id不为空则以seller_id的值作为卖家账号忽略本参数
**/
private $sellerEmail;
/**
* 卖家支付宝账号对应的支付宝唯一用户号以2088开头的纯16位数字。如果和seller_email同时为空则本参数默认填充partner的值
**/
private $sellerId;
/**
* 收银台页面上,商品展示的超链接
**/
private $showUrl;
/**
* 商品购买
**/
private $subject;
/**
* 订单金额。该笔订单的资金总额,取值范围[0.01,100000000]精确到小数点后2位。
**/
private $totalFee;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBody($body)
{
$this->body = $body;
$this->apiParas["body"] = $body;
}
public function getBody()
{
return $this->body;
}
public function setChannelParameters($channelParameters)
{
$this->channelParameters = $channelParameters;
$this->apiParas["channel_parameters"] = $channelParameters;
}
public function getChannelParameters()
{
return $this->channelParameters;
}
public function setCurrency($currency)
{
$this->currency = $currency;
$this->apiParas["currency"] = $currency;
}
public function getCurrency()
{
return $this->currency;
}
public function setExtendParams($extendParams)
{
$this->extendParams = $extendParams;
$this->apiParas["extend_params"] = $extendParams;
}
public function getExtendParams()
{
return $this->extendParams;
}
public function setGoodsDetail($goodsDetail)
{
$this->goodsDetail = $goodsDetail;
$this->apiParas["goods_detail"] = $goodsDetail;
}
public function getGoodsDetail()
{
return $this->goodsDetail;
}
public function setItBPay($itBPay)
{
$this->itBPay = $itBPay;
$this->apiParas["it_b_pay"] = $itBPay;
}
public function getItBPay()
{
return $this->itBPay;
}
public function setOperatorCode($operatorCode)
{
$this->operatorCode = $operatorCode;
$this->apiParas["operator_code"] = $operatorCode;
}
public function getOperatorCode()
{
return $this->operatorCode;
}
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->apiParas["operator_id"] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setPrice($price)
{
$this->price = $price;
$this->apiParas["price"] = $price;
}
public function getPrice()
{
return $this->price;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
$this->apiParas["quantity"] = $quantity;
}
public function getQuantity()
{
return $this->quantity;
}
public function setRoyaltyParameters($royaltyParameters)
{
$this->royaltyParameters = $royaltyParameters;
$this->apiParas["royalty_parameters"] = $royaltyParameters;
}
public function getRoyaltyParameters()
{
return $this->royaltyParameters;
}
public function setRoyaltyType($royaltyType)
{
$this->royaltyType = $royaltyType;
$this->apiParas["royalty_type"] = $royaltyType;
}
public function getRoyaltyType()
{
return $this->royaltyType;
}
public function setSellerEmail($sellerEmail)
{
$this->sellerEmail = $sellerEmail;
$this->apiParas["seller_email"] = $sellerEmail;
}
public function getSellerEmail()
{
return $this->sellerEmail;
}
public function setSellerId($sellerId)
{
$this->sellerId = $sellerId;
$this->apiParas["seller_id"] = $sellerId;
}
public function getSellerId()
{
return $this->sellerId;
}
public function setShowUrl($showUrl)
{
$this->showUrl = $showUrl;
$this->apiParas["show_url"] = $showUrl;
}
public function getShowUrl()
{
return $this->showUrl;
}
public function setSubject($subject)
{
$this->subject = $subject;
$this->apiParas["subject"] = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setTotalFee($totalFee)
{
$this->totalFee = $totalFee;
$this->apiParas["total_fee"] = $totalFee;
}
public function getTotalFee()
{
return $this->totalFee;
}
public function getApiMethodName()
{
return "alipay.acquire.precreate";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* ALIPAY API: alipay.acquire.query request
*
* @author auto create
* @since 1.0, 2014-05-28 11:58:01
*/
class AlipayAcquireQueryRequest
{
/**
* 支付宝合作商户网站唯一订单号
**/
private $outTradeNo;
/**
* 该交易在支付宝系统中的交易流水号。
最短16位最长64位。
如果同时传了out_trade_no和trade_no则以trade_no为准。
**/
private $tradeNo;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->apiParas["trade_no"] = $tradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function getApiMethodName()
{
return "alipay.acquire.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,236 @@
<?php
/**
* ALIPAY API: alipay.acquire.refund request
*
* @author auto create
* @since 1.0, 2014-06-12 17:17:03
*/
class AlipayAcquireRefundRequest
{
/**
* 卖家的操作员ID。
**/
private $operatorId;
/**
* 操作员的类型:
0支付宝操作员
1商户的操作员
如果传入其它值或者为空则默认设置为1。
**/
private $operatorType;
/**
* 商户退款请求单号,用以标识本次交易的退款请求。
如果不传入本参数则以out_trade_no填充本参数的值。同时认为本次请求为全额退款要求退款金额和交易支付金额一致。
**/
private $outRequestNo;
/**
* 商户网站唯一订单号
**/
private $outTradeNo;
/**
* 业务关联ID集合用于放置商户的退款单号、退款流水号等信息json格式
**/
private $refIds;
/**
* 退款金额;退款金额不能大于订单金额,全额退款必须与订单金额一致。
**/
private $refundAmount;
/**
* 退款原因说明。
**/
private $refundReason;
/**
* 该交易在支付宝系统中的交易流水号。
最短16位最长64位。
如果同时传了out_trade_no和trade_no则以trade_no为准
**/
private $tradeNo;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setOperatorId($operatorId)
{
$this->operatorId = $operatorId;
$this->apiParas["operator_id"] = $operatorId;
}
public function getOperatorId()
{
return $this->operatorId;
}
public function setOperatorType($operatorType)
{
$this->operatorType = $operatorType;
$this->apiParas["operator_type"] = $operatorType;
}
public function getOperatorType()
{
return $this->operatorType;
}
public function setOutRequestNo($outRequestNo)
{
$this->outRequestNo = $outRequestNo;
$this->apiParas["out_request_no"] = $outRequestNo;
}
public function getOutRequestNo()
{
return $this->outRequestNo;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
$this->apiParas["out_trade_no"] = $outTradeNo;
}
public function getOutTradeNo()
{
return $this->outTradeNo;
}
public function setRefIds($refIds)
{
$this->refIds = $refIds;
$this->apiParas["ref_ids"] = $refIds;
}
public function getRefIds()
{
return $this->refIds;
}
public function setRefundAmount($refundAmount)
{
$this->refundAmount = $refundAmount;
$this->apiParas["refund_amount"] = $refundAmount;
}
public function getRefundAmount()
{
return $this->refundAmount;
}
public function setRefundReason($refundReason)
{
$this->refundReason = $refundReason;
$this->apiParas["refund_reason"] = $refundReason;
}
public function getRefundReason()
{
return $this->refundReason;
}
public function setTradeNo($tradeNo)
{
$this->tradeNo = $tradeNo;
$this->apiParas["trade_no"] = $tradeNo;
}
public function getTradeNo()
{
return $this->tradeNo;
}
public function getApiMethodName()
{
return "alipay.acquire.refund";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.app.token.get request
*
* @author auto create
* @since 1.0, 2016-07-29 19:56:12
*/
class AlipayAppTokenGetRequest
{
/**
* 应用安全码
**/
private $secret;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setSecret($secret)
{
$this->secret = $secret;
$this->apiParas["secret"] = $secret;
}
public function getSecret()
{
return $this->secret;
}
public function getApiMethodName()
{
return "alipay.app.token.get";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* ALIPAY API: alipay.asset.account.bind request
*
* @author auto create
* @since 1.0, 2017-04-07 18:06:34
*/
class AlipayAssetAccountBindRequest
{
/**
* 绑定场景,目前仅支持如下:
wechat微信公众平台
transport物流转运平台
appOneBind一对一app绑定
注意:必须是这些值,区分大小写。
**/
private $bindScene;
/**
* 使用该app提供用户信息的商户可以和app相同。
**/
private $providerId;
/**
* 用户在商户网站的会员标识。商户需确保其唯一性,不可变更。
**/
private $providerUserId;
/**
* 用户在商户网站的会员名(登录号或昵称)。
**/
private $providerUserName;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBindScene($bindScene)
{
$this->bindScene = $bindScene;
$this->apiParas["bind_scene"] = $bindScene;
}
public function getBindScene()
{
return $this->bindScene;
}
public function setProviderId($providerId)
{
$this->providerId = $providerId;
$this->apiParas["provider_id"] = $providerId;
}
public function getProviderId()
{
return $this->providerId;
}
public function setProviderUserId($providerUserId)
{
$this->providerUserId = $providerUserId;
$this->apiParas["provider_user_id"] = $providerUserId;
}
public function getProviderUserId()
{
return $this->providerUserId;
}
public function setProviderUserName($providerUserName)
{
$this->providerUserName = $providerUserName;
$this->apiParas["provider_user_name"] = $providerUserName;
}
public function getProviderUserName()
{
return $this->providerUserName;
}
public function getApiMethodName()
{
return "alipay.asset.account.bind";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* ALIPAY API: alipay.asset.account.get request
*
* @author auto create
* @since 1.0, 2017-04-07 18:05:33
*/
class AlipayAssetAccountGetRequest
{
/**
* 使用该app提供用户信息的商户可以和app相同。
**/
private $providerId;
/**
* 用户在商户网站的会员标识。商户需确保其唯一性,不可变更。
注意根据provider_user_id查询时该值不可空。
**/
private $providerUserId;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setProviderId($providerId)
{
$this->providerId = $providerId;
$this->apiParas["provider_id"] = $providerId;
}
public function getProviderId()
{
return $this->providerId;
}
public function setProviderUserId($providerUserId)
{
$this->providerUserId = $providerUserId;
$this->apiParas["provider_user_id"] = $providerUserId;
}
public function getProviderUserId()
{
return $this->providerUserId;
}
public function getApiMethodName()
{
return "alipay.asset.account.get";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* ALIPAY API: alipay.asset.account.unbind request
*
* @author auto create
* @since 1.0, 2017-04-07 18:06:06
*/
class AlipayAssetAccountUnbindRequest
{
/**
* 业务参数 使用该app提供用户信息的商户在支付宝签约时的支付宝账户userID可以和app相同。
**/
private $providerId;
/**
* 用户在商户网站的会员标识。商户需确保其唯一性,不可变更。
**/
private $providerUserId;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setProviderId($providerId)
{
$this->providerId = $providerId;
$this->apiParas["provider_id"] = $providerId;
}
public function getProviderId()
{
return $this->providerId;
}
public function setProviderUserId($providerUserId)
{
$this->providerUserId = $providerUserId;
$this->apiParas["provider_user_id"] = $providerUserId;
}
public function getProviderUserId()
{
return $this->providerUserId;
}
public function getApiMethodName()
{
return "alipay.asset.account.unbind";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* ALIPAY API: alipay.asset.point.balance.query request
*
* @author auto create
* @since 1.0, 2017-04-07 18:43:10
*/
class AlipayAssetPointBalanceQueryRequest
{
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function getApiMethodName()
{
return "alipay.asset.point.balance.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* ALIPAY API: alipay.asset.point.budget.query request
*
* @author auto create
* @since 1.0, 2017-04-07 18:41:34
*/
class AlipayAssetPointBudgetQueryRequest
{
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function getApiMethodName()
{
return "alipay.asset.point.budget.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.asset.point.order.create request
*
* @author auto create
* @since 1.0, 2017-04-07 18:38:50
*/
class AlipayAssetPointOrderCreateRequest
{
/**
* 商户在采购完集分宝后可以通过此接口发放集分宝
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.asset.point.order.create";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.asset.point.order.query request
*
* @author auto create
* @since 1.0, 2017-04-07 18:45:38
*/
class AlipayAssetPointOrderQueryRequest
{
/**
* 商户在调用集分宝发放接口后可以通过此接口查询发放情况
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.asset.point.order.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* ALIPAY API: alipay.boss.cs.channel.query request
*
* @author auto create
* @since 1.0, 2016-02-23 20:04:44
*/
class AlipayBossCsChannelQueryRequest
{
/**
* 云客服热线数据查询,云客服会有很多外部客服,他们需要查询落地在站内的自己公司的服务数据。
**/
private $bizContent;
private $apiParas = array();
private $terminalType;
private $terminalInfo;
private $prodCode;
private $apiVersion="1.0";
private $notifyUrl;
private $returnUrl;
private $needEncrypt=false;
public function setBizContent($bizContent)
{
$this->bizContent = $bizContent;
$this->apiParas["biz_content"] = $bizContent;
}
public function getBizContent()
{
return $this->bizContent;
}
public function getApiMethodName()
{
return "alipay.boss.cs.channel.query";
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl=$notifyUrl;
}
public function getNotifyUrl()
{
return $this->notifyUrl;
}
public function setReturnUrl($returnUrl)
{
$this->returnUrl=$returnUrl;
}
public function getReturnUrl()
{
return $this->returnUrl;
}
public function getApiParas()
{
return $this->apiParas;
}
public function getTerminalType()
{
return $this->terminalType;
}
public function setTerminalType($terminalType)
{
$this->terminalType = $terminalType;
}
public function getTerminalInfo()
{
return $this->terminalInfo;
}
public function setTerminalInfo($terminalInfo)
{
$this->terminalInfo = $terminalInfo;
}
public function getProdCode()
{
return $this->prodCode;
}
public function setProdCode($prodCode)
{
$this->prodCode = $prodCode;
}
public function setApiVersion($apiVersion)
{
$this->apiVersion=$apiVersion;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function setNeedEncrypt($needEncrypt)
{
$this->needEncrypt=$needEncrypt;
}
public function getNeedEncrypt()
{
return $this->needEncrypt;
}
}

Some files were not shown because too many files have changed in this diff Show More