- 测试淘宝官方SDK

v6 v6.0.123
李光春 4 years ago
parent 95b370a8e7
commit 25ce72a985

@ -1,4 +1,7 @@
## v6.0.122 / 2020-11-28
## v6.0.123 / 2020-11-19
- 测试淘宝官方SDK
## v6.0.122 / 2020-11-18
- 增加订单侠开放平台接口
## v6.0.121 / 2020-11-12

@ -40,7 +40,7 @@
"qcloud/cos-sdk-v5": "^2.0",
"qiniu/php-sdk": "^7.2",
"upyun/sdk": "^3.4",
"phpoffice/phpspreadsheet": "^1.14"
"phpoffice/phpspreadsheet": "1.12.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2"

@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService;
/**
* 定义当前版本
*/
const VERSION = '6.0.122';
const VERSION = '6.0.123';
if (!function_exists('get_ip_info')) {
/**

@ -0,0 +1,113 @@
<?php
namespace DtApp\ThinkLibrary\service\taobao;
use DtApp\ThinkLibrary\Service;
use TbkScInvitecodeGetRequest;
use TopClient;
/**
* 淘宝服务
* Class TaoBaoService
* @package DtApp\ThinkLibrary\service\taobao
*/
class TaoBaoService extends Service
{
/**
* TOP分配给应用的
* @var string
*/
private $app_key, $app_secret = "";
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 响应内容
* @var
*/
private $output;
/**
* 配置应用的AppKey
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
}
/**
* 应用AppSecret
* @param string $appSecret
* @return $this
*/
public function appSecret(string $appSecret): self
{
$this->app_secret = $appSecret;
return $this;
}
/**
* 请求参数
* @param array $param
* @return $this
*/
public function param(array $param): self
{
$this->param = $param;
return $this;
}
public function scInvitecodeGet($sessionKey): self
{
$c = new TopClient();
$c->appkey = $this->app_key;
$c->secretKey = $this->app_secret;
$req = new TbkScInvitecodeGetRequest();
if (isset($this->param['relation_id'])) {
$req->setRelationId($this->param['relation_id']);
}
if (isset($this->param['relation_app'])) {
$req->setRelationApp($this->param['relation_app']);
}
if (isset($this->param['code_type'])) {
$req->setCodeType($this->param['code_type']);
}
$resp = $c->execute($req, $sessionKey);
return $this;
}
/**
* 返回Array
* @return array|mixed
*/
public function toArray()
{
if (isset($this->output['error_response'])) {
// 错误
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
return json_decode($this->output, true);
}
// 正常
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
}

@ -0,0 +1,78 @@
<?php
class Autoloader{
/**
* 类库自动加载,写死路径,确保不加载其他文件。
* @param string $class 对象类名
* @return void
*/
public static function autoload($class) {
$name = $class;
if(false !== strpos($name,'\\')){
$name = strstr($class, '\\', true);
}
$filename = TOP_AUTOLOADER_PATH."/top/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/top/request/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/top/domain/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/aliyun/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/aliyun/request/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/aliyun/domain/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/dingtalk/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/dingtalk/request/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/dingtalk/domain/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
$filename = TOP_AUTOLOADER_PATH."/QimenCloud/".$name.".php";
if(is_file($filename)) {
include $filename;
return;
}
}
}
spl_autoload_register('Autoloader::autoload');
?>

@ -0,0 +1,12 @@
<?php
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiMediaUploadRequest;
$req->setType("image");
$req->setMedia(array('type'=>'application/octet-stream','filename'=>'image.png', 'content' => file_get_contents('/Users/test/image.png')));
$resp=$c->execute($req, "******","https://oapi.dingtalk.com/media/upload");
var_dump($resp)
?>

@ -0,0 +1,384 @@
<?php
class QimenCloudClient
{
public $appkey;
public $secretKey;
public $targetAppkey = "";
public $gatewayUrl = null;
public $format = "xml";
public $connectTimeout;
public $readTimeout;
/** 是否打开入参check**/
public $checkRequest = true;
protected $signMethod = "md5";
protected $apiVersion = "2.0";
protected $sdkVersion = "top-sdk-php-20151012";
public function getAppkey()
{
return $this->appkey;
}
public function __construct($appkey = "",$secretKey = ""){
$this->appkey = $appkey;
$this->secretKey = $secretKey ;
}
protected function generateSign($params)
{
ksort($params);
$stringToBeSigned = $this->secretKey;
foreach ($params as $k => $v)
{
if(!is_array($v) && "@" != substr($v, 0, 1))
{
$stringToBeSigned .= "$k$v";
}
}
unset($k, $v);
$stringToBeSigned .= $this->secretKey;
return strtoupper(md5($stringToBeSigned));
}
public function curl($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
//https 请求
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($postFields) && 0 < count($postFields))
{
$postBodyString = "";
$postMultipart = false;
foreach ($postFields as $k => $v)
{
if("@" != substr($v, 0, 1))//判断是不是文件上传
{
$postBodyString .= "$k=" . urlencode($v) . "&";
}
else//文件上传用multipart/form-data否则用www-form-urlencoded
{
$postMultipart = true;
if(class_exists('\CURLFile')){
$postFields[$k] = new \CURLFile(substr($v, 1));
}
}
}
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true);
if ($postMultipart)
{
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
else
{
$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
}
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
//https 请求
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//生成分隔符
$delimiter = '-------------' . uniqid();
//先将post的普通数据生成主体字符串
$data = '';
if($postFields != null){
foreach ($postFields as $name => $content) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"';
//multipart/form-data 不需要urlencode参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
$data .= "\r\n\r\n" . $content . "\r\n";
}
unset($name,$content);
}
//将上传的文件生成主体字符串
if($fileFields != null){
foreach ($fileFields as $name => $file) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['name'] . "\" \r\n";
$data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
$data .= $file['content'] . "\r\n";
}
unset($name,$file);
}
//主体结束的分隔符
$data .= "--" . $delimiter . "--";
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER , array(
'Content-Type: multipart/form-data; boundary=' . $delimiter,
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$reponse = curl_exec($ch);
unset($data);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
{
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
date("Y-m-d H:i:s"),
$apiName,
$this->appkey,
$localIp,
PHP_OS,
$this->sdkVersion,
$requestUrl,
$errorCode,
str_replace("\n","",$responseTxt)
);
$logger->log($logData);
}
public function execute($request, $session = null,$bestUrl = null)
{
if($this->gatewayUrl == null) {
throw new Exception("client-check-error:Need Set gatewayUrl.", 40);
}
$result = new ResultSet();
if($this->checkRequest) {
try {
$request->check();
} catch (Exception $e) {
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
}
//组装系统参数
$sysParams["app_key"] = $this->appkey;
$sysParams["v"] = $this->apiVersion;
$sysParams["format"] = $this->format;
$sysParams["sign_method"] = $this->signMethod;
$sysParams["method"] = $request->getApiMethodName();
$sysParams["timestamp"] = date("Y-m-d H:i:s");
$sysParams["target_app_key"] = $this->targetAppkey;
if (null != $session)
{
$sysParams["session"] = $session;
}
$apiParams = array();
//获取业务参数
$apiParams = $request->getApiParas();
//系统参数放入GET请求串
if($bestUrl){
$requestUrl = $bestUrl."?";
$sysParams["partner_id"] = $this->getClusterTag();
}else{
$requestUrl = $this->gatewayUrl."?";
$sysParams["partner_id"] = $this->sdkVersion;
}
//签名
$sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams));
foreach ($sysParams as $sysParamKey => $sysParamValue)
{
// if(strcmp($sysParamKey,"timestamp") != 0)
$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
}
$fileFields = array();
foreach ($apiParams as $key => $value) {
if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
$value['name'] = $key;
$fileFields[$key] = $value;
unset($apiParams[$key]);
}
}
// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
$requestUrl = substr($requestUrl, 0, -1);
//发起HTTP请求
try
{
if(count($fileFields) > 0){
$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
}else{
$resp = $this->curl($requestUrl, $apiParams);
}
}
catch (Exception $e)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
unset($apiParams);
unset($fileFields);
//解析TOP返回结果
$respWellFormed = false;
if ("json" == $this->format)
{
$respObject = json_decode($resp);
if (null !== $respObject)
{
$respWellFormed = true;
foreach ($respObject as $propKey => $propValue)
{
$respObject = $propValue;
}
}
}
else if("xml" == $this->format)
{
$respObject = @simplexml_load_string($resp);
if (false !== $respObject)
{
$respWellFormed = true;
}
}
//返回的HTTP文本不是标准JSON或者XML记下错误日志
if (false === $respWellFormed)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
$result->code = 0;
$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
return $result;
}
//如果TOP返回了错误码记录到业务错误日志中
if (isset($respObject->code))
{
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
$logger->log(array(
date("Y-m-d H:i:s"),
$resp
));
}
return $respObject;
}
public function exec($paramsArray)
{
if (!isset($paramsArray["method"]))
{
trigger_error("No api name passed");
}
$inflector = new LtInflector;
$inflector->conf["separator"] = ".";
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
if (!class_exists($requestClassName))
{
trigger_error("No such api: " . $paramsArray["method"]);
}
$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
$req = new $requestClassName;
foreach($paramsArray as $paraKey => $paraValue)
{
$inflector->conf["separator"] = "_";
$setterMethodName = $inflector->camelize($paraKey);
$inflector->conf["separator"] = ".";
$setterMethodName = "set" . $inflector->camelize($setterMethodName);
if (method_exists($req, $setterMethodName))
{
$req->$setterMethodName($paraValue);
}
}
return $this->execute($req, $session);
}
private function getClusterTag()
{
return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
}
}

@ -0,0 +1,40 @@
<?php
/**
* TOP SDK 入口文件
* 请不要修改这个文件,除非你知道怎样修改以及怎样恢复
* @author xuteng.xt
*/
/**
* 定义常量开始
* 在include("TopSdk.php")之前定义这些常量,不要直接修改本文件,以利于升级覆盖
*/
/**
* SDK工作目录
* 存放日志TOP缓存数据
*/
if (!defined("TOP_SDK_WORK_DIR"))
{
define("TOP_SDK_WORK_DIR", "/tmp/");
}
/**
* 是否处于开发模式
* 在你自己电脑上开发程序的时候千万不要设为false以免缓存造成你的代码修改了不生效
* 部署到生产环境正式运营后如果性能压力大可以把此常量设定为false能提高运行速度对应的代价就是你下次升级程序时要清一下缓存
*/
if (!defined("TOP_SDK_DEV_MODE"))
{
define("TOP_SDK_DEV_MODE", true);
}
if (!defined("TOP_AUTOLOADER_PATH"))
{
define("TOP_AUTOLOADER_PATH", dirname(__FILE__));
}
/**
* 注册autoLoader,此注册autoLoader只加载top文件
* 不要删除,除非你自己加载文件。
**/
require("Autoloader.php");

@ -0,0 +1,255 @@
<?php
class AliyunClient
{
public $accessKeyId;
public $accessKeySecret;
public $serverUrl = "http://ecs.aliyuncs.com/";
public $format = "json";
public $connectTimeout = 3000;//3秒
public $readTimeout = 80000;//80秒
/** 是否打开入参check**/
public $checkRequest = true;
protected $signatureMethod = "HMAC-SHA1";
protected $signatureVersion = "1.0";
protected $dateTimeFormat = 'Y-m-d\TH:i:s\Z'; // ISO8601规范
protected $sdkVersion = "1.0";
public function execute($request)
{
if($this->checkRequest) {
try {
$request->check();
} catch (Exception $e) {
$result->code = $e->getCode();
$result->message = $e->getMessage();
return $result;
}
}
//获取业务参数
$apiParams = $request->getApiParas();
//组装系统参数
$apiParams["AccessKeyId"] = $this->accessKeyId;
$apiParams["Format"] = $this->format;//
$apiParams["SignatureMethod"] = $this->signatureMethod;
$apiParams["SignatureVersion"] = $this->signatureVersion;
$apiParams["SignatureNonce"] = uniqid();
date_default_timezone_set("GMT");
$apiParams["TimeStamp"] = date($this->dateTimeFormat);
$apiParams["partner_id"] = $this->sdkVersion;
$apiNameArray = split("\.", $request->getApiMethodName());
$apiParams["Action"] = $apiNameArray[3];
$apiParams["Version"] = $apiNameArray[4];
//签名
$apiParams["Signature"] = $this->computeSignature($apiParams, $this->accessKeySecret);
//系统参数放入GET请求串
$requestUrl = rtrim($this->serverUrl,"/") . "/?";
foreach ($apiParams as $apiParamKey => $apiParamValue)
{
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
}
$requestUrl = substr($requestUrl, 0, -1);
//发起HTTP请求
try
{
$resp = $this->curl($requestUrl, null);
}
catch (Exception $e)
{
$this->logCommunicationError($apiParams["Action"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
if ("json" == $this->format)
{
return json_decode($e->getMessage());
}
else if("xml" == $this->format)
{
return @simplexml_load_string($e->getMessage());
}
}
//解析API返回结果
$respWellFormed = false;
if ("json" == $this->format)
{
$respObject = json_decode($resp);
if (null !== $respObject)
{
$respWellFormed = true;
}
}
else if("xml" == $this->format)
{
$respObject = @simplexml_load_string($resp);
if (false !== $respObject)
{
$respWellFormed = true;
}
}
//返回的HTTP文本不是标准JSON或者XML记下错误日志
if (false === $respWellFormed)
{
$this->logCommunicationError($apiParams["Action"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
$result->code = 0;
$result->message = "HTTP_RESPONSE_NOT_WELL_FORMED";
return $result;
}
//如果TOP返回了错误码记录到业务错误日志中
if (isset($respObject->code))
{
$logger = new LtLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
$logger->log(array(
date("Y-m-d H:i:s"),
$resp
));
}
return $respObject;
}
public function exec($paramsArray)
{
if (!isset($paramsArray["Action"]))
{
trigger_error("No api name passed");
}
$inflector = new LtInflector;
$inflector->conf["separator"] = ".";
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["Action"], 7))) . "Request";
if (!class_exists($requestClassName))
{
trigger_error("No such api: " . $paramsArray["Action"]);
}
$req = new $requestClassName;
foreach($paramsArray as $paraKey => $paraValue)
{
$inflector->conf["separator"] = "_";
$setterMethodName = $inflector->camelize($paraKey);
$inflector->conf["separator"] = ".";
$setterMethodName = "set" . $inflector->camelize($setterMethodName);
if (method_exists($req, $setterMethodName))
{
$req->$setterMethodName($paraValue);
}
}
return $this->execute($req, $session);
}
protected function percentEncode($str)
{
// 使用urlencode编码后将"+","*","%7E"做替换即满足 API规定的编码规范
$res = urlencode($str);
$res = preg_replace('/\+/', '%20', $res);
$res = preg_replace('/\*/', '%2A', $res);
$res = preg_replace('/%7E/', '~', $res);
return $res;
}
protected function computeSignature($parameters, $accessKeySecret)
{
// 将参数Key按字典顺序排序
ksort($parameters);
// 生成规范化请求字符串
$canonicalizedQueryString = '';
foreach($parameters as $key => $value)
{
$canonicalizedQueryString .= '&' . $this->percentEncode($key)
. '=' . $this->percentEncode($value);
}
// 生成用于计算签名的字符串 stringToSign
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
// 计算签名注意accessKeySecret后面要加上字符'&'
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret . '&', true));
return $signature;
}
public function curl($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
//https 请求
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($postFields) && 0 < count($postFields))
{
$postBodyString = "";
$postMultipart = false;
foreach ($postFields as $k => $v)
{
if("@" != substr($v, 0, 1))//判断是不是文件上传
{
$postBodyString .= "$k=" . urlencode($v) . "&";
}
else//文件上传用multipart/form-data否则用www-form-urlencoded
{
$postMultipart = true;
}
}
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true);
if ($postMultipart)
{
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
else
{
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
}
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
curl_close($ch);
return $reponse;
}
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
{
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new LtLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->accessKeyId . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
date("Y-m-d H:i:s"),
$apiName,
$this->accessKeyId,
$localIp,
PHP_OS,
$this->sdkVersion,
$requestUrl,
$errorCode,
str_replace("\n","",$responseTxt)
);
$logger->log($logData);
}
}

@ -0,0 +1,653 @@
<?php
class DingTalkClient
{
/**@Author chaohui.zch copy from TopClient and modify 2016-12-14 **/
/**@Author chaohui.zch modify $gatewayUrl 2017-07-18 **/
public $gatewayUrl = "https://eco.taobao.com/router/rest";
public $format = "xml";
public $connectTimeout;
public $readTimeout;
public $apiCallType;
public $httpMethod;
/** 是否打开入参check**/
public $checkRequest = true;
protected $apiVersion = "2.0";
protected $sdkVersion = "dingtalk-sdk-php-20161214";
public function __construct($apiCallType = null, $httpMethod = null, $format = "xml"){
$this->apiCallType = $apiCallType;
$this->httpMethod = $httpMethod;
$this->format = $format;
}
public function curl($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
//https 请求
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($postFields) && 0 < count($postFields))
{
$postBodyString = "";
$postMultipart = false;
foreach ($postFields as $k => $v)
{
if("@" != substr($v, 0, 1))//判断是不是文件上传
{
$postBodyString .= "$k=" . urlencode($v) . "&";
}
else//文件上传用multipart/form-data否则用www-form-urlencoded
{
$postMultipart = true;
if(class_exists('\CURLFile')){
$postFields[$k] = new \CURLFile(substr($v, 1));
}
}
}
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true);
if ($postMultipart)
{
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
else
{
$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
}
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
public function curl_get($url,$apiFields = null)
{
$ch = curl_init();
foreach ($apiFields as $key => $value)
{
$url .= "&" ."$key=" . urlencode($value);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($this->readTimeout)
{
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout)
{
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
//https ignore ssl check ?
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" )
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
public function curl_json($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
//https 请求
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($postFields) && 0 < count($postFields))
{
$postBodyString = "";
$postMultipart = false;
foreach ($postFields as $k => $v)
{
if(!is_string($v)){
$v = json_encode($v);
}
if("@" != substr($v, 0, 1))//判断是不是文件上传
{
$postBodyString .= "$k=" . urlencode($v) . "&";
}
else//文件上传用multipart/form-data否则用www-form-urlencoded
{
$postMultipart = true;
if(class_exists('\CURLFile')){
$postFields[$k] = new \CURLFile(substr($v, 1));
}
}
}
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true);
if ($postMultipart)
{
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
else {
$header = array("Content-Type: application/json; charset=utf-8", "Content-Length:".strlen(json_encode($postFields)));
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
}
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
//https 请求
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//生成分隔符
$delimiter = '-------------' . uniqid();
//先将post的普通数据生成主体字符串
$data = '';
if($postFields != null){
foreach ($postFields as $name => $content) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"';
//multipart/form-data 不需要urlencode参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
$data .= "\r\n\r\n" . $content . "\r\n";
}
unset($name,$content);
}
//将上传的文件生成主体字符串
if($fileFields != null){
foreach ($fileFields as $name => $file) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['filename'] . "\" \r\n";
$data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
$data .= $file['content'] . "\r\n";
}
unset($name,$file);
}
//主体结束的分隔符
$data .= "--" . $delimiter . "--";
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER , array(
'Content-Type: multipart/form-data; boundary=' . $delimiter,
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$reponse = curl_exec($ch);
unset($data);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
{
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
date("Y-m-d H:i:s"),
$apiName,
$localIp,
PHP_OS,
$this->sdkVersion,
$requestUrl,
$errorCode,
str_replace("\n","",$responseTxt)
);
$logger->log($logData);
}
public function execute($request, $session = null,$bestUrl = null){
if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
return $this->_executeOapi($request, $session, $bestUrl, null, null, null, null);
}else{
return $this->_execute($request, $session, $bestUrl);
}
}
public function executeWithAccessKey($request, $bestUrl = null, $accessKey, $accessSecret){
return $this->executeWithCorpId($request, $bestUrl, $accessKey, $accessSecret, null, null);
}
public function executeWithSuiteTicket($request,$bestUrl = null, $accessKey, $accessSecret, $suiteTicket){
return $this->executeWithCorpId($request,$bestUrl, $accessKey, $accessSecret, $suiteTicket, null);
}
public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
return $this->_executeOapi($request, null, $bestUrl,$accessKey, $accessSecret, $suiteTicket, $corpId);
}else{
return $this->_execute($request, null, $bestUrl);
}
}
private function _executeOapi($request, $session = null,$bestUrl = null,$accessKey, $accessSecret, $suiteTicket, $corpId){
$result = new ResultSet();
if($this->checkRequest) {
try {
$request->check();
} catch (Exception $e) {
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
}
$sysParams["method"] = $request->getApiMethodName();
//系统参数放入GET请求串
if($bestUrl){
if(strpos($bestUrl,'?') === false){
$requestUrl = $bestUrl."?";
}else{
$requestUrl = $bestUrl;
}
}else{
$requestUrl = $this->gatewayUrl."?";
}
if(null != $accessKey){
$timestamp = $this->getMillisecond();
// 验证签名有效性
$canonicalString = $this->getCanonicalStringForIsv($timestamp, $suiteTicket);
$signature = $this->computeSignature($accessSecret, $canonicalString);
$queryParams["accessKey"] = $accessKey;
$queryParams["signature"] = $signature;
$queryParams["timestamp"] = $timestamp+"";
if($suiteTicket != null) {
$queryParams["suiteTicket"] = $suiteTicket;
}
if($corpId != null){
$queryParams["corpId"] = $corpId;
}
foreach ($queryParams as $queryParamKey => $queryParamValue) {
$requestUrl .= "$queryParamKey=" . urlencode($queryParamValue) . "&";
}
}else{
$requestUrl .= "access_token=" . urlencode($session) . "&";
}
$apiParams = array();
//获取业务参数
$apiParams = $request->getApiParas();
$fileFields = array();
foreach ($apiParams as $key => $value) {
if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
$value['name'] = $key;
$fileFields[$key] = $value;
unset($apiParams[$key]);
}
}
// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
$requestUrl = substr($requestUrl, 0, -1);
//发起HTTP请求
try
{
if(count($fileFields) > 0){
$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
}else{
if(DingTalkConstant::$METHOD_POST == $this->httpMethod){
$resp = $this->curl_json($requestUrl, $apiParams);
}else{
$resp = $this->curl_get($requestUrl, $apiParams);
}
}
}
catch (Exception $e)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
unset($apiParams);
unset($fileFields);
//解析TOP返回结果
$respWellFormed = false;
if ("json" == $this->format)
{
$respObject = json_decode($resp);
if (null !== $respObject)
{
$respWellFormed = true;
}
}
else if("xml" == $this->format)
{
$respObject = @simplexml_load_string($resp);
if (false !== $respObject)
{
$respWellFormed = true;
}
}
//返回的HTTP文本不是标准JSON或者XML记下错误日志
if (false === $respWellFormed)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
$result->code = 0;
$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
return $result;
}
//如果TOP返回了错误码记录到业务错误日志中
if (isset($respObject->code))
{
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . "_" . date("Y-m-d") . ".log";
$logger->log(array(
date("Y-m-d H:i:s"),
$resp
));
}
return $respObject;
}
private function getMillisecond() {
list($s1, $s2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
private function getCanonicalStringForIsv($timestamp, $suiteTicket) {
$result = $timestamp;
if($suiteTicket != null) {
$result .= "\n".$suiteTicket;
}
return $result;
}
private function computeSignature($accessSecret, $canonicalString){
$s = hash_hmac('sha256', $canonicalString, $accessSecret, true);
return base64_encode($s);
}
private function _execute($request, $session = null,$bestUrl = null)
{
$result = new ResultSet();
if($this->checkRequest) {
try {
$request->check();
} catch (Exception $e) {
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
}
//组装系统参数
$sysParams["v"] = $this->apiVersion;
$sysParams["format"] = $this->format;
$sysParams["method"] = $request->getApiMethodName();
$sysParams["timestamp"] = date("Y-m-d H:i:s");
if (null != $session)
{
$sysParams["session"] = $session;
}
$apiParams = array();
//获取业务参数
$apiParams = $request->getApiParas();
//系统参数放入GET请求串
if($bestUrl){
if(strpos($bestUrl,'?') === false){
$requestUrl = $bestUrl."?";
}else{
$requestUrl = $bestUrl;
}
$sysParams["partner_id"] = $this->getClusterTag();
}else{
$requestUrl = $this->gatewayUrl."?";
$sysParams["partner_id"] = $this->sdkVersion;
}
foreach ($sysParams as $sysParamKey => $sysParamValue)
{
// if(strcmp($sysParamKey,"timestamp") != 0)
$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
}
$fileFields = array();
foreach ($apiParams as $key => $value) {
if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
$value['name'] = $key;
$fileFields[$key] = $value;
unset($apiParams[$key]);
}
}
// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
$requestUrl = substr($requestUrl, 0, -1);
//发起HTTP请求
try
{
if(count($fileFields) > 0){
$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
}else{
$resp = $this->curl($requestUrl, $apiParams);
}
}
catch (Exception $e)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
unset($apiParams);
unset($fileFields);
//解析TOP返回结果
$respWellFormed = false;
if ("json" == $this->format)
{
$respObject = json_decode($resp);
if (null !== $respObject)
{
$respWellFormed = true;
foreach ($respObject as $propKey => $propValue)
{
$respObject = $propValue;
}
}
}
else if("xml" == $this->format)
{
$respObject = @simplexml_load_string($resp);
if (false !== $respObject)
{
$respWellFormed = true;
}
}
//返回的HTTP文本不是标准JSON或者XML记下错误日志
if (false === $respWellFormed)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
$result->code = 0;
$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
return $result;
}
//如果TOP返回了错误码记录到业务错误日志中
if (isset($respObject->code))
{
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . "_" . date("Y-m-d") . ".log";
$logger->log(array(
date("Y-m-d H:i:s"),
$resp
));
}
return $respObject;
}
public function exec($paramsArray)
{
if (!isset($paramsArray["method"]))
{
trigger_error("No api name passed");
}
$inflector = new LtInflector;
$inflector->conf["separator"] = ".";
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
if (!class_exists($requestClassName))
{
trigger_error("No such dingtalk-api: " . $paramsArray["method"]);
}
$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
$req = new $requestClassName;
foreach($paramsArray as $paraKey => $paraValue)
{
$inflector->conf["separator"] = "_";
$setterMethodName = $inflector->camelize($paraKey);
$inflector->conf["separator"] = ".";
$setterMethodName = "set" . $inflector->camelize($setterMethodName);
if (method_exists($req, $setterMethodName))
{
$req->$setterMethodName($paraValue);
}
}
return $this->execute($req, $session);
}
private function getClusterTag()
{
return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
}
}

@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: zuodeng
* Date: 2018/7/18
* Time: 上午11:31
*/
class DingTalkConstant
{
static $CALL_TYPE_OAPI = "oapi";
static $CALL_TYPE_TOP = "top";
static $METHOD_POST = "POST";
static $METHOD_GET = "GET";
static $FORMAT_JSON = "json";
static $FORMAT_XML = "xml";
}

@ -0,0 +1,47 @@
<?php
class ApplicationVar
{
var $save_file;
var $application = null;
var $app_data = '';
var $__writed = false;
function __construct()
{
$this->save_file = __DIR__.'/httpdns.conf' ;
$this->application = array();
}
public function setValue($var_name,$var_value)
{
if (!is_string($var_name) || empty($var_name))
return false;
$this->application[$var_name] = $var_value;
}
public function write(){
$this->app_data = @serialize($this->application);
$this->__writeToFile();
}
public function getValue()
{
if (!is_file($this->save_file))
$this->__writeToFile();
return @unserialize(@file_get_contents($this->save_file));
}
function __writeToFile()
{
$fp = @fopen($this->save_file,"w");
if(flock($fp , LOCK_EX | LOCK_NB)){
@fwrite($fp,$this->app_data);
flock($fp , LOCK_UN);
}
@fclose($fp);
}
}
?>

@ -0,0 +1,199 @@
<?php
class ClusterTopClient extends TopClient {
private static $dnsconfig;
private static $syncDate = 0;
private static $applicationVar ;
private static $cfgDuration = 10;
public function __construct($appkey = "",$secretKey = ""){
ClusterTopClient::$applicationVar = new ApplicationVar;
$this->appkey = $appkey;
$this->secretKey = $secretKey ;
$saveConfig = ClusterTopClient::$applicationVar->getValue();
if($saveConfig){
$tmpConfig = $saveConfig['dnsconfig'];
ClusterTopClient::$dnsconfig = $this->object_to_array($tmpConfig);
unset($tmpConfig);
ClusterTopClient::$syncDate = $saveConfig['syncDate'];
if(!ClusterTopClient::$syncDate)
ClusterTopClient::$syncDate = 0;
}
}
public function __destruct(){
if(ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate){
ClusterTopClient::$applicationVar->setValue("dnsconfig",ClusterTopClient::$dnsconfig);
ClusterTopClient::$applicationVar->setValue("syncDate",ClusterTopClient::$syncDate);
ClusterTopClient::$applicationVar->write();
}
}
public function execute($request = null, $session = null,$bestUrl = null){
$currentDate = date('U');
$syncDuration = $this->getDnsConfigSyncDuration();
$bestUrl = $this->getBestVipUrl($this->gatewayUrl,$request->getApiMethodName(),$session);
if($currentDate - ClusterTopClient::$syncDate > $syncDuration * 60){
$httpdns = new HttpdnsGetRequest;
ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns,null,$bestUrl)->result,true);
$syncDate = date('U');
ClusterTopClient::$syncDate = $syncDate ;
}
return parent::execute($request,$session,$bestUrl);
}
private function getDnsConfigSyncDuration(){
if(ClusterTopClient::$cfgDuration){
return ClusterTopClient::$cfgDuration;
}
if(!ClusterTopClient::$dnsconfig){
return ClusterTopClient::$cfgDuration;
}
$config = json_encode(ClusterTopClient::$dnsconfig);
if(!$config){
return ClusterTopClient::$cfgDuration;
}
$config = ClusterTopClient::$dnsconfig['config'];
$duration = $config['interval'];
ClusterTopClient::$cfgDuration = $duration;
return ClusterTopClient::$cfgDuration;
}
private function getBestVipUrl($url,$apiname = null,$session = null){
$config = ClusterTopClient::$dnsconfig['config'];
$degrade = $config['degrade'];
if(strcmp($degrade,'true') == 0){
return $url;
}
$currentEnv = $this->getEnvByApiName($apiname,$session);
$vip = $this->getVipByEnv($url,$currentEnv);
if($vip)
return $vip;
return $url;
}
private function getVipByEnv($comUrl,$currentEnv){
$urlSchema = parse_url($comUrl);
if(!$urlSchema)
return null;
if(!ClusterTopClient::$dnsconfig['env'])
return null;
if(!array_key_exists($currentEnv,ClusterTopClient::$dnsconfig['env']))
return null;
$hostList = ClusterTopClient::$dnsconfig['env'][$currentEnv];
if(!$hostList)
return null ;
$vipList = null;
foreach ($hostList as $key => $value) {
if(strcmp($key,$urlSchema['host']) == 0 && strcmp($value['proto'],$urlSchema['scheme']) == 0){
$vipList = $value;
break;
}
}
$vip = $this->getRandomWeightElement($vipList['vip']);
if($vip){
return $urlSchema['scheme']."://".$vip.$urlSchema['path'];
}
return null;
}
private function getEnvByApiName($apiName,$session=""){
$apiCfgArray = ClusterTopClient::$dnsconfig['api'];
if($apiCfgArray){
if(array_key_exists($apiName,$apiCfgArray)){
$apiCfg = $apiCfgArray[$apiName];
if(array_key_exists('user',$apiCfg)){
$userFlag = $apiCfg['user'];
$flag = $this->getUserFlag($session);
if($userFlag && $flag ){
return $this->getEnvBySessionFlag($userFlag,$flag);
}else{
return $this->getRandomWeightElement($apiCfg['rule']);
}
}
}
}
return $this->getDeafultEnv();
}
private function getUserFlag($session){
if($session && strlen($session) > 5){
if($session[0] == '6' || $session[0] == '7'){
return $session[strlen($session) -1];
}else if($session[0] == '5' || $session[0] == '8'){
return $session[5];
}
}
return null;
}
private function getEnvBySessionFlag($targetConfig,$flag){
if($flag){
$userConf = ClusterTopClient::$dnsconfig['user'];
$cfgArry = $userConf[$targetConfig];
foreach ($cfgArry as $key => $value) {
if(in_array($flag,$value))
return $key;
}
}else{
return null;
}
}
private function getRandomWeightElement($elements){
$totalWeight = 0;
if($elements){
foreach ($elements as $ele) {
$weight = $this->getElementWeight($ele);
$r = $this->randomFloat() * ($weight + $totalWeight);
if($r >= $totalWeight){
$selected = $ele;
}
$totalWeight += $weight;
}
if($selected){
return $this->getElementValue($selected);
}
}
return null;
}
private function getElementWeight($ele){
$params = explode('|', $ele);
return floatval($params[1]);
}
private function getElementValue($ele){
$params = explode('|', $ele);
return $params[0];
}
private function getDeafultEnv(){
return ClusterTopClient::$dnsconfig['config']['def_env'];
}
private static function startsWith($haystack, $needle) {
return $needle === "" || strpos($haystack, $needle) === 0;
}
private function object_to_array($obj)
{
$_arr= is_object($obj) ? get_object_vars($obj) : $obj;
foreach($_arr as $key=> $val)
{
$val= (is_array($val) || is_object($val))? $this->object_to_array($val) : $val;
$arr[$key] = $val;
}
return$arr;
}
private function randomFloat($min = 0, $max = 1) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); }
}
?>

@ -0,0 +1,23 @@
<?php
class HttpdnsGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.httpdns.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check(){}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,107 @@
<?php
/**
* API入参静态检查类
* 可以对API的参数类型、长度、最大值等进行校验
*
**/
class RequestCheckUtil
{
/**
* 校验字段 fieldName 的值$value非空
*
**/
public static function checkNotNull($value,$fieldName) {
if(self::checkEmpty($value)){
throw new Exception("client-check-error:Missing Required Arguments: " .$fieldName , 40);
}
}
/**
* 检验字段fieldName的值value 的长度
*
**/
public static function checkMaxLength($value,$maxLength,$fieldName){
if(!self::checkEmpty($value) && mb_strlen($value , "UTF-8") > $maxLength){
throw new Exception("client-check-error:Invalid Arguments:the length of " .$fieldName . " can not be larger than " . $maxLength . "." , 41);
}
}
/**
* 检验字段fieldName的值value的最大列表长度
*
**/
public static function checkMaxListSize($value,$maxSize,$fieldName) {
if(self::checkEmpty($value))
return ;
$list=preg_split("/,/",$value);
if(count($list) > $maxSize){
throw new Exception("client-check-error:Invalid Arguments:the listsize(the string split by \",\") of ". $fieldName . " must be less than " . $maxSize . " ." , 41);
}
}
/**
* 检验字段fieldName的值value 的最大值
*
**/
public static function checkMaxValue($value,$maxValue,$fieldName){
if(self::checkEmpty($value))
return ;
self::checkNumeric($value,$fieldName);
if($value > $maxValue){
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be larger than " . $maxValue ." ." , 41);
}
}
/**
* 检验字段fieldName的值value 的最小值
*
**/
public static function checkMinValue($value,$minValue,$fieldName) {
if(self::checkEmpty($value))
return ;
self::checkNumeric($value,$fieldName);
if($value < $minValue){
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be less than " . $minValue . " ." , 41);
}
}
/**
* 检验字段fieldName的值value是否是number
*
**/
protected static function checkNumeric($value,$fieldName) {
if(!is_numeric($value))
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " is not number : " . $value . " ." , 41);
}
/**
* 校验$value是否非空
* if not set ,return true;
* if is null , return true;
*
*
**/
public static function checkEmpty($value) {
if(!isset($value))
return true ;
if($value === null )
return true;
if(is_array($value) && count($value) == 0)
return true;
if(is_string($value) &&trim($value) === "")
return true;
return false;
}
}
?>

@ -0,0 +1,21 @@
<?php
/**
* 返回的默认类
*
* @author auto create
* @since 1.0, 2015-01-20
*/
class ResultSet
{
/**
* 返回的错误码
**/
public $code;
/**
* 返回的错误信息
**/
public $msg;
}

@ -0,0 +1,219 @@
<?php
class SpiUtils{
private static $top_sign_list = "HTTP_TOP_SIGN_LIST";
private static $timestamp = "timestamp";
private static $header_real_ip = array("X_Real_IP", "X_Forwarded_For", "Proxy_Client_IP",
"WL_Proxy_Client_IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR");
/**
* 校验SPI请求签名适用于所有GET请求及不包含文件参数的POST请求。
*
* @param request 请求对象
* @param secret app对应的secret
* @return true校验通过false校验不通过
*/
public static function checkSign4FormRequest($secret){
return self::checkSign(null,null,$secret);
}
/**
* 校验SPI请求签名适用于请求体是xml/json等可用文本表示的POST请求。
*
* @param request 请求对象
* @param body 请求体的文本内容
* @param secret app对应的secret
* @return true校验通过false校验不通过
*/
public static function checkSign4TextRequest($body,$secret){
return self::checkSign(null,$body,$secret);
}
/**
* 校验SPI请求签名适用于带文件上传的POST请求。
*
* @param request 请求对象
* @param form 除了文件参数以外的所有普通文本参数的map集合
* @param secret app对应的secret
* @return true校验通过false校验不通过
*/
public static function checkSign4FileRequest($form, $secret){
return self::checkSign($form, null, $secret);
}
private static function checkSign($form, $body, $secret) {
$params = array();
// 1. 获取header参数
$headerMap = self::getHeaderMap();
foreach ($headerMap as $k => $v){
$params[$k] = $v ;
}
// 2. 获取url参数
$queryMap = self::getQueryMap();
foreach ($queryMap as $k => $v){
$params[$k] = $v ;
}
// 3. 获取form参数
if ($form == null && $body == null) {
$formMap = self::getFormMap();
foreach ($formMap as $k => $v){
$params[$k] = $v ;
}
} else if ($form != null) {
foreach ($form as $k => $v){
$params[$k] = $v ;
}
}
if($body == null){
$body = file_get_contents('php://input');
}
$remoteSign = $queryMap["sign"];
$localSign = self::sign($params, $body, $secret);
if (strcmp($remoteSign, $localSign) == 0) {
return true;
} else {
$paramStr = self::getParamStrFromMap($params);
self::logCommunicationError($remoteSign,$localSign,$paramStr,$body);
return false;
}
}
private static function getHeaderMap() {
$headerMap = array();
$signList = $_SERVER['HTTP_TOP_SIGN_LIST']; // 只获取参与签名的头部字段
if(!$signList) {
return $headerMap;
}
$signList = trim($signList);
if (strlen($signList) > 0){
$params = split(",", $signList);
foreach ($_SERVER as $k => $v){
if (substr($k, 0, 5) == 'HTTP_'){
foreach($params as $kk){
$upperkey = strtoupper($kk);
if(self::endWith($k,$upperkey)){
$headerMap[$kk] = $v;
}
}
}
}
}
return $headerMap;
}
private static function getQueryMap(){
$queryStr = $_SERVER["QUERY_STRING"];
$resultArray = array();
foreach (explode('&', $queryStr) as $pair) {
list($key, $value) = explode('=', $pair);
if (strpos($key, '.') !== false) {
list($subKey, $subVal) = explode('.', $key);
if (preg_match('/(?P<name>\w+)\[(?P<index>\w+)\]/', $subKey, $matches)) {
$resultArray[$matches['name']][$matches['index']][$subVal] = $value;
} else {
$resultArray[$subKey][$subVal] = urldecode($value);
}
} else {
$resultArray[$key] = urldecode($value);
}
}
return $resultArray;
}
private static function checkRemoteIp(){
$remoteIp = $_SERVER["REMOTE_ADDR"];
foreach ($header_real_ip as $k){
$realIp = $_SERVER[$k];
$realIp = trim($realIp);
if(strlen($realIp) > 0 && strcasecmp("unknown",$realIp)){
$remoteIp = $realIp;
break;
}
}
return self::startsWith($remoteIp,"140.205.144.") || self::startsWith($remoteIp,"40.205.145.");
}
private static function getFormMap(){
$resultArray = array();
foreach($_POST as $key=>$v) {
$resultArray[$key] = $v ;
}
return $resultArray ;
}
private static function startsWith($haystack, $needle) {
return $needle === "" || strpos($haystack, $needle) === 0;
}
private static function endWith($haystack, $needle) {
$length = strlen($needle);
if($length == 0)
{
return true;
}
return (substr($haystack, -$length) === $needle);
}
private static function checkTimestamp(){
$ts = $_POST['timestamp'];
if($ts){
$clientTimestamp = strtotime($ts);
$current = $_SERVER['REQUEST_TIME'];
return ($current - $clientTimestamp) <= 5*60*1000;
}else{
return false;
}
}
private static function getParamStrFromMap($params){
ksort($params);
$stringToBeSigned = "";
foreach ($params as $k => $v)
{
if(strcmp("sign", $k) != 0)
{
$stringToBeSigned .= "$k$v";
}
}
unset($k, $v);
return $stringToBeSigned;
}
private static function sign($params,$body,$secret){
ksort($params);
$stringToBeSigned = $secret;
$stringToBeSigned .= self::getParamStrFromMap($params);
if($body)
$stringToBeSigned .= $body;
$stringToBeSigned .= $secret;
return strtoupper(md5($stringToBeSigned));
}
protected static function logCommunicationError($remoteSign, $localSign, $paramStr, $body)
{
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_". date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
"checkTopSign error" ,
"remoteSign=".$remoteSign ,
"localSign=".$localSign ,
"paramStr=".$paramStr ,
"body=".$body
);
$logger->log($logData);
}
private static function clear_blank($str, $glue='')
{
$replace = array(" ", "\r", "\n", "\t"); return str_replace($replace, $glue, $str);
}
}
?>

@ -0,0 +1,377 @@
<?php
class TopClient
{
public $appkey;
public $secretKey;
public $gatewayUrl = "http://gw.api.taobao.com/router/rest";
public $format = "xml";
public $connectTimeout;
public $readTimeout;
/** 是否打开入参check**/
public $checkRequest = true;
protected $signMethod = "md5";
protected $apiVersion = "2.0";
protected $sdkVersion = "top-sdk-php-20180326";
public function getAppkey()
{
return $this->appkey;
}
public function __construct($appkey = "",$secretKey = ""){
$this->appkey = $appkey;
$this->secretKey = $secretKey ;
}
protected function generateSign($params)
{
ksort($params);
$stringToBeSigned = $this->secretKey;
foreach ($params as $k => $v)
{
if(!is_array($v) && "@" != substr($v, 0, 1))
{
$stringToBeSigned .= "$k$v";
}
}
unset($k, $v);
$stringToBeSigned .= $this->secretKey;
return strtoupper(md5($stringToBeSigned));
}
public function curl($url, $postFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
//https 请求
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($postFields) && 0 < count($postFields))
{
$postBodyString = "";
$postMultipart = false;
foreach ($postFields as $k => $v)
{
if("@" != substr($v, 0, 1))//判断是不是文件上传
{
$postBodyString .= "$k=" . urlencode($v) . "&";
}
else//文件上传用multipart/form-data否则用www-form-urlencoded
{
$postMultipart = true;
if(class_exists('\CURLFile')){
$postFields[$k] = new \CURLFile(substr($v, 1));
}
}
}
unset($k, $v);
curl_setopt($ch, CURLOPT_POST, true);
if ($postMultipart)
{
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
else
{
$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
}
}
$reponse = curl_exec($ch);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
}
if ($this->connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
}
curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
//https 请求
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//生成分隔符
$delimiter = '-------------' . uniqid();
//先将post的普通数据生成主体字符串
$data = '';
if($postFields != null){
foreach ($postFields as $name => $content) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"';
//multipart/form-data 不需要urlencode参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
$data .= "\r\n\r\n" . $content . "\r\n";
}
unset($name,$content);
}
//将上传的文件生成主体字符串
if($fileFields != null){
foreach ($fileFields as $name => $file) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['name'] . "\" \r\n";
$data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
$data .= $file['content'] . "\r\n";
}
unset($name,$file);
}
//主体结束的分隔符
$data .= "--" . $delimiter . "--";
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER , array(
'Content-Type: multipart/form-data; boundary=' . $delimiter,
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$reponse = curl_exec($ch);
unset($data);
if (curl_errno($ch))
{
throw new Exception(curl_error($ch),0);
}
else
{
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode)
{
throw new Exception($reponse,$httpStatusCode);
}
}
curl_close($ch);
return $reponse;
}
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
{
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
$logger->conf["separator"] = "^_^";
$logData = array(
date("Y-m-d H:i:s"),
$apiName,
$this->appkey,
$localIp,
PHP_OS,
$this->sdkVersion,
$requestUrl,
$errorCode,
str_replace("\n","",$responseTxt)
);
$logger->log($logData);
}
public function execute($request, $session = null,$bestUrl = null)
{
$result = new ResultSet();
if($this->checkRequest) {
try {
$request->check();
} catch (Exception $e) {
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
}
//组装系统参数
$sysParams["app_key"] = $this->appkey;
$sysParams["v"] = $this->apiVersion;
$sysParams["format"] = $this->format;
$sysParams["sign_method"] = $this->signMethod;
$sysParams["method"] = $request->getApiMethodName();
$sysParams["timestamp"] = date("Y-m-d H:i:s");
if (null != $session)
{
$sysParams["session"] = $session;
}
$apiParams = array();
//获取业务参数
$apiParams = $request->getApiParas();
//系统参数放入GET请求串
if($bestUrl){
$requestUrl = $bestUrl."?";
$sysParams["partner_id"] = $this->getClusterTag();
}else{
$requestUrl = $this->gatewayUrl."?";
$sysParams["partner_id"] = $this->sdkVersion;
}
//签名
$sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams));
foreach ($sysParams as $sysParamKey => $sysParamValue)
{
// if(strcmp($sysParamKey,"timestamp") != 0)
$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
}
$fileFields = array();
foreach ($apiParams as $key => $value) {
if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
$value['name'] = $key;
$fileFields[$key] = $value;
unset($apiParams[$key]);
}
}
// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
$requestUrl = substr($requestUrl, 0, -1);
//发起HTTP请求
try
{
if(count($fileFields) > 0){
$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
}else{
$resp = $this->curl($requestUrl, $apiParams);
}
}
catch (Exception $e)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
$result->code = $e->getCode();
$result->msg = $e->getMessage();
return $result;
}
unset($apiParams);
unset($fileFields);
//解析TOP返回结果
$respWellFormed = false;
if ("json" == $this->format)
{
$respObject = json_decode($resp);
if (null !== $respObject)
{
$respWellFormed = true;
foreach ($respObject as $propKey => $propValue)
{
$respObject = $propValue;
}
}
}
else if("xml" == $this->format)
{
$respObject = @simplexml_load_string($resp);
if (false !== $respObject)
{
$respWellFormed = true;
}
}
//返回的HTTP文本不是标准JSON或者XML记下错误日志
if (false === $respWellFormed)
{
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
$result->code = 0;
$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
return $result;
}
//如果TOP返回了错误码记录到业务错误日志中
if (isset($respObject->code))
{
$logger = new TopLogger;
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
$logger->log(array(
date("Y-m-d H:i:s"),
$resp
));
}
return $respObject;
}
public function exec($paramsArray)
{
if (!isset($paramsArray["method"]))
{
trigger_error("No api name passed");
}
$inflector = new LtInflector;
$inflector->conf["separator"] = ".";
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
if (!class_exists($requestClassName))
{
trigger_error("No such api: " . $paramsArray["method"]);
}
$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
$req = new $requestClassName;
foreach($paramsArray as $paraKey => $paraValue)
{
$inflector->conf["separator"] = "_";
$setterMethodName = $inflector->camelize($paraKey);
$inflector->conf["separator"] = ".";
$setterMethodName = "set" . $inflector->camelize($setterMethodName);
if (method_exists($req, $setterMethodName))
{
$req->$setterMethodName($paraValue);
}
}
return $this->execute($req, $session);
}
private function getClusterTag()
{
return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
}
}

@ -0,0 +1,43 @@
<?php
class TopLogger
{
public $conf = array(
"separator" => "\t",
"log_file" => ""
);
private $fileHandle;
protected function getFileHandle()
{
if (null === $this->fileHandle)
{
if (empty($this->conf["log_file"]))
{
trigger_error("no log file spcified.");
}
$logDir = dirname($this->conf["log_file"]);
if (!is_dir($logDir))
{
mkdir($logDir, 0777, true);
}
$this->fileHandle = fopen($this->conf["log_file"], "a");
}
return $this->fileHandle;
}
public function log($logData)
{
if ("" == $logData || array() == $logData)
{
return false;
}
if (is_array($logData))
{
$logData = implode($this->conf["separator"], $logData);
}
$logData = $logData. "\n";
fwrite($this->getFileHandle(), $logData);
}
}
?>

@ -0,0 +1,25 @@
<?php
/**
* data
* @author auto create
*/
class Data
{
/**
* 共享字段 - 渠道或会员列表
**/
public $inviter_list;
/**
* 渠道专属pidList
**/
public $root_pid_channel_list;
/**
* 共享字段 - 总记录数
**/
public $total_count;
}
?>

@ -0,0 +1,15 @@
<?php
/**
* 扩展属性
* @author auto create
*/
class Extend
{
/**
* empty
**/
public $empty;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 选品库详细信息
* @author auto create
*/
class FavoritesDetail
{
/**
* 选品库id
**/
public $favorites_id;
/**
* 选品库标题
**/
public $favorites_title;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 选品库信息
* @author auto create
*/
class FavoritesInfo
{
/**
* 选品库详细信息
**/
public $favorites_list;
/**
* 选品库总数量
**/
public $total_count;
}
?>

@ -0,0 +1,110 @@
<?php
/**
* 商品数据
* @author auto create
*/
class Items
{
/**
* 聚划算价格,单位分
**/
public $act_price;
/**
* 类目名称
**/
public $category_name;
/**
* itemId
**/
public $item_id;
/**
* 商品卖点
**/
public $item_usp_list;
/**
* 聚划算id
**/
public $ju_id;
/**
* 开团结束时间
**/
public $online_end_time;
/**
* 开团时间
**/
public $online_start_time;
/**
* 原价
**/
public $orig_price;
/**
* 是否包邮
**/
public $pay_postage;
/**
* pc链接
**/
public $pc_url;
/**
* pc主图
**/
public $pic_url_for_p_c;
/**
* 无线主图
**/
public $pic_url_for_w_l;
/**
* 频道id
**/
public $platform_id;
/**
* 价格卖点
**/
public $price_usp_list;
/**
* 展示结束时间
**/
public $show_end_time;
/**
* 开始展示时间
**/
public $show_start_time;
/**
* 淘宝类目id
**/
public $tb_first_cat_id;
/**
* 商品标题
**/
public $title;
/**
* 卖点描述
**/
public $usp_desc_list;
/**
* 无线链接
**/
public $wap_url;
}
?>

@ -0,0 +1,29 @@
<?php
/**
* KFC 关键词过滤匹配结果
* @author auto create
*/
class KfcSearchResult
{
/**
* 过滤后的文本:
当匹配到B等级的词时文本中的关键词被替换为*号content即为关键词替换后的文本
其他情况content始终为null
**/
public $content;
/**
* 匹配到的关键词的等级值为null或为A、B、C、D。
当匹配不到关键词时值为null否则值为A、B、C、D中的一个。
A、B、C、D等级按严重程度从高至低排列。
**/
public $level;
/**
* 是否匹配到关键词,匹配到则为true.
**/
public $matched;
}
?>

@ -0,0 +1,385 @@
<?php
/**
* resultList
* @author auto create
*/
class MapData
{
/**
* 商品信息-叶子类目id
**/
public $category_id;
/**
* 商品信息-叶子类目名称
**/
public $category_name;
/**
* 商品信息-佣金比率。1550表示15.5%
**/
public $commission_rate;
/**
* 商品信息-佣金类型。MKT表示营销计划SP表示定向计划COMMON表示通用计划
**/
public $commission_type;
/**
* 优惠券(元) 若属于预售商品,该优惠券付尾款可用,付定金不可用
**/
public $coupon_amount;
/**
* 优惠券信息-优惠券结束时间
**/
public $coupon_end_time;
/**
* 优惠券信息-优惠券id
**/
public $coupon_id;
/**
* 优惠券信息-优惠券满减信息
**/
public $coupon_info;
/**
* 优惠券信息-优惠券剩余量
**/
public $coupon_remain_count;
/**
* 链接-宝贝+券二合一页面链接
**/
public $coupon_share_url;
/**
* 优惠券信息-优惠券起用门槛满X元可用。如满299元减20元
**/
public $coupon_start_fee;
/**
* 优惠券信息-优惠券开始时间
**/
public $coupon_start_time;
/**
* 优惠券信息-优惠券总量
**/
public $coupon_total_count;
/**
* 本地化-到门店距离(米)
**/
public $distance;
/**
* 商品信息-是否包含定向计划
**/
public $include_dxjh;
/**
* 商品信息-是否包含营销计划
**/
public $include_mkt;
/**
* 商品信息-定向计划信息
**/
public $info_dxjh;
/**
* 商品信息-宝贝描述(推荐理由)
**/
public $item_description;
/**
* 商品信息-宝贝id
**/
public $item_id;
/**
* 链接-宝贝地址
**/
public $item_url;
/**
* 拼团专用-拼团几人团
**/
public $jdd_num;
/**
* 拼团专用-拼团拼成价,单位元
**/
public $jdd_price;
/**
* 跨店满减信息
**/
public $kuadian_promotion_info;
/**
* 商品信息-一级类目ID
**/
public $level_one_category_id;
/**
* 商品信息-一级类目名称
**/
public $level_one_category_name;
/**
* 锁住的佣金率
**/
public $lock_rate;
/**
* 锁佣结束时间
**/
public $lock_rate_end_time;
/**
* 锁佣开始时间
**/
public $lock_rate_start_time;
/**
* 店铺信息-卖家昵称
**/
public $nick;
/**
* 商品信息-宝贝id(该字段废弃,请勿再用)
**/
public $num_iid;
/**
* 拼团专用-拼团结束时间
**/
public $oetime;
/**
* 拼团专用-拼团一人价(原价),单位元
**/
public $orig_price;
/**
* 拼团专用-拼团开始时间
**/
public $ostime;
/**
* 商品信息-商品主图
**/
public $pict_url;
/**
* 预售商品-定金(元)
**/
public $presale_deposit;
/**
* 预售商品-优惠
**/
public $presale_discount_fee_text;
/**
* 预售商品-付定金结束时间(毫秒)
**/
public $presale_end_time;
/**
* 预售商品-付定金开始时间(毫秒)
**/
public $presale_start_time;
/**
* 预售商品-付尾款结束时间(毫秒)
**/
public $presale_tail_end_time;
/**
* 预售商品-付尾款开始时间(毫秒)
**/
public $presale_tail_start_time;
/**
* 商品信息-宝贝所在地
**/
public $provcity;
/**
* 商品邮费
**/
public $real_post_fee;
/**
* 商品信息-商品一口价格
**/
public $reserve_price;
/**
* 比价场景专用当系统检测到入参消费者ID购买当前商品会获得《天天开彩蛋》玩法的彩蛋时该字段显示1否则为0
**/
public $reward_info;
/**
* 本地化-销售开始时间
**/
public $sale_begin_time;
/**
* 本地化-销售结束时间
**/
public $sale_end_time;
/**
* 活动价
**/
public $sale_price;
/**
* 拼团专用-拼团已售数量
**/
public $sell_num;
/**
* 店铺信息-卖家id
**/
public $seller_id;
/**
* 店铺信息-店铺dsr评分
**/
public $shop_dsr;
/**
* 店铺信息-店铺名称
**/
public $shop_title;
/**
* 商品信息-商品短标题
**/
public $short_title;
/**
* 商品信息-商品小图列表
**/
public $small_images;
/**
* 拼团专用-拼团剩余库存
**/
public $stock;
/**
* 是否品牌精选0不是1是
**/
public $superior_brand;
/**
* 商品信息-商品标题
**/
public $title;
/**
* 商品信息-月支出佣金(该字段废弃,请勿再用)
**/
public $tk_total_commi;
/**
* 商品信息-淘客30天推广量
**/
public $tk_total_sales;
/**
* 营销-天猫营销玩法
**/
public $tmall_play_activity_info;
/**
* 拼团专用-拼团库存数量
**/
public $total_stock;
/**
* 链接-宝贝推广链接
**/
public $url;
/**
* 本地化-可用店铺id
**/
public $usable_shop_id;
/**
* 本地化-可用店铺名称
**/
public $usable_shop_name;
/**
* 店铺信息-卖家类型。0表示集市1表示天猫
**/
public $user_type;
/**
* 预售专用-预售数量
**/
public $uv_sum_pre_sale;
/**
* 商品信息-30天销量饿了么卡券信息-总销量)
**/
public $volume;
/**
* 商品信息-商品白底图
**/
public $white_image;
/**
* 链接-物料块id(测试中请勿使用)
**/
public $x_id;
/**
* 预售有礼-推广链接
**/
public $ysyl_click_url;
/**
* 预售有礼-佣金比例( 预售有礼活动享受的推广佣金比例推广该活动有特殊分成规则请详见https://tbk.bbs.taobao.com/detail.html?appId=45301&postId=9334376
**/
public $ysyl_commission_rate;
/**
* 预售有礼-预估淘礼金(元)
**/
public $ysyl_tlj_face;
/**
* 预售有礼-淘礼金发放时间
**/
public $ysyl_tlj_send_time;
/**
* 预售有礼-淘礼金使用结束时间
**/
public $ysyl_tlj_use_end_time;
/**
* 预售有礼-淘礼金使用开始时间
**/
public $ysyl_tlj_use_start_time;
/**
* 折扣价(元) 若属于预售商品,付定金时间内,折扣价=预售价
**/
public $zk_final_price;
}
?>

@ -0,0 +1,210 @@
<?php
/**
* 淘宝客商品
* @author auto create
*/
class NTbkItem
{
/**
* 叶子类目名称
**/
public $cat_leaf_name;
/**
* 一级类目名称
**/
public $cat_name;
/**
* 是否包邮
**/
public $free_shipment;
/**
* 好评率是否高于行业均值
**/
public $h_good_rate;
/**
* 成交转化是否高于行业均值
**/
public $h_pay_rate30;
/**
* 退款率是否低于行业均值
**/
public $i_rfd_rate;
/**
* 是否加入消费者保障
**/
public $is_prepay;
/**
* 商品链接
**/
public $item_url;
/**
* 聚划算信息-聚淘结束时间(毫秒)
**/
public $ju_online_end_time;
/**
* 聚划算信息-聚淘开始时间(毫秒)
**/
public $ju_online_start_time;
/**
* 聚划算满减 -结束时间(毫秒)
**/
public $ju_play_end_time;
/**
* 聚划算满减 -开始时间(毫秒)
**/
public $ju_play_start_time;
/**
* 聚划算信息-商品预热结束时间(毫秒)
**/
public $ju_pre_show_end_time;
/**
* 聚划算信息-商品预热开始时间(毫秒)
**/
public $ju_pre_show_start_time;
/**
* 跨店满减信息
**/
public $kuadian_promotion_info;
/**
* 商品库类型,支持多库类型输出,以英文逗号分隔“,”分隔1:营销商品主推库如果值为空则不属于1这种商品类型
**/
public $material_lib_type;
/**
* 店铺名称
**/
public $nick;
/**
* 商品ID
**/
public $num_iid;
/**
* 商品主图
**/
public $pict_url;
/**
* 1聚划算满减满N件减X元满N件X折满N件X元 2天猫限时抢前N分钟每件X元前N分钟满N件每件X元前N件每件X元
**/
public $play_info;
/**
* 预售商品-定金(元)
**/
public $presale_deposit;
/**
* 预售商品-商品优惠信息
**/
public $presale_discount_fee_text;
/**
* 预售商品-付定金结束时间(毫秒)
**/
public $presale_end_time;
/**
* 预售商品-付定金开始时间(毫秒)
**/
public $presale_start_time;
/**
* 预售商品-付定金结束时间(毫秒)
**/
public $presale_tail_end_time;
/**
* 预售商品-付尾款开始时间(毫秒)
**/
public $presale_tail_start_time;
/**
* 商品所在地
**/
public $provcity;
/**
* 卖家等级
**/
public $ratesum;
/**
* 商品一口价格
**/
public $reserve_price;
/**
* 活动价
**/
public $sale_price;
/**
* 卖家id
**/
public $seller_id;
/**
* 店铺dsr 评分
**/
public $shop_dsr;
/**
* 商品小图列表
**/
public $small_images;
/**
* 是否品牌精选0不是1是
**/
public $superior_brand;
/**
* 商品标题
**/
public $title;
/**
* 天猫限时抢可售 -结束时间(毫秒)
**/
public $tmall_play_activity_end_time;
/**
* 天猫限时抢可售 -开始时间(毫秒)
**/
public $tmall_play_activity_start_time;
/**
* 卖家类型0表示集市1表示商城
**/
public $user_type;
/**
* 30天销量
**/
public $volume;
/**
* 折扣价(元) 若属于预售商品,付定金时间内,折扣价=预售价
**/
public $zk_final_price;
}
?>

@ -0,0 +1,45 @@
<?php
/**
* 淘宝客店铺
* @author auto create
*/
class NTbkShop
{
/**
* 淘客地址
**/
public $click_url;
/**
* 店标图片
**/
public $pict_url;
/**
* 卖家昵称
**/
public $seller_nick;
/**
* 店铺名称
**/
public $shop_title;
/**
* 店铺类型B天猫C淘宝
**/
public $shop_type;
/**
* 店铺地址
**/
public $shop_url;
/**
* 卖家ID
**/
public $user_id;
}
?>

@ -0,0 +1,30 @@
<?php
/**
* 复购订单,仅适用于手淘拉新
* @author auto create
*/
class OrderData
{
/**
* 预估佣金
**/
public $commission;
/**
* 收货时间
**/
public $confirm_receive_time;
/**
* 订单号
**/
public $order_no;
/**
* 支付时间
**/
public $pay_time;
}
?>

@ -0,0 +1,40 @@
<?php
/**
* PublisherOrderDto
* @author auto create
*/
class OrderPage
{
/**
* 是否还有下一页
**/
public $has_next;
/**
* 是否还有上一页
**/
public $has_pre;
/**
* 页码
**/
public $page_no;
/**
* 页大小
**/
public $page_size;
/**
* 位点字段,由调用方原样传递
**/
public $position_index;
/**
* PublisherOrderDto
**/
public $results;
}
?>

@ -0,0 +1,30 @@
<?php
/**
* 真正的业务数据结构
* @author auto create
*/
class PageResult
{
/**
* pageNo
**/
public $page_no;
/**
* pageSize
**/
public $page_size;
/**
* 订单列表
**/
public $results;
/**
* 总值
**/
public $total_count;
}
?>

@ -0,0 +1,60 @@
<?php
/**
* 返回结果
* @author auto create
*/
class PaginationResult
{
/**
* 当前页码
**/
public $current_page;
/**
* 扩展属性
**/
public $extend;
/**
* 商品数据
**/
public $model_list;
/**
* 错误码
**/
public $msg_code;
/**
* 错误信息
**/
public $msg_info;
/**
* 一页大小
**/
public $page_size;
/**
* 请求是否成功
**/
public $success;
/**
* 商品总数
**/
public $total_item;
/**
* 总页数
**/
public $total_page;
/**
* 埋点信息
**/
public $track_params;
}
?>

@ -0,0 +1,25 @@
<?php
/**
* 权益扩展信息
* @author auto create
*/
class PromotionExtend
{
/**
* 权益链接
**/
public $promotion_url;
/**
* 权益推荐商品
**/
public $recommend_item_list;
/**
* 有价券信息
**/
public $youjia_coupon_info;
}
?>

@ -0,0 +1,30 @@
<?php
/**
* 权益信息
* @author auto create
*/
class PromotionList
{
/**
* 权益起用门槛满X元可用券场景为满元精确到分如满100元可用
**/
public $entry_condition;
/**
* 权益面额,券场景为减钱,精确到分
**/
public $entry_discount;
/**
* 权益结束时间,精确到毫秒时间戳
**/
public $entry_used_end_time;
/**
* 权益开始时间,精确到毫秒时间戳
**/
public $entry_used_start_time;
}
?>

@ -0,0 +1,285 @@
<?php
/**
* PublisherOrderDto
* @author auto create
*/
class PublisherOrderDto
{
/**
* 推广位管理下的推广位名称对应的ID同时也是pid=mm_1_2_3中的“3”这段数字
**/
public $adzone_id;
/**
* 推广位管理下的自定义推广位名称
**/
public $adzone_name;
/**
* 推广者赚取佣金后支付给阿里妈妈的技术服务费用的比率
**/
public $alimama_rate;
/**
* 技术服务费=结算金额*收入比率*技术服务费率。推广者赚取佣金后支付给阿里妈妈的技术服务费用
**/
public $alimama_share_fee;
/**
* 买家拍下付款的金额(不包含运费金额)
**/
public $alipay_total_price;
/**
* 口碑子订单号
**/
public $alsc_id;
/**
* 口碑父订单号
**/
public $alsc_pid;
/**
* 通过推广链接达到商品、店铺详情页的点击时间
**/
public $click_time;
/**
* 预售时期,用户对预售商品支付的定金金额
**/
public $deposit_price;
/**
* 产品类型
**/
public $flow_source;
/**
* 订单结算的佣金比率+平台的补贴比率
**/
public $income_rate;
/**
* 订单是否为激励池订单 1表征是 0表征否
**/
public $is_lx;
/**
* 商品所属的一级类目名称
**/
public $item_category_name;
/**
* 商品id
**/
public $item_id;
/**
* 商品图片
**/
public $item_img;
/**
* 商品链接
**/
public $item_link;
/**
* 商品数量
**/
public $item_num;
/**
* 商品单价
**/
public $item_price;
/**
* 商品标题
**/
public $item_title;
/**
* 激励池对应的rid
**/
public $lx_rid;
/**
* 订单所属平台类型,包括天猫、淘宝、聚划算等
**/
public $order_type;
/**
* 买家确认收货的付款金额(不包含运费金额)
**/
public $pay_price;
/**
* 推广者的会员id
**/
public $pub_id;
/**
* 结算预估收入=结算金额*提成。以买家确认收货的付款金额为基数,预估您可能获得的收入。因买家退款、您违规推广等原因,可能与您最终收入不一致。最终收入以月结后您实际收到的为准
**/
public $pub_share_fee;
/**
* 付款预估收入=付款金额*提成。指买家付款金额为基数,预估您可能获得的收入。因买家退款等原因,可能与结算预估收入不一致
**/
public $pub_share_pre_fee;
/**
* 从结算佣金中分得的收益比率
**/
public $pub_share_rate;
/**
* 维权标签0 含义为非维权 1 含义为维权订单
**/
public $refund_tag;
/**
* 渠道关系id
**/
public $relation_id;
/**
* 掌柜旺旺
**/
public $seller_nick;
/**
* 店铺名称
**/
public $seller_shop_title;
/**
* 服务费信息
**/
public $service_fee_dto_list;
/**
* 媒体管理下的ID同时也是pid=mm_1_2_3中的“2”这段数字
**/
public $site_id;
/**
* 媒体管理下的对应ID的自定义名称
**/
public $site_name;
/**
* 会员运营id
**/
public $special_id;
/**
* 补贴金额=结算金额*补贴比率
**/
public $subsidy_fee;
/**
* 平台给与的补贴比率,如天猫、淘宝、聚划算等
**/
public $subsidy_rate;
/**
* 平台出资方,如天猫、淘宝、或聚划算等
**/
public $subsidy_type;
/**
* 预售时期,用户对预售商品支付定金的付款时间
**/
public $tb_deposit_time;
/**
* 订单在淘宝拍下付款的时间
**/
public $tb_paid_time;
/**
* 成交平台
**/
public $terminal_type;
/**
* 结算内容专项服务费:内容场景专项技术服务费,内容推广者在内容场景进行推广需要支付给阿里妈妈专项的技术服务费用。专项服务费=结算金额*专项服务费率。
**/
public $tk_commission_fee_for_media_platform;
/**
* 预估内容专项服务费:内容场景专项技术服务费,内容推广者在内容场景进行推广需要支付给阿里妈妈专项的技术服务费用。专项服务费=付款金额*专项服务费率。
**/
public $tk_commission_pre_fee_for_media_platform;
/**
* 内容专项服务费率:内容场景专项技术服务费率,内容推广者在内容场景进行推广需要按结算金额支付一定比例给阿里妈妈作为内容场景专项技术服务费,用于提供与内容平台实现产品技术对接等服务。
**/
public $tk_commission_rate_for_media_platform;
/**
* 订单创建的时间,该时间同步淘宝,可能会略晚于买家在淘宝的订单创建时间
**/
public $tk_create_time;
/**
* 预售时期,用户对预售商品支付定金的付款时间,可能略晚于在淘宝付定金时间
**/
public $tk_deposit_time;
/**
* 订单确认收货后且商家完成佣金支付的时间
**/
public $tk_earning_time;
/**
* 二方:佣金收益的第一归属者; 三方:从其他淘宝客佣金中进行分成的推广者
**/
public $tk_order_role;
/**
* 订单付款的时间,该时间同步淘宝,可能会略晚于买家在淘宝的订单创建时间
**/
public $tk_paid_time;
/**
* 已付款:指订单已付款,但还未确认收货 已收货:指订单已确认收货,但商家佣金未支付 已结算:指订单已确认收货,且商家佣金已支付成功 已失效:指订单关闭/订单佣金小于0.01元订单关闭主要有1买家超时未付款 2买家付款前买家/卖家取消了订单3订单付款后发起售中退款成功3订单结算12订单付款 13订单失效14订单成功
**/
public $tk_status;
/**
* 提成=收入比率*分成比率。指实际获得收益的比率
**/
public $tk_total_rate;
/**
* 佣金金额=结算金额*佣金比率
**/
public $total_commission_fee;
/**
* 佣金比率
**/
public $total_commission_rate;
/**
* 买家通过购物车购买的每个商品对应的订单编号,此订单编号并未在淘宝买家后台透出
**/
public $trade_id;
/**
* 买家在淘宝后台显示的订单编号
**/
public $trade_parent_id;
/**
* unid(本字段不对外开放)
**/
public $unid;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 权益推荐商品
* @author auto create
*/
class RecommendItemList
{
/**
* 权益推荐商品id
**/
public $item_id;
/**
* 商品链接
**/
public $url;
}
?>

@ -0,0 +1,50 @@
<?php
/**
* 线下备案专属信息
* @author auto create
*/
class RegisterInfoDto
{
/**
* 渠道独有 -经营类型
**/
public $career;
/**
* 渠道独有 -对应的证件证件类型编号
**/
public $certify_number;
/**
* 渠道独有 -详细地址
**/
public $detail_address;
/**
* 渠道独有 -地区
**/
public $location;
/**
* 渠道独有 -手机号码
**/
public $phone_number;
/**
* 渠道独有 -证件类型
**/
public $shop_certify_type;
/**
* 渠道独有 -店铺名称
**/
public $shop_name;
/**
* 渠道独有 -店铺类型
**/
public $shop_type;
}
?>

@ -0,0 +1,125 @@
<?php
/**
* 订单列表
* @author auto create
*/
class Result
{
/**
* (口碑订单)口碑子订单号
**/
public $alsc_id;
/**
* (口碑订单)口碑父订单号
**/
public $alsc_pid;
/**
* 订单结算时间
**/
public $earning_time;
/**
* 维权金额
**/
public $refund_fee;
/**
* 维权创建(淘客结算回执) 4,维权成功(淘客结算回执) 2,维权失败(淘客结算回执) 3,发生多次维权,待处理 11,从淘客处补扣(钱已结给淘客) 等待扣款 12,从淘客处补扣(钱已结给淘客) 扣款成功 13,从卖家处补扣(钱已结给卖家) 等待扣款 14,从卖家处补扣(钱已结给卖家) 扣款成功 15
**/
public $refund_status;
/**
* 1 表示2方2表示3方
**/
public $refund_type;
/**
* 渠道关系id
**/
public $relation_id;
/**
* 会员关系id
**/
public $special_id;
/**
* 宝贝标题
**/
public $tb_auction_title;
/**
* 订单创建时间
**/
public $tb_trade_create_time;
/**
* 结算金额
**/
public $tb_trade_finish_price;
/**
* 淘宝子订单编号
**/
public $tb_trade_id;
/**
* 淘宝订单编号
**/
public $tb_trade_parent_id;
/**
* 第三方推广者memberid
**/
public $tk3rd_pub_id;
/**
* 应返商家金额(三方)
**/
public $tk3rd_pub_show_return_fee;
/**
* 第三方应该返还的佣金
**/
public $tk_commission_fee_refund3rd_pub;
/**
* 第二方应该返还的佣金(不包括技术服务费)
**/
public $tk_commission_fee_refund_pub;
/**
* 推广者memberid
**/
public $tk_pub_id;
/**
* 应返商家金额(二方)
**/
public $tk_pub_show_return_fee;
/**
* 维权完成时间
**/
public $tk_refund_suit_time;
/**
* 维权创建时间
**/
public $tk_refund_time;
/**
* 第三方应该返还的补贴
**/
public $tk_subsidy_fee_refund3rd_pub;
/**
* 第二方应该返还的补贴(不包括技术服务费)
**/
public $tk_subsidy_fee_refund_pub;
}
?>

@ -0,0 +1,15 @@
<?php
/**
* data
* @author auto create
*/
class Results
{
/**
* data
**/
public $data;
}
?>

@ -0,0 +1,30 @@
<?php
/**
* model
* @author auto create
*/
class RightsInstanceCreateResult
{
/**
* 创建完成后资金账户可用资金单位元保留2位小数
**/
public $available_fee;
/**
* 淘礼金Id
**/
public $rights_id;
/**
* 淘礼金领取Url
**/
public $send_url;
/**
* 投放code【百川商品详情页业务专用】
**/
public $vegas_code;
}
?>

@ -0,0 +1,25 @@
<?php
/**
* 渠道关系id的发放数据
* @author auto create
*/
class RightsSendRelationRptDto
{
/**
* 日期
**/
public $biz_date;
/**
* 红包发放数量
**/
public $fund_num;
/**
* 渠道关系id
**/
public $relation_id;
}
?>

@ -0,0 +1,15 @@
<?php
/**
* model
* @author auto create
*/
class RightsSendRptDTO
{
/**
* 渠道关系id的发放数据
**/
public $relation_rpt_list;
}
?>

@ -0,0 +1,35 @@
<?php
/**
* 返回结果封装对象
* @author auto create
*/
class RpcResult
{
/**
* 业务错误码 101, 102,103
**/
public $biz_error_code;
/**
* 业务错误信息
**/
public $biz_error_desc;
/**
* 真正的业务数据结构
**/
public $data;
/**
* 接口返回值信息跟rpc架构保持一致
**/
public $result_code;
/**
* 返回信息
**/
public $result_msg;
}
?>

@ -0,0 +1,30 @@
<?php
/**
* 服务费信息
* @author auto create
*/
class ServiceFeeDto
{
/**
* 结算专项服务费
**/
public $share_fee;
/**
* 预估专项服务费
**/
public $share_pre_fee;
/**
* 专项服务费率
**/
public $share_relative_rate;
/**
* 专项服务费来源122-渠道
**/
public $tk_share_role_type;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 传播形式对象列表
* @author auto create
*/
class TbkSpread
{
/**
* 传播形式, 目前只支持短链接
**/
public $content;
/**
* 调用错误信息由于是批量接口请重点关注每条请求返回的结果如果非OK则说明该结果对应的content不正常请酌情处理;
**/
public $err_msg;
}
?>

@ -0,0 +1,15 @@
<?php
/**
* 请求列表内部包含多个url
* @author auto create
*/
class TbkSpreadRequest
{
/**
* 原始url, 只支持uland.taobao.coms.click.taobao.com ai.taobao.comtemai.taobao.com的域名转换否则判错
**/
public $url;
}
?>

@ -0,0 +1,70 @@
<?php
/**
* model
* @author auto create
*/
class TljInstanceReportDto
{
/**
* 引导成交金额
**/
public $alipay_amount;
/**
* 退款红包金额
**/
public $fp_refund_amount;
/**
* 退款红包个数
**/
public $fp_refund_num;
/**
* 引导预估佣金金额
**/
public $pre_commission_amount;
/**
* 失效回退金额
**/
public $refund_amount;
/**
* 失效回退红包个数
**/
public $refund_num;
/**
* 解冻金额
**/
public $unfreeze_amount;
/**
* 解冻红包个数
**/
public $unfreeze_num;
/**
* 红包核销金额
**/
public $use_amount;
/**
* 红包核销个数
**/
public $use_num;
/**
* 红包领取金额
**/
public $win_amount;
/**
* 红包领取个数
**/
public $win_num;
}
?>

@ -0,0 +1,70 @@
<?php
/**
* 入参的对象
* @author auto create
*/
class TopApiAfOrderOption
{
/**
* pid中的第三段adzoneId
**/
public $adzone_id;
/**
* pageNo
**/
public $page_no;
/**
* pagesize
**/
public $page_size;
/**
* 此参数不再使用,请勿入参
**/
public $punish_status;
/**
* 渠道关系id
**/
public $relation_id;
/**
* pid中的第二段siteId
**/
public $site_id;
/**
* 查询时间跨度不超过30天单位是天
**/
public $span;
/**
* 此参数不再使用,请勿入参
**/
public $special_id;
/**
* 查询开始时间以taoke订单创建时间开始
**/
public $start_time;
/**
* 子订单号
**/
public $tb_trade_id;
/**
* 此参数不再使用,请勿入参
**/
public $tb_trade_parent_id;
/**
* 此参数不再使用,请勿入参
**/
public $violation_type;
}
?>

@ -0,0 +1,40 @@
<?php
/**
* 参数option
* @author auto create
*/
class TopApiRefundRptOption
{
/**
* 1代表渠道关系id2代表会员关系id
**/
public $biz_type;
/**
* pagenumber
**/
public $page_no;
/**
* pagesize
**/
public $page_size;
/**
* 1 表示2方2表示3方0表示不限
**/
public $refund_type;
/**
* 1-维权发起时间2-订单结算时间正向订单3-维权完成时间4-订单创建时间
**/
public $search_type;
/**
* 开始时间
**/
public $start_time;
}
?>

@ -0,0 +1,25 @@
<?php
/**
* results
* @author auto create
*/
class TopDownloadRecordDo
{
/**
* 文件创建时间
**/
public $created;
/**
* 下载链接状态。1:未下载。2:已下载
**/
public $status;
/**
* 下载链接
**/
public $url;
}
?>

@ -0,0 +1,45 @@
<?php
/**
* query
* @author auto create
*/
class TopItemQuery
{
/**
* 页码,必传
**/
public $current_page;
/**
* 一页大小,必传
**/
public $page_size;
/**
* 媒体pid,必传
**/
public $pid;
/**
* 是否包邮,可不传
**/
public $postage;
/**
* 状态预热1正在进行中2,可不传
**/
public $status;
/**
* 淘宝类目id,可不传
**/
public $taobao_category_id;
/**
* 搜索关键词,可不传
**/
public $word;
}
?>

@ -0,0 +1,15 @@
<?php
/**
* 埋点信息
* @author auto create
*/
class Trackparams
{
/**
* empty
**/
public $empty;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 商品信息-商品关联词
* @author auto create
*/
class WordMapData
{
/**
* 链接-商品相关关联词落地页地址
**/
public $url;
/**
* 商品相关的关联词
**/
public $word;
}
?>

@ -0,0 +1,20 @@
<?php
/**
* 有价券信息
* @author auto create
*/
class Youjiacouponinfo
{
/**
* 有价券商品id
**/
public $item_id;
/**
* 商品链接
**/
public $url;
}
?>

@ -0,0 +1,26 @@
<?php
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new TopClient;
$c->appkey = '***********';
$c->secretKey = '*************************';
// $req = new TradeVoucherUploadRequest;
// $req->setFileName("example");
// $req->setFileData("@/Users/xt/Downloads/1.jpg");
// $req->setSellerNick("奥利奥官方旗舰店");
// $req->setBuyerNick("101NufynDYcbjf2cFQD123j8M/mjtyz6RoxQ2OL1c0e/Bcasdfasdasdfasdfas");
// var_dump($c->execute($req));
$req2 = new TradeVoucherUploadRequest;
$req2->setFileName("example");
$myPic = array(
'type' => 'application/octet-stream',
'content' => file_get_contents('/Users/xt/Downloads/1.jpg')
);
$req2->setFileData($myPic);
$req2->setSellerNick("奥利奥官方旗舰店");
$req2->setBuyerNick("101NufynDYcbjf2cFQD123j8M/mjtyz6RoxQ2OL1c0e/Bcasdfasdasdfasdfas");
var_dump($c->execute($req2));
?>

@ -0,0 +1,32 @@
<?php
/**
* TOP API: taobao.appip.get request
*
* @author auto create
* @since 1.0, 2020.08.28
*/
class AppipGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.appip.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,81 @@
<?php
/**
* TOP API: taobao.files.get request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class FilesGetRequest
{
/**
* 搜索结束时间
**/
private $endDate;
/**
* 搜索开始时间
**/
private $startDate;
/**
* 下载链接状态。1:未下载。2:已下载
**/
private $status;
private $apiParas = array();
public function setEndDate($endDate)
{
$this->endDate = $endDate;
$this->apiParas["end_date"] = $endDate;
}
public function getEndDate()
{
return $this->endDate;
}
public function setStartDate($startDate)
{
$this->startDate = $startDate;
$this->apiParas["start_date"] = $startDate;
}
public function getStartDate()
{
return $this->startDate;
}
public function setStatus($status)
{
$this->status = $status;
$this->apiParas["status"] = $status;
}
public function getStatus()
{
return $this->status;
}
public function getApiMethodName()
{
return "taobao.files.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->endDate,"endDate");
RequestCheckUtil::checkNotNull($this->startDate,"startDate");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,32 @@
<?php
/**
* TOP API: taobao.httpdns.get request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class HttpdnsGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.httpdns.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,47 @@
<?php
/**
* TOP API: taobao.ju.items.search request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class JuItemsSearchRequest
{
/**
* query
**/
private $paramTopItemQuery;
private $apiParas = array();
public function setParamTopItemQuery($paramTopItemQuery)
{
$this->paramTopItemQuery = $paramTopItemQuery;
$this->apiParas["param_top_item_query"] = $paramTopItemQuery;
}
public function getParamTopItemQuery()
{
return $this->paramTopItemQuery;
}
public function getApiMethodName()
{
return "taobao.ju.items.search";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,85 @@
<?php
/**
* TOP API: taobao.kfc.keyword.search request
*
* @author auto create
* @since 1.0, 2018.07.26
*/
class KfcKeywordSearchRequest
{
/**
* 应用点分为一级应用点、二级应用点。其中一级应用点通常是指某一个系统或产品比如淘宝的商品应用taobao_auction二级应用点是指一级应用点下的具体的分类比如商品标题(title)、商品描述(content)。不同的二级应用可以设置不同关键词。
这里的apply参数是由一级应用点与二级应用点合起来的字符一级应用点+"."+二级应用点如taobao_auction.title。
通常apply参数是不需要传递的。如有特殊需求比如特殊的过滤需求需要自己维护一套自己词库需传递此参数。
**/
private $apply;
/**
* 需要过滤的文本信息
**/
private $content;
/**
* 发布信息的淘宝会员名,可以不传
**/
private $nick;
private $apiParas = array();
public function setApply($apply)
{
$this->apply = $apply;
$this->apiParas["apply"] = $apply;
}
public function getApply()
{
return $this->apply;
}
public function setContent($content)
{
$this->content = $content;
$this->apiParas["content"] = $content;
}
public function getContent()
{
return $this->content;
}
public function setNick($nick)
{
$this->nick = $nick;
$this->apiParas["nick"] = $nick;
}
public function getNick()
{
return $this->nick;
}
public function getApiMethodName()
{
return "taobao.kfc.keyword.search";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->content,"content");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,65 @@
<?php
/**
* TOP API: taobao.openuid.change request
*
* @author auto create
* @since 1.0, 2018.10.26
*/
class OpenuidChangeRequest
{
/**
* openUid
**/
private $openUid;
/**
* 转换到的appkey
**/
private $targetAppKey;
private $apiParas = array();
public function setOpenUid($openUid)
{
$this->openUid = $openUid;
$this->apiParas["open_uid"] = $openUid;
}
public function getOpenUid()
{
return $this->openUid;
}
public function setTargetAppKey($targetAppKey)
{
$this->targetAppKey = $targetAppKey;
$this->apiParas["target_app_key"] = $targetAppKey;
}
public function getTargetAppKey()
{
return $this->targetAppKey;
}
public function getApiMethodName()
{
return "taobao.openuid.change";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->openUid,"openUid");
RequestCheckUtil::checkNotNull($this->targetAppKey,"targetAppKey");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,48 @@
<?php
/**
* TOP API: taobao.openuid.get.bymixnick request
*
* @author auto create
* @since 1.0, 2019.10.21
*/
class OpenuidGetBymixnickRequest
{
/**
* 无线类应用获取到的混淆的nick
**/
private $mixNick;
private $apiParas = array();
public function setMixNick($mixNick)
{
$this->mixNick = $mixNick;
$this->apiParas["mix_nick"] = $mixNick;
}
public function getMixNick()
{
return $this->mixNick;
}
public function getApiMethodName()
{
return "taobao.openuid.get.bymixnick";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->mixNick,"mixNick");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,48 @@
<?php
/**
* TOP API: taobao.openuid.get.bytrade request
*
* @author auto create
* @since 1.0, 2018.10.17
*/
class OpenuidGetBytradeRequest
{
/**
* 订单ID
**/
private $tid;
private $apiParas = array();
public function setTid($tid)
{
$this->tid = $tid;
$this->apiParas["tid"] = $tid;
}
public function getTid()
{
return $this->tid;
}
public function getApiMethodName()
{
return "taobao.openuid.get.bytrade";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->tid,"tid");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,32 @@
<?php
/**
* TOP API: taobao.openuid.get request
*
* @author auto create
* @since 1.0, 2018.10.17
*/
class OpenuidGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.openuid.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,113 @@
<?php
/**
* TOP API: taobao.tbk.activity.info.get request
*
* @author auto create
* @since 1.0, 2020.10.19
*/
class TbkActivityInfoGetRequest
{
/**
* 官方活动会场ID从淘宝客后台“我要推广-活动推广”中获取
**/
private $activityMaterialId;
/**
* mm_xxx_xxx_xxx的第三位
**/
private $adzoneId;
/**
* 渠道关系id
**/
private $relationId;
/**
* mm_xxx_xxx_xxx 仅三方分成场景使用
**/
private $subPid;
/**
* 自定义输入串英文和数字组成长度不能大于12个字符区分不同的推广渠道
**/
private $unionId;
private $apiParas = array();
public function setActivityMaterialId($activityMaterialId)
{
$this->activityMaterialId = $activityMaterialId;
$this->apiParas["activity_material_id"] = $activityMaterialId;
}
public function getActivityMaterialId()
{
return $this->activityMaterialId;
}
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setRelationId($relationId)
{
$this->relationId = $relationId;
$this->apiParas["relation_id"] = $relationId;
}
public function getRelationId()
{
return $this->relationId;
}
public function setSubPid($subPid)
{
$this->subPid = $subPid;
$this->apiParas["sub_pid"] = $subPid;
}
public function getSubPid()
{
return $this->subPid;
}
public function setUnionId($unionId)
{
$this->unionId = $unionId;
$this->apiParas["union_id"] = $unionId;
}
public function getUnionId()
{
return $this->unionId;
}
public function getApiMethodName()
{
return "taobao.tbk.activity.info.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->activityMaterialId,"activityMaterialId");
RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,79 @@
<?php
/**
* TOP API: taobao.tbk.coupon.get request
*
* @author auto create
* @since 1.0, 2020.10.08
*/
class TbkCouponGetRequest
{
/**
* 券ID
**/
private $activityId;
/**
* 商品ID
**/
private $itemId;
/**
* 带券ID与商品ID的加密串
**/
private $me;
private $apiParas = array();
public function setActivityId($activityId)
{
$this->activityId = $activityId;
$this->apiParas["activity_id"] = $activityId;
}
public function getActivityId()
{
return $this->activityId;
}
public function setItemId($itemId)
{
$this->itemId = $itemId;
$this->apiParas["item_id"] = $itemId;
}
public function getItemId()
{
return $this->itemId;
}
public function setMe($me)
{
$this->me = $me;
$this->apiParas["me"] = $me;
}
public function getMe()
{
return $this->me;
}
public function getApiMethodName()
{
return "taobao.tbk.coupon.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,625 @@
<?php
/**
* TOP API: taobao.tbk.dg.material.optional request
*
* @author auto create
* @since 1.0, 2020.11.03
*/
class TbkDgMaterialOptionalRequest
{
/**
* mm_xxx_xxx_12345678三段式的最后一段数字
**/
private $adzoneId;
/**
* 商品筛选-后台类目ID。用,分割最大10个该ID可以通过taobao.itemcats.get接口获取到
**/
private $cat;
/**
* 本地化业务入参-LBS信息-国标城市码,仅支持单个请求,请求饿了么卡券物料时,该字段必填。 详细城市ID见https://mo.m.taobao.com/page_2020010315120200508
**/
private $cityCode;
/**
* 智能匹配-设备号加密类型MD5
**/
private $deviceEncrypt;
/**
* 智能匹配-设备号类型IMEI或者IDFA或者UTDIDUTDID不支持MD5加密或者OAID
**/
private $deviceType;
/**
* 智能匹配-设备号加密后的值MD5加密需32位小写
**/
private $deviceValue;
/**
* 商品筛选-KA媒体淘客佣金比率上限。如1234表示12.34%
**/
private $endKaTkRate;
/**
* 商品筛选-折扣价范围上限。单位:元
**/
private $endPrice;
/**
* 商品筛选-淘客佣金比率上限。如1234表示12.34%
**/
private $endTkRate;
/**
* 优惠券筛选-是否有优惠券。true表示该商品有优惠券false或不设置表示不限
**/
private $hasCoupon;
/**
* 商品筛选-好评率是否高于行业均值。True表示大于等于false或不设置表示不限
**/
private $includeGoodRate;
/**
* 商品筛选(特定媒体支持)-成交转化是否高于行业均值。True表示大于等于false或不设置表示不限
**/
private $includePayRate30;
/**
* 商品筛选(特定媒体支持)-退款率是否低于行业均值。True表示大于等于false或不设置表示不限
**/
private $includeRfdRate;
/**
* ip参数影响邮费获取如果不传或者传入不准确邮费无法精准提供
**/
private $ip;
/**
* 商品筛选-是否海外商品。true表示属于海外商品false或不设置表示不限
**/
private $isOverseas;
/**
* 商品筛选-是否天猫商品。true表示属于天猫商品false或不设置表示不限
**/
private $isTmall;
/**
* 商品筛选-所在地
**/
private $itemloc;
/**
* 本地化业务入参-LBS信息-纬度
**/
private $latitude;
/**
* 锁佣结束时间
**/
private $lockRateEndTime;
/**
* 锁佣开始时间
**/
private $lockRateStartTime;
/**
* 本地化业务入参-LBS信息-经度
**/
private $longitude;
/**
* 不传时默认物料id=2836如果直接对消费者投放可使用官方个性化算法优化的搜索物料id=17004
**/
private $materialId;
/**
* 商品筛选-是否包邮。true表示包邮false或不设置表示不限
**/
private $needFreeShipment;
/**
* 商品筛选-是否加入消费者保障。true表示加入false或不设置表示不限
**/
private $needPrepay;
/**
* 商品筛选-牛皮癣程度。取值1不限2无3轻微
**/
private $npxLevel;
/**
* 第几页,默认:1
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
/**
* 链接形式1PC2无线默认
**/
private $platform;
/**
* 商品筛选-查询词
**/
private $q;
/**
* 渠道关系ID仅适用于渠道推广场景
**/
private $relationId;
/**
* 商家id仅支持饿了么卡券商家ID支持批量请求1-100以内多个商家ID使用英文逗号分隔
**/
private $sellerIds;
/**
* 排序_des降序排序_asc升序销量total_sales淘客佣金比率tk_rate 累计推广量tk_total_sales总支出佣金tk_total_commi价格price
**/
private $sort;
/**
* 会员运营ID
**/
private $specialId;
/**
* 商品筛选(特定媒体支持)-店铺dsr评分。筛选大于等于当前设置的店铺dsr评分的商品0-50000之间
**/
private $startDsr;
/**
* 商品筛选-KA媒体淘客佣金比率下限。如1234表示12.34%
**/
private $startKaTkRate;
/**
* 商品筛选-折扣价范围下限。单位:元
**/
private $startPrice;
/**
* 商品筛选-淘客佣金比率下限。如1234表示12.34%
**/
private $startTkRate;
private $apiParas = array();
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setCat($cat)
{
$this->cat = $cat;
$this->apiParas["cat"] = $cat;
}
public function getCat()
{
return $this->cat;
}
public function setCityCode($cityCode)
{
$this->cityCode = $cityCode;
$this->apiParas["city_code"] = $cityCode;
}
public function getCityCode()
{
return $this->cityCode;
}
public function setDeviceEncrypt($deviceEncrypt)
{
$this->deviceEncrypt = $deviceEncrypt;
$this->apiParas["device_encrypt"] = $deviceEncrypt;
}
public function getDeviceEncrypt()
{
return $this->deviceEncrypt;
}
public function setDeviceType($deviceType)
{
$this->deviceType = $deviceType;
$this->apiParas["device_type"] = $deviceType;
}
public function getDeviceType()
{
return $this->deviceType;
}
public function setDeviceValue($deviceValue)
{
$this->deviceValue = $deviceValue;
$this->apiParas["device_value"] = $deviceValue;
}
public function getDeviceValue()
{
return $this->deviceValue;
}
public function setEndKaTkRate($endKaTkRate)
{
$this->endKaTkRate = $endKaTkRate;
$this->apiParas["end_ka_tk_rate"] = $endKaTkRate;
}
public function getEndKaTkRate()
{
return $this->endKaTkRate;
}
public function setEndPrice($endPrice)
{
$this->endPrice = $endPrice;
$this->apiParas["end_price"] = $endPrice;
}
public function getEndPrice()
{
return $this->endPrice;
}
public function setEndTkRate($endTkRate)
{
$this->endTkRate = $endTkRate;
$this->apiParas["end_tk_rate"] = $endTkRate;
}
public function getEndTkRate()
{
return $this->endTkRate;
}
public function setHasCoupon($hasCoupon)
{
$this->hasCoupon = $hasCoupon;
$this->apiParas["has_coupon"] = $hasCoupon;
}
public function getHasCoupon()
{
return $this->hasCoupon;
}
public function setIncludeGoodRate($includeGoodRate)
{
$this->includeGoodRate = $includeGoodRate;
$this->apiParas["include_good_rate"] = $includeGoodRate;
}
public function getIncludeGoodRate()
{
return $this->includeGoodRate;
}
public function setIncludePayRate30($includePayRate30)
{
$this->includePayRate30 = $includePayRate30;
$this->apiParas["include_pay_rate_30"] = $includePayRate30;
}
public function getIncludePayRate30()
{
return $this->includePayRate30;
}
public function setIncludeRfdRate($includeRfdRate)
{
$this->includeRfdRate = $includeRfdRate;
$this->apiParas["include_rfd_rate"] = $includeRfdRate;
}
public function getIncludeRfdRate()
{
return $this->includeRfdRate;
}
public function setIp($ip)
{
$this->ip = $ip;
$this->apiParas["ip"] = $ip;
}
public function getIp()
{
return $this->ip;
}
public function setIsOverseas($isOverseas)
{
$this->isOverseas = $isOverseas;
$this->apiParas["is_overseas"] = $isOverseas;
}
public function getIsOverseas()
{
return $this->isOverseas;
}
public function setIsTmall($isTmall)
{
$this->isTmall = $isTmall;
$this->apiParas["is_tmall"] = $isTmall;
}
public function getIsTmall()
{
return $this->isTmall;
}
public function setItemloc($itemloc)
{
$this->itemloc = $itemloc;
$this->apiParas["itemloc"] = $itemloc;
}
public function getItemloc()
{
return $this->itemloc;
}
public function setLatitude($latitude)
{
$this->latitude = $latitude;
$this->apiParas["latitude"] = $latitude;
}
public function getLatitude()
{
return $this->latitude;
}
public function setLockRateEndTime($lockRateEndTime)
{
$this->lockRateEndTime = $lockRateEndTime;
$this->apiParas["lock_rate_end_time"] = $lockRateEndTime;
}
public function getLockRateEndTime()
{
return $this->lockRateEndTime;
}
public function setLockRateStartTime($lockRateStartTime)
{
$this->lockRateStartTime = $lockRateStartTime;
$this->apiParas["lock_rate_start_time"] = $lockRateStartTime;
}
public function getLockRateStartTime()
{
return $this->lockRateStartTime;
}
public function setLongitude($longitude)
{
$this->longitude = $longitude;
$this->apiParas["longitude"] = $longitude;
}
public function getLongitude()
{
return $this->longitude;
}
public function setMaterialId($materialId)
{
$this->materialId = $materialId;
$this->apiParas["material_id"] = $materialId;
}
public function getMaterialId()
{
return $this->materialId;
}
public function setNeedFreeShipment($needFreeShipment)
{
$this->needFreeShipment = $needFreeShipment;
$this->apiParas["need_free_shipment"] = $needFreeShipment;
}
public function getNeedFreeShipment()
{
return $this->needFreeShipment;
}
public function setNeedPrepay($needPrepay)
{
$this->needPrepay = $needPrepay;
$this->apiParas["need_prepay"] = $needPrepay;
}
public function getNeedPrepay()
{
return $this->needPrepay;
}
public function setNpxLevel($npxLevel)
{
$this->npxLevel = $npxLevel;
$this->apiParas["npx_level"] = $npxLevel;
}
public function getNpxLevel()
{
return $this->npxLevel;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setPlatform($platform)
{
$this->platform = $platform;
$this->apiParas["platform"] = $platform;
}
public function getPlatform()
{
return $this->platform;
}
public function setQ($q)
{
$this->q = $q;
$this->apiParas["q"] = $q;
}
public function getQ()
{
return $this->q;
}
public function setRelationId($relationId)
{
$this->relationId = $relationId;
$this->apiParas["relation_id"] = $relationId;
}
public function getRelationId()
{
return $this->relationId;
}
public function setSellerIds($sellerIds)
{
$this->sellerIds = $sellerIds;
$this->apiParas["seller_ids"] = $sellerIds;
}
public function getSellerIds()
{
return $this->sellerIds;
}
public function setSort($sort)
{
$this->sort = $sort;
$this->apiParas["sort"] = $sort;
}
public function getSort()
{
return $this->sort;
}
public function setSpecialId($specialId)
{
$this->specialId = $specialId;
$this->apiParas["special_id"] = $specialId;
}
public function getSpecialId()
{
return $this->specialId;
}
public function setStartDsr($startDsr)
{
$this->startDsr = $startDsr;
$this->apiParas["start_dsr"] = $startDsr;
}
public function getStartDsr()
{
return $this->startDsr;
}
public function setStartKaTkRate($startKaTkRate)
{
$this->startKaTkRate = $startKaTkRate;
$this->apiParas["start_ka_tk_rate"] = $startKaTkRate;
}
public function getStartKaTkRate()
{
return $this->startKaTkRate;
}
public function setStartPrice($startPrice)
{
$this->startPrice = $startPrice;
$this->apiParas["start_price"] = $startPrice;
}
public function getStartPrice()
{
return $this->startPrice;
}
public function setStartTkRate($startTkRate)
{
$this->startTkRate = $startTkRate;
$this->apiParas["start_tk_rate"] = $startTkRate;
}
public function getStartTkRate()
{
return $this->startTkRate;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.material.optional";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId");
RequestCheckUtil::checkMaxValue($this->startDsr,50000,"startDsr");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,130 @@
<?php
/**
* TOP API: taobao.tbk.dg.newuser.order.get request
*
* @author auto create
* @since 1.0, 2019.07.04
*/
class TbkDgNewuserOrderGetRequest
{
/**
* 活动id 活动名称与活动ID列表请参见https://tbk.bbs.taobao.com/detail.html?appId=45301&postId=8599277
**/
private $activityId;
/**
* mm_xxx_xxx_xxx的第三位
**/
private $adzoneId;
/**
* 结束时间,当活动为淘宝活动,表示最晚结束时间;当活动为支付宝活动,表示最晚绑定时间;当活动为天猫活动,表示最晚领取红包的时间
**/
private $endTime;
/**
* 页码默认1
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
/**
* 开始时间,当活动为淘宝活动,表示最早注册时间;当活动为支付宝活动,表示最早绑定时间;当活动为天猫活动,表示最早领取红包时间
**/
private $startTime;
private $apiParas = array();
public function setActivityId($activityId)
{
$this->activityId = $activityId;
$this->apiParas["activity_id"] = $activityId;
}
public function getActivityId()
{
return $this->activityId;
}
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setEndTime($endTime)
{
$this->endTime = $endTime;
$this->apiParas["end_time"] = $endTime;
}
public function getEndTime()
{
return $this->endTime;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setStartTime($startTime)
{
$this->startTime = $startTime;
$this->apiParas["start_time"] = $startTime;
}
public function getStartTime()
{
return $this->startTime;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.newuser.order.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->activityId,"activityId");
RequestCheckUtil::checkMaxValue($this->pageSize,100,"pageSize");
RequestCheckUtil::checkMinValue($this->pageSize,1,"pageSize");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,132 @@
<?php
/**
* TOP API: taobao.tbk.dg.newuser.order.sum request
*
* @author auto create
* @since 1.0, 2019.07.04
*/
class TbkDgNewuserOrderSumRequest
{
/**
* 活动id 活动名称与活动ID列表请参见https://tbk.bbs.taobao.com/detail.html?appId=45301&postId=8599277
**/
private $activityId;
/**
* mm_xxx_xxx_xxx的第三位
**/
private $adzoneId;
/**
* 页码默认1
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
/**
* 结算月份
**/
private $settleMonth;
/**
* mm_xxx_xxx_xxx的第二位
**/
private $siteId;
private $apiParas = array();
public function setActivityId($activityId)
{
$this->activityId = $activityId;
$this->apiParas["activity_id"] = $activityId;
}
public function getActivityId()
{
return $this->activityId;
}
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setSettleMonth($settleMonth)
{
$this->settleMonth = $settleMonth;
$this->apiParas["settle_month"] = $settleMonth;
}
public function getSettleMonth()
{
return $this->settleMonth;
}
public function setSiteId($siteId)
{
$this->siteId = $siteId;
$this->apiParas["site_id"] = $siteId;
}
public function getSiteId()
{
return $this->siteId;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.newuser.order.sum";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->activityId,"activityId");
RequestCheckUtil::checkNotNull($this->pageNo,"pageNo");
RequestCheckUtil::checkNotNull($this->pageSize,"pageSize");
RequestCheckUtil::checkMaxValue($this->pageSize,100,"pageSize");
RequestCheckUtil::checkMinValue($this->pageSize,1,"pageSize");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,211 @@
<?php
/**
* TOP API: taobao.tbk.dg.optimus.material request
*
* @author auto create
* @since 1.0, 2020.10.26
*/
class TbkDgOptimusMaterialRequest
{
/**
* mm_xxx_xxx_xxx的第三位
**/
private $adzoneId;
/**
* 内容专用-内容详情ID
**/
private $contentId;
/**
* 内容专用-内容渠道信息
**/
private $contentSource;
/**
* 智能匹配-设备号加密类型MD5类型为OAID时不传
**/
private $deviceEncrypt;
/**
* 智能匹配-设备号类型IMEI或者IDFA或者UTDIDUTDID不支持MD5加密或者OAID
**/
private $deviceType;
/**
* 智能匹配-设备号加密后的值MD5加密需32位小写类型为OAID时传原始OAID值
**/
private $deviceValue;
/**
* 选品库投放id
**/
private $favoritesId;
/**
* 商品ID用于相似商品推荐
**/
private $itemId;
/**
* 官方的物料Id(详细物料id见https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a)
**/
private $materialId;
/**
* 第几页默认1
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
private $apiParas = array();
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setContentId($contentId)
{
$this->contentId = $contentId;
$this->apiParas["content_id"] = $contentId;
}
public function getContentId()
{
return $this->contentId;
}
public function setContentSource($contentSource)
{
$this->contentSource = $contentSource;
$this->apiParas["content_source"] = $contentSource;
}
public function getContentSource()
{
return $this->contentSource;
}
public function setDeviceEncrypt($deviceEncrypt)
{
$this->deviceEncrypt = $deviceEncrypt;
$this->apiParas["device_encrypt"] = $deviceEncrypt;
}
public function getDeviceEncrypt()
{
return $this->deviceEncrypt;
}
public function setDeviceType($deviceType)
{
$this->deviceType = $deviceType;
$this->apiParas["device_type"] = $deviceType;
}
public function getDeviceType()
{
return $this->deviceType;
}
public function setDeviceValue($deviceValue)
{
$this->deviceValue = $deviceValue;
$this->apiParas["device_value"] = $deviceValue;
}
public function getDeviceValue()
{
return $this->deviceValue;
}
public function setFavoritesId($favoritesId)
{
$this->favoritesId = $favoritesId;
$this->apiParas["favorites_id"] = $favoritesId;
}
public function getFavoritesId()
{
return $this->favoritesId;
}
public function setItemId($itemId)
{
$this->itemId = $itemId;
$this->apiParas["item_id"] = $itemId;
}
public function getItemId()
{
return $this->itemId;
}
public function setMaterialId($materialId)
{
$this->materialId = $materialId;
$this->apiParas["material_id"] = $materialId;
}
public function getMaterialId()
{
return $this->materialId;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.optimus.material";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId");
RequestCheckUtil::checkNotNull($this->materialId,"materialId");
RequestCheckUtil::checkMaxValue($this->pageSize,100,"pageSize");
RequestCheckUtil::checkMinValue($this->pageSize,1,"pageSize");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,98 @@
<?php
/**
* TOP API: taobao.tbk.dg.optimus.promotion request
*
* @author auto create
* @since 1.0, 2020.10.27
*/
class TbkDgOptimusPromotionRequest
{
/**
* mm_xxx_xxx_xxx的第3段数字
**/
private $adzoneId;
/**
* 第几页默认1
**/
private $pageNum;
/**
* 页大小一次请求请限制在10以内
**/
private $pageSize;
/**
* 官方提供的权益物料Id。有价券-37104、大额店铺券-37116更多权益物料id敬请期待
**/
private $promotionId;
private $apiParas = array();
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setPageNum($pageNum)
{
$this->pageNum = $pageNum;
$this->apiParas["page_num"] = $pageNum;
}
public function getPageNum()
{
return $this->pageNum;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setPromotionId($promotionId)
{
$this->promotionId = $promotionId;
$this->apiParas["promotion_id"] = $promotionId;
}
public function getPromotionId()
{
return $this->promotionId;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.optimus.promotion";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId");
RequestCheckUtil::checkMaxValue($this->pageSize,10,"pageSize");
RequestCheckUtil::checkNotNull($this->promotionId,"promotionId");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,47 @@
<?php
/**
* TOP API: taobao.tbk.dg.punish.order.get request
*
* @author auto create
* @since 1.0, 2019.11.10
*/
class TbkDgPunishOrderGetRequest
{
/**
* 入参的对象
**/
private $afOrderOption;
private $apiParas = array();
public function setAfOrderOption($afOrderOption)
{
$this->afOrderOption = $afOrderOption;
$this->apiParas["af_order_option"] = $afOrderOption;
}
public function getAfOrderOption()
{
return $this->afOrderOption;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.punish.order.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,113 @@
<?php
/**
* TOP API: taobao.tbk.dg.vegas.send.report request
*
* @author auto create
* @since 1.0, 2020.10.20
*/
class TbkDgVegasSendReportRequest
{
/**
* 2020双11大促活动id1306
**/
private $activityId;
/**
* 统计日期
**/
private $bizDate;
/**
* 页码
**/
private $pageNo;
/**
* 每页大小
**/
private $pageSize;
/**
* 渠道关系id
**/
private $relationId;
private $apiParas = array();
public function setActivityId($activityId)
{
$this->activityId = $activityId;
$this->apiParas["activity_id"] = $activityId;
}
public function getActivityId()
{
return $this->activityId;
}
public function setBizDate($bizDate)
{
$this->bizDate = $bizDate;
$this->apiParas["biz_date"] = $bizDate;
}
public function getBizDate()
{
return $this->bizDate;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setRelationId($relationId)
{
$this->relationId = $relationId;
$this->apiParas["relation_id"] = $relationId;
}
public function getRelationId()
{
return $this->relationId;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.vegas.send.report";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->activityId,"activityId");
RequestCheckUtil::checkNotNull($this->bizDate,"bizDate");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,263 @@
<?php
/**
* TOP API: taobao.tbk.dg.vegas.tlj.create request
*
* @author auto create
* @since 1.0, 2020.08.18
*/
class TbkDgVegasTljCreateRequest
{
/**
* 妈妈广告位Id
**/
private $adzoneId;
/**
* CPS佣金计划类型
**/
private $campaignType;
/**
* 宝贝id
**/
private $itemId;
/**
* 淘礼金名称最大10个字符
**/
private $name;
/**
* 单个淘礼金面额,支持两位小数,单位元
**/
private $perFace;
/**
* 安全等级0适用于常规淘礼金投放场景1更高安全级别适用于淘礼金面额偏大等安全性较高的淘礼金投放场景可能导致更多用户拦截。security_switch为true此字段不填写时使用0作为默认安全级别。如果security_switch为false不进行安全判断。
**/
private $securityLevel;
/**
* 安全开关,若不进行安全校验,可能放大您的资损风险,请谨慎选择
**/
private $securitySwitch;
/**
* 发放截止时间
**/
private $sendEndTime;
/**
* 发放开始时间
**/
private $sendStartTime;
/**
* 淘礼金总个数
**/
private $totalNum;
/**
* 使用结束日期。如果是结束时间模式为相对时间时间格式为1-7直接的整数, 例如1相对领取时间1天 如果是绝对时间格式为yyyy-MM-dd例如2019-01-29表示到2019-01-29 23:59:59结束
**/
private $useEndTime;
/**
* 结束日期的模式,1:相对时间2:绝对时间
**/
private $useEndTimeMode;
/**
* 使用开始日期。相对时间,无需填写,以用户领取时间作为使用开始时间。绝对时间,格式 yyyy-MM-dd例如2019-01-29表示从2019-01-29 00:00:00 开始
**/
private $useStartTime;
/**
* 单用户累计中奖次数上限
**/
private $userTotalWinNumLimit;
private $apiParas = array();
public function setAdzoneId($adzoneId)
{
$this->adzoneId = $adzoneId;
$this->apiParas["adzone_id"] = $adzoneId;
}
public function getAdzoneId()
{
return $this->adzoneId;
}
public function setCampaignType($campaignType)
{
$this->campaignType = $campaignType;
$this->apiParas["campaign_type"] = $campaignType;
}
public function getCampaignType()
{
return $this->campaignType;
}
public function setItemId($itemId)
{
$this->itemId = $itemId;
$this->apiParas["item_id"] = $itemId;
}
public function getItemId()
{
return $this->itemId;
}
public function setName($name)
{
$this->name = $name;
$this->apiParas["name"] = $name;
}
public function getName()
{
return $this->name;
}
public function setPerFace($perFace)
{
$this->perFace = $perFace;
$this->apiParas["per_face"] = $perFace;
}
public function getPerFace()
{
return $this->perFace;
}
public function setSecurityLevel($securityLevel)
{
$this->securityLevel = $securityLevel;
$this->apiParas["security_level"] = $securityLevel;
}
public function getSecurityLevel()
{
return $this->securityLevel;
}
public function setSecuritySwitch($securitySwitch)
{
$this->securitySwitch = $securitySwitch;
$this->apiParas["security_switch"] = $securitySwitch;
}
public function getSecuritySwitch()
{
return $this->securitySwitch;
}
public function setSendEndTime($sendEndTime)
{
$this->sendEndTime = $sendEndTime;
$this->apiParas["send_end_time"] = $sendEndTime;
}
public function getSendEndTime()
{
return $this->sendEndTime;
}
public function setSendStartTime($sendStartTime)
{
$this->sendStartTime = $sendStartTime;
$this->apiParas["send_start_time"] = $sendStartTime;
}
public function getSendStartTime()
{
return $this->sendStartTime;
}
public function setTotalNum($totalNum)
{
$this->totalNum = $totalNum;
$this->apiParas["total_num"] = $totalNum;
}
public function getTotalNum()
{
return $this->totalNum;
}
public function setUseEndTime($useEndTime)
{
$this->useEndTime = $useEndTime;
$this->apiParas["use_end_time"] = $useEndTime;
}
public function getUseEndTime()
{
return $this->useEndTime;
}
public function setUseEndTimeMode($useEndTimeMode)
{
$this->useEndTimeMode = $useEndTimeMode;
$this->apiParas["use_end_time_mode"] = $useEndTimeMode;
}
public function getUseEndTimeMode()
{
return $this->useEndTimeMode;
}
public function setUseStartTime($useStartTime)
{
$this->useStartTime = $useStartTime;
$this->apiParas["use_start_time"] = $useStartTime;
}
public function getUseStartTime()
{
return $this->useStartTime;
}
public function setUserTotalWinNumLimit($userTotalWinNumLimit)
{
$this->userTotalWinNumLimit = $userTotalWinNumLimit;
$this->apiParas["user_total_win_num_limit"] = $userTotalWinNumLimit;
}
public function getUserTotalWinNumLimit()
{
return $this->userTotalWinNumLimit;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.vegas.tlj.create";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId");
RequestCheckUtil::checkNotNull($this->itemId,"itemId");
RequestCheckUtil::checkNotNull($this->name,"name");
RequestCheckUtil::checkNotNull($this->perFace,"perFace");
RequestCheckUtil::checkNotNull($this->securitySwitch,"securitySwitch");
RequestCheckUtil::checkNotNull($this->sendStartTime,"sendStartTime");
RequestCheckUtil::checkNotNull($this->totalNum,"totalNum");
RequestCheckUtil::checkNotNull($this->userTotalWinNumLimit,"userTotalWinNumLimit");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,48 @@
<?php
/**
* TOP API: taobao.tbk.dg.vegas.tlj.instance.report request
*
* @author auto create
* @since 1.0, 2020.07.09
*/
class TbkDgVegasTljInstanceReportRequest
{
/**
* 实例ID
**/
private $rightsId;
private $apiParas = array();
public function setRightsId($rightsId)
{
$this->rightsId = $rightsId;
$this->apiParas["rights_id"] = $rightsId;
}
public function getRightsId()
{
return $this->rightsId;
}
public function getApiMethodName()
{
return "taobao.tbk.dg.vegas.tlj.instance.report";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->rightsId,"rightsId");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,80 @@
<?php
/**
* TOP API: taobao.tbk.item.info.get request
*
* @author auto create
* @since 1.0, 2020.10.19
*/
class TbkItemInfoGetRequest
{
/**
* ip地址影响邮费获取如果不传或者传入不准确邮费无法精准提供
**/
private $ip;
/**
* 商品ID串用,分割最大40个
**/
private $numIids;
/**
* 链接形式1PC2无线默认
**/
private $platform;
private $apiParas = array();
public function setIp($ip)
{
$this->ip = $ip;
$this->apiParas["ip"] = $ip;
}
public function getIp()
{
return $this->ip;
}
public function setNumIids($numIids)
{
$this->numIids = $numIids;
$this->apiParas["num_iids"] = $numIids;
}
public function getNumIids()
{
return $this->numIids;
}
public function setPlatform($platform)
{
$this->platform = $platform;
$this->apiParas["platform"] = $platform;
}
public function getPlatform()
{
return $this->platform;
}
public function getApiMethodName()
{
return "taobao.tbk.item.info.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->numIids,"numIids");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,193 @@
<?php
/**
* TOP API: taobao.tbk.order.details.get request
*
* @author auto create
* @since 1.0, 2020.10.27
*/
class TbkOrderDetailsGetRequest
{
/**
* 订单查询结束时间订单开始时间至订单结束时间中间时间段日常要求不超过3个小时但如618、双11、年货节等大促期间预估时间段不可超过20分钟超过会提示错误调用时请务必注意时间段的选择以保证亲能正常调用
**/
private $endTime;
/**
* 跳转类型,当向前或者向后翻页必须提供,-1: 向前翻页,1向后翻页
**/
private $jumpType;
/**
* 推广者角色类型,2:二方3:三方,不传,表示所有角色
**/
private $memberType;
/**
* 场景订单场景类型1:常规订单2:渠道订单3:会员运营订单默认为1
**/
private $orderScene;
/**
* 第几页默认11~100
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
/**
* 位点,除第一页之外,都需要传递;前端原样返回。
**/
private $positionIndex;
/**
* 查询时间类型1按照订单淘客创建时间查询2:按照订单淘客付款时间查询3:按照订单淘客结算时间查询
**/
private $queryType;
/**
* 订单查询开始时间
**/
private $startTime;
/**
* 淘客订单状态12-付款13-关闭14-确认收货3-结算成功;不传,表示所有状态
**/
private $tkStatus;
private $apiParas = array();
public function setEndTime($endTime)
{
$this->endTime = $endTime;
$this->apiParas["end_time"] = $endTime;
}
public function getEndTime()
{
return $this->endTime;
}
public function setJumpType($jumpType)
{
$this->jumpType = $jumpType;
$this->apiParas["jump_type"] = $jumpType;
}
public function getJumpType()
{
return $this->jumpType;
}
public function setMemberType($memberType)
{
$this->memberType = $memberType;
$this->apiParas["member_type"] = $memberType;
}
public function getMemberType()
{
return $this->memberType;
}
public function setOrderScene($orderScene)
{
$this->orderScene = $orderScene;
$this->apiParas["order_scene"] = $orderScene;
}
public function getOrderScene()
{
return $this->orderScene;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setPositionIndex($positionIndex)
{
$this->positionIndex = $positionIndex;
$this->apiParas["position_index"] = $positionIndex;
}
public function getPositionIndex()
{
return $this->positionIndex;
}
public function setQueryType($queryType)
{
$this->queryType = $queryType;
$this->apiParas["query_type"] = $queryType;
}
public function getQueryType()
{
return $this->queryType;
}
public function setStartTime($startTime)
{
$this->startTime = $startTime;
$this->apiParas["start_time"] = $startTime;
}
public function getStartTime()
{
return $this->startTime;
}
public function setTkStatus($tkStatus)
{
$this->tkStatus = $tkStatus;
$this->apiParas["tk_status"] = $tkStatus;
}
public function getTkStatus()
{
return $this->tkStatus;
}
public function getApiMethodName()
{
return "taobao.tbk.order.details.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->endTime,"endTime");
RequestCheckUtil::checkNotNull($this->startTime,"startTime");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,47 @@
<?php
/**
* TOP API: taobao.tbk.relation.refund request
*
* @author auto create
* @since 1.0, 2020.03.23
*/
class TbkRelationRefundRequest
{
/**
* 参数option
**/
private $searchOption;
private $apiParas = array();
public function setSearchOption($searchOption)
{
$this->searchOption = $searchOption;
$this->apiParas["search_option"] = $searchOption;
}
public function getSearchOption()
{
return $this->searchOption;
}
public function getApiMethodName()
{
return "taobao.tbk.relation.refund";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,81 @@
<?php
/**
* TOP API: taobao.tbk.sc.invitecode.get request
*
* @author auto create
* @since 1.0, 2020.10.30
*/
class TbkScInvitecodeGetRequest
{
/**
* 邀请码类型1 - 渠道邀请2 - 渠道裂变3 -会员邀请
**/
private $codeType;
/**
* 渠道推广的物料类型
**/
private $relationApp;
/**
* 渠道关系ID
**/
private $relationId;
private $apiParas = array();
public function setCodeType($codeType)
{
$this->codeType = $codeType;
$this->apiParas["code_type"] = $codeType;
}
public function getCodeType()
{
return $this->codeType;
}
public function setRelationApp($relationApp)
{
$this->relationApp = $relationApp;
$this->apiParas["relation_app"] = $relationApp;
}
public function getRelationApp()
{
return $this->relationApp;
}
public function setRelationId($relationId)
{
$this->relationId = $relationId;
$this->apiParas["relation_id"] = $relationId;
}
public function getRelationId()
{
return $this->relationId;
}
public function getApiMethodName()
{
return "taobao.tbk.sc.invitecode.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->codeType,"codeType");
RequestCheckUtil::checkNotNull($this->relationApp,"relationApp");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,145 @@
<?php
/**
* TOP API: taobao.tbk.sc.publisher.info.get request
*
* @author auto create
* @since 1.0, 2020.10.30
*/
class TbkScPublisherInfoGetRequest
{
/**
* 淘宝客外部用户标记如自身系统账户ID微信ID等
**/
private $externalId;
/**
* 类型,必选 1:渠道信息2:会员信息
**/
private $infoType;
/**
* 第几页
**/
private $pageNo;
/**
* 每页大小
**/
private $pageSize;
/**
* 备案的场景common通用备案etao一淘备案minietao一淘小程序备案offlineShop线下门店备案offlinePerson线下个人备案。如不填默认common。查询会员信息只需填写common即可
**/
private $relationApp;
/**
* 渠道独占 - 渠道关系ID
**/
private $relationId;
/**
* 会员独占 - 会员运营ID
**/
private $specialId;
private $apiParas = array();
public function setExternalId($externalId)
{
$this->externalId = $externalId;
$this->apiParas["external_id"] = $externalId;
}
public function getExternalId()
{
return $this->externalId;
}
public function setInfoType($infoType)
{
$this->infoType = $infoType;
$this->apiParas["info_type"] = $infoType;
}
public function getInfoType()
{
return $this->infoType;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setRelationApp($relationApp)
{
$this->relationApp = $relationApp;
$this->apiParas["relation_app"] = $relationApp;
}
public function getRelationApp()
{
return $this->relationApp;
}
public function setRelationId($relationId)
{
$this->relationId = $relationId;
$this->apiParas["relation_id"] = $relationId;
}
public function getRelationId()
{
return $this->relationId;
}
public function setSpecialId($specialId)
{
$this->specialId = $specialId;
$this->apiParas["special_id"] = $specialId;
}
public function getSpecialId()
{
return $this->specialId;
}
public function getApiMethodName()
{
return "taobao.tbk.sc.publisher.info.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->infoType,"infoType");
RequestCheckUtil::checkNotNull($this->relationApp,"relationApp");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,145 @@
<?php
/**
* TOP API: taobao.tbk.sc.publisher.info.save request
*
* @author auto create
* @since 1.0, 2020.10.30
*/
class TbkScPublisherInfoSaveRequest
{
/**
* 类型,必选 默认为1:
**/
private $infoType;
/**
* 淘宝客邀请渠道或会员的邀请码
**/
private $inviterCode;
/**
* 媒体侧渠道备注
**/
private $note;
/**
* 渠道备案 - 线下场景信息1 - 门店2- 学校3 - 工厂4 - 其他
**/
private $offlineScene;
/**
* 渠道备案 - 线上场景信息1 - 微信群2- QQ群3 - 其他
**/
private $onlineScene;
/**
* 线下备案注册信息,字段包含: 电话号码(phoneNumber必填),省(province,必填),市(city,必填),区县街道(location,必填),详细地址(detailAddress,必填),经营类型(career,线下个人必填),店铺类型(shopType,线下店铺必填),店铺名称(shopName,线下店铺必填),店铺证书类型(shopCertifyType,线下店铺选填),店铺证书编号(certifyNumber,线下店铺选填)
**/
private $registerInfo;
/**
* 渠道备案 - 来源,取链接的来源
**/
private $relationFrom;
private $apiParas = array();
public function setInfoType($infoType)
{
$this->infoType = $infoType;
$this->apiParas["info_type"] = $infoType;
}
public function getInfoType()
{
return $this->infoType;
}
public function setInviterCode($inviterCode)
{
$this->inviterCode = $inviterCode;
$this->apiParas["inviter_code"] = $inviterCode;
}
public function getInviterCode()
{
return $this->inviterCode;
}
public function setNote($note)
{
$this->note = $note;
$this->apiParas["note"] = $note;
}
public function getNote()
{
return $this->note;
}
public function setOfflineScene($offlineScene)
{
$this->offlineScene = $offlineScene;
$this->apiParas["offline_scene"] = $offlineScene;
}
public function getOfflineScene()
{
return $this->offlineScene;
}
public function setOnlineScene($onlineScene)
{
$this->onlineScene = $onlineScene;
$this->apiParas["online_scene"] = $onlineScene;
}
public function getOnlineScene()
{
return $this->onlineScene;
}
public function setRegisterInfo($registerInfo)
{
$this->registerInfo = $registerInfo;
$this->apiParas["register_info"] = $registerInfo;
}
public function getRegisterInfo()
{
return $this->registerInfo;
}
public function setRelationFrom($relationFrom)
{
$this->relationFrom = $relationFrom;
$this->apiParas["relation_from"] = $relationFrom;
}
public function getRelationFrom()
{
return $this->relationFrom;
}
public function getApiMethodName()
{
return "taobao.tbk.sc.publisher.info.save";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->infoType,"infoType");
RequestCheckUtil::checkNotNull($this->inviterCode,"inviterCode");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,273 @@
<?php
/**
* TOP API: taobao.tbk.shop.get request
*
* @author auto create
* @since 1.0, 2020.02.24
*/
class TbkShopGetRequest
{
/**
* 累计推广商品上限
**/
private $endAuctionCount;
/**
* 淘客佣金比率上限1~10000
**/
private $endCommissionRate;
/**
* 信用等级上限1~20
**/
private $endCredit;
/**
* 店铺商品总数上限
**/
private $endTotalAction;
/**
* 需返回的字段列表
**/
private $fields;
/**
* 是否商城的店铺设置为true表示该是属于淘宝商城的店铺设置为false或不设置表示不判断这个属性
**/
private $isTmall;
/**
* 第几页默认11~100
**/
private $pageNo;
/**
* 页大小默认201~100
**/
private $pageSize;
/**
* 链接形式1PC2无线默认
**/
private $platform;
/**
* 查询词
**/
private $q;
/**
* 排序_des降序排序_asc升序佣金比率commission_rate 商品数量auction_count销售总数量total_auction
**/
private $sort;
/**
* 累计推广商品下限
**/
private $startAuctionCount;
/**
* 淘客佣金比率下限1~10000
**/
private $startCommissionRate;
/**
* 信用等级下限1~20
**/
private $startCredit;
/**
* 店铺商品总数下限
**/
private $startTotalAction;
private $apiParas = array();
public function setEndAuctionCount($endAuctionCount)
{
$this->endAuctionCount = $endAuctionCount;
$this->apiParas["end_auction_count"] = $endAuctionCount;
}
public function getEndAuctionCount()
{
return $this->endAuctionCount;
}
public function setEndCommissionRate($endCommissionRate)
{
$this->endCommissionRate = $endCommissionRate;
$this->apiParas["end_commission_rate"] = $endCommissionRate;
}
public function getEndCommissionRate()
{
return $this->endCommissionRate;
}
public function setEndCredit($endCredit)
{
$this->endCredit = $endCredit;
$this->apiParas["end_credit"] = $endCredit;
}
public function getEndCredit()
{
return $this->endCredit;
}
public function setEndTotalAction($endTotalAction)
{
$this->endTotalAction = $endTotalAction;
$this->apiParas["end_total_action"] = $endTotalAction;
}
public function getEndTotalAction()
{
return $this->endTotalAction;
}
public function setFields($fields)
{
$this->fields = $fields;
$this->apiParas["fields"] = $fields;
}
public function getFields()
{
return $this->fields;
}
public function setIsTmall($isTmall)
{
$this->isTmall = $isTmall;
$this->apiParas["is_tmall"] = $isTmall;
}
public function getIsTmall()
{
return $this->isTmall;
}
public function setPageNo($pageNo)
{
$this->pageNo = $pageNo;
$this->apiParas["page_no"] = $pageNo;
}
public function getPageNo()
{
return $this->pageNo;
}
public function setPageSize($pageSize)
{
$this->pageSize = $pageSize;
$this->apiParas["page_size"] = $pageSize;
}
public function getPageSize()
{
return $this->pageSize;
}
public function setPlatform($platform)
{
$this->platform = $platform;
$this->apiParas["platform"] = $platform;
}
public function getPlatform()
{
return $this->platform;
}
public function setQ($q)
{
$this->q = $q;
$this->apiParas["q"] = $q;
}
public function getQ()
{
return $this->q;
}
public function setSort($sort)
{
$this->sort = $sort;
$this->apiParas["sort"] = $sort;
}
public function getSort()
{
return $this->sort;
}
public function setStartAuctionCount($startAuctionCount)
{
$this->startAuctionCount = $startAuctionCount;
$this->apiParas["start_auction_count"] = $startAuctionCount;
}
public function getStartAuctionCount()
{
return $this->startAuctionCount;
}
public function setStartCommissionRate($startCommissionRate)
{
$this->startCommissionRate = $startCommissionRate;
$this->apiParas["start_commission_rate"] = $startCommissionRate;
}
public function getStartCommissionRate()
{
return $this->startCommissionRate;
}
public function setStartCredit($startCredit)
{
$this->startCredit = $startCredit;
$this->apiParas["start_credit"] = $startCredit;
}
public function getStartCredit()
{
return $this->startCredit;
}
public function setStartTotalAction($startTotalAction)
{
$this->startTotalAction = $startTotalAction;
$this->apiParas["start_total_action"] = $startTotalAction;
}
public function getStartTotalAction()
{
return $this->startTotalAction;
}
public function getApiMethodName()
{
return "taobao.tbk.shop.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->fields,"fields");
RequestCheckUtil::checkNotNull($this->q,"q");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,97 @@
<?php
/**
* TOP API: taobao.tbk.shop.recommend.get request
*
* @author auto create
* @since 1.0, 2020.10.08
*/
class TbkShopRecommendGetRequest
{
/**
* 返回数量默认20最大值40
**/
private $count;
/**
* 需返回的字段列表
**/
private $fields;
/**
* 链接形式1PC2无线默认
**/
private $platform;
/**
* 卖家Id
**/
private $userId;
private $apiParas = array();
public function setCount($count)
{
$this->count = $count;
$this->apiParas["count"] = $count;
}
public function getCount()
{
return $this->count;
}
public function setFields($fields)
{
$this->fields = $fields;
$this->apiParas["fields"] = $fields;
}
public function getFields()
{
return $this->fields;
}
public function setPlatform($platform)
{
$this->platform = $platform;
$this->apiParas["platform"] = $platform;
}
public function getPlatform()
{
return $this->platform;
}
public function setUserId($userId)
{
$this->userId = $userId;
$this->apiParas["user_id"] = $userId;
}
public function getUserId()
{
return $this->userId;
}
public function getApiMethodName()
{
return "taobao.tbk.shop.recommend.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->fields,"fields");
RequestCheckUtil::checkNotNull($this->userId,"userId");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,47 @@
<?php
/**
* TOP API: taobao.tbk.spread.get request
*
* @author auto create
* @since 1.0, 2020.02.24
*/
class TbkSpreadGetRequest
{
/**
* 请求列表内部包含多个url
**/
private $requests;
private $apiParas = array();
public function setRequests($requests)
{
$this->requests = $requests;
$this->apiParas["requests"] = $requests;
}
public function getRequests()
{
return $this->requests;
}
public function getApiMethodName()
{
return "taobao.tbk.spread.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,113 @@
<?php
/**
* TOP API: taobao.tbk.tpwd.create request
*
* @author auto create
* @since 1.0, 2020.10.08
*/
class TbkTpwdCreateRequest
{
/**
* [已废弃]扩展字段JSON格式
**/
private $ext;
/**
* 口令弹框logoURL
**/
private $logo;
/**
* 口令弹框内容
**/
private $text;
/**
* 口令跳转目标页
**/
private $url;
/**
* 生成口令的淘宝用户ID
**/
private $userId;
private $apiParas = array();
public function setExt($ext)
{
$this->ext = $ext;
$this->apiParas["ext"] = $ext;
}
public function getExt()
{
return $this->ext;
}
public function setLogo($logo)
{
$this->logo = $logo;
$this->apiParas["logo"] = $logo;
}
public function getLogo()
{
return $this->logo;
}
public function setText($text)
{
$this->text = $text;
$this->apiParas["text"] = $text;
}
public function getText()
{
return $this->text;
}
public function setUrl($url)
{
$this->url = $url;
$this->apiParas["url"] = $url;
}
public function getUrl()
{
return $this->url;
}
public function setUserId($userId)
{
$this->userId = $userId;
$this->apiParas["user_id"] = $userId;
}
public function getUserId()
{
return $this->userId;
}
public function getApiMethodName()
{
return "taobao.tbk.tpwd.create";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->text,"text");
RequestCheckUtil::checkNotNull($this->url,"url");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,32 @@
<?php
/**
* TOP API: taobao.time.get request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class TimeGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.time.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,64 @@
<?php
/**
* TOP API: taobao.top.auth.token.create request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class TopAuthTokenCreateRequest
{
/**
* 授权codegrantType==authorization_code 时需要
**/
private $code;
/**
* 与生成code的uuid配对
**/
private $uuid;
private $apiParas = array();
public function setCode($code)
{
$this->code = $code;
$this->apiParas["code"] = $code;
}
public function getCode()
{
return $this->code;
}
public function setUuid($uuid)
{
$this->uuid = $uuid;
$this->apiParas["uuid"] = $uuid;
}
public function getUuid()
{
return $this->uuid;
}
public function getApiMethodName()
{
return "taobao.top.auth.token.create";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->code,"code");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,48 @@
<?php
/**
* TOP API: taobao.top.auth.token.refresh request
*
* @author auto create
* @since 1.0, 2019.11.26
*/
class TopAuthTokenRefreshRequest
{
/**
* grantType==refresh_token 时需要
**/
private $refreshToken;
private $apiParas = array();
public function setRefreshToken($refreshToken)
{
$this->refreshToken = $refreshToken;
$this->apiParas["refresh_token"] = $refreshToken;
}
public function getRefreshToken()
{
return $this->refreshToken;
}
public function getApiMethodName()
{
return "taobao.top.auth.token.refresh";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->refreshToken,"refreshToken");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,32 @@
<?php
/**
* TOP API: taobao.top.ipout.get request
*
* @author auto create
* @since 1.0, 2018.08.07
*/
class TopIpoutGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.top.ipout.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,64 @@
<?php
/**
* TOP API: taobao.top.sdk.feedback.upload request
*
* @author auto create
* @since 1.0, 2020.08.19
*/
class TopSdkFeedbackUploadRequest
{
/**
* 具体内容json形式
**/
private $content;
/**
* 1、回传加密信息
**/
private $type;
private $apiParas = array();
public function setContent($content)
{
$this->content = $content;
$this->apiParas["content"] = $content;
}
public function getContent()
{
return $this->content;
}
public function setType($type)
{
$this->type = $type;
$this->apiParas["type"] = $type;
}
public function getType()
{
return $this->type;
}
public function getApiMethodName()
{
return "taobao.top.sdk.feedback.upload";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->type,"type");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,80 @@
<?php
/**
* TOP API: taobao.top.secret.get request
*
* @author auto create
* @since 1.0, 2019.11.07
*/
class TopSecretGetRequest
{
/**
* 自定义用户id
**/
private $customerUserId;
/**
* 伪随机数
**/
private $randomNum;
/**
* 秘钥版本号
**/
private $secretVersion;
private $apiParas = array();
public function setCustomerUserId($customerUserId)
{
$this->customerUserId = $customerUserId;
$this->apiParas["customer_user_id"] = $customerUserId;
}
public function getCustomerUserId()
{
return $this->customerUserId;
}
public function setRandomNum($randomNum)
{
$this->randomNum = $randomNum;
$this->apiParas["random_num"] = $randomNum;
}
public function getRandomNum()
{
return $this->randomNum;
}
public function setSecretVersion($secretVersion)
{
$this->secretVersion = $secretVersion;
$this->apiParas["secret_version"] = $secretVersion;
}
public function getSecretVersion()
{
return $this->secretVersion;
}
public function getApiMethodName()
{
return "taobao.top.secret.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
RequestCheckUtil::checkNotNull($this->randomNum,"randomNum");
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,47 @@
<?php
/**
* TOP API: taobao.top.secret.register request
*
* @author auto create
* @since 1.0, 2018.07.25
*/
class TopSecretRegisterRequest
{
/**
* 用户id保证唯一
**/
private $userId;
private $apiParas = array();
public function setUserId($userId)
{
$this->userId = $userId;
$this->apiParas["user_id"] = $userId;
}
public function getUserId()
{
return $this->userId;
}
public function getApiMethodName()
{
return "taobao.top.secret.register";
}
public function getApiParas()
{
return $this->apiParas;
}
public function check()
{
}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,51 @@
<?php
class Security {
private static $iv = "0102030405060708";
public static function encrypt($input, $key) {
$key = base64_decode($key);
$localIV = Security::$iv;
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $key, $localIV);
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$input = Security::pkcs5_pad($input, $size);
$data = mcrypt_generic($module, $input);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
$data = base64_encode($data);
return $data;
}
public static function hmac_md5($input, $key) {
$key = base64_decode($key);
return hash_hmac('md5', $input, $key,true);
}
private static function pkcs5_pad ($text, $blocksize) {
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
public static function decrypt($sStr, $key) {
$key = base64_decode($key);
$localIV = Security::$iv;
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $key, $localIV);
$encryptedData = base64_decode($sStr);
$encryptedData = mdecrypt_generic($module, $encryptedData);
$dec_s = strlen($encryptedData);
$padding = ord($encryptedData[$dec_s-1]);
$decrypted = substr($encryptedData, 0, -$padding);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
if(!$decrypted){
throw new Exception("Decrypt Error,Please Check SecretKey");
}
return $decrypted;
}
}
?>

@ -0,0 +1,8 @@
1,使用方式参见SecurityTest.php
2,建议使用本地缓存解密秘钥,可以使用系统实现的 YacCache 或者自己去实现 iCache 接口插入到 SecurityClient 中。
3(必须安装) 加密框架依赖 mcrypt 扩展,安装参见 http://www.cnblogs.com/lihanbingboke/p/5534258.html
4(可选安装) YacCache 依赖 yac 扩展,安装参见 http://www.widuu.com/archives/09/792.html

@ -0,0 +1,61 @@
<?php
class SecretContext
{
var $secret;
var $secretVersion;
var $invalidTime;
var $maxInvalidTime;
var $appConfig;
var $cacheKey = '';
var $session = '';
var $encryptPhoneNum = 0;
var $encryptNickNum = 0;
var $encryptReceiverNameNum = 0;
var $encryptSimpleNum = 0;
var $encryptSearchNum = 0;
var $decryptPhoneNum = 0;
var $decryptNickNum = 0;
var $decryptReceiverNameNum = 0;
var $decryptSimpleNum = 0;
var $decryptSearchNum = 0;
var $searchPhoneNum = 0;
var $searchNickNum = 0;
var $searchReceiverNameNum = 0;
var $searchSimpleNum = 0;
var $searchSearchNum = 0;
var $lastUploadTime;
function toLogString()
{
return $this->session.','.$this->encryptPhoneNum.','.$this->encryptNickNum.','
.$this->encryptReceiverNameNum.','.$this->encryptSimpleNum.','.$this->encryptSearchNum.','
.$this->decryptPhoneNum.','.$this->decryptNickNum.','.$this->decryptReceiverNameNum.','
.$this->decryptSimpleNum.','.$this->decryptSearchNum.','.$this->searchPhoneNum.','
.$this->searchNickNum.','.$this->searchReceiverNameNum.','.$this->searchSimpleNum.','
.$this->searchSearchNum ;
}
function __construct()
{
$this->lastUploadTime = time();
}
}
class SecretData
{
var $originalValue;
var $originalBase64Value;
var $secretVersion;
var $search;
function __construct()
{
}
}
?>

@ -0,0 +1,97 @@
<?php
include './SecretContext.php';
include './iCache.php';
include '../../TopSdk.php';
class SecretCounterUtil
{
private $topClient ;
private $cacheClient = null;
private $counterMap;
function __construct($client)
{
$this->topClient = $client;
$counterMap = array();
}
/*
* 如果不走缓存模式析构即调用API回传统计信息
*/
function __destruct()
{
if($this->cacheClient == null){
}
}
function report($session)
{
$request = new TopSdkFeedbackUploadRequest;
}
function setCacheClient($cache)
{
$this->cacheClient = $cache;
}
function incrDecrypt($delt,$session,$type)
{
$item = getItem($session);
if($item == null){
$item = new SecretCounter();
putItem($session,$item);
}
if($type == "nick"){
$item->$decryptNickNum += $delt;
}else if($type == "receiver_name"){
$item->$decryptReceiverNameNum += $delt ;
}else if($type == "phone"){
$item->$decryptPhoneNum += $delt ;
}else if($type == "simple"){
$item->$decryptSimpleNum += $delt ;
}
}
function incrEncrypt($delt,$session,$type)
{
$item = getItem($session);
if($item == null){
$item = new SecretCounter();
putItem($session,$item);
}
if($type == "nick"){
$item->$encryptNickNum += $delt ;
}else if($type == "receiver_name"){
$item->$encryptReceiverNameNum += $delt ;
}else if($type == "phone"){
$item->$encryptPhoneNum += $delt ;
}else if($type == "simple"){
$item->$encryptSimpleNum += $delt ;
}
}
function getItem($session)
{
if($this->cacheClient == null){
return $counterMap[$session];
}else{
return $this->cacheClient->getCache('s_'.$session);
}
}
function putItem($session,$item)
{
if($this->cacheClient == null){
$counterMap[$session] = $item;
}else{
$this->cacheClient->setCache('s_'.$session,$item);
}
}
}
?>

@ -0,0 +1,35 @@
<?php
class TopSecretGetRequest
{
private $apiParas = array();
public function getApiMethodName()
{
return "taobao.top.secret.get";
}
public function getApiParas()
{
return $this->apiParas;
}
public function setRandomNum($random){
$this->apiParas['random_num'] = $random;
}
public function setCustomerUserId($customId){
$this->apiParas['customer_user_id'] = $customId;
}
public function setSecretVersion($version){
$this->apiParas['secret_version'] = $version;
}
public function check(){}
public function putOtherTextParam($key, $value) {
$this->apiParas[$key] = $value;
$this->$key = $value;
}
}

@ -0,0 +1,543 @@
<?php
include './SecurityUtil.php';
include './SecretGetRequest.php';
include './TopSdkFeedbackUploadRequest.php';
include './iCache.php';
include '../../TopSdk.php';
class SecurityClient
{
private $topClient ;
private $randomNum ;
private $securityUtil;
private $cacheClient = null;
function __construct($client, $random)
{
define('APP_SECRET_TYPE','2');
define('APP_USER_SECRET_TYPE','3');
$this->topClient = $client;
$this->randomNum = $random;
$this->securityUtil = new SecurityUtil();
}
/**
* 设置缓存处理器
*/
function setCacheClient($cache)
{
$this->cacheClient = $cache;
}
/**
* 密文检索,在秘钥升级场景下兼容查询
*
* @see #search(String, String, String, Long)
* @return
*/
function searchPrevious($data,$type,$session = null)
{
return $this->searchInner($data,$type,$session,-1);
}
/**
* 密文检索(每个用户单独分配秘钥)
*
* @see #search(String, String, String, Long)
* @return
*/
function search($data,$type,$session = null)
{
return $this->searchInner($data,$type,$session,null);
}
/**
* 密文检索。 手机号码格式:$base64(H-MAC(phone后4位))$ simple格式base64(H-MAC(滑窗))
*
* @param data
* 明文数据
* @param type
* 加密字段类型(例如simple\phone)
* @param session
* 用户身份,用户级加密必填
* @param version
* 秘钥历史版本
* @return
*/
function searchInner($data, $type, $session,$version)
{
if(empty($data) || empty($type)){
return $data;
}
$secretContext = null;
$secretContext = $this->callSecretApiWithCache($session,$version);
$this->incrCounter(3,$type,$secretContext,true);
if(empty($secretContext) || empty($secretContext->secret)) {
return $data;
}
return $this->securityUtil->search($data, $type,$secretContext);
}
/**
* 单条数据解密,使用appkey级别公钥
* 非加密数据直接返回原文
*/
function decryptPublic($data,$type)
{
return $this->decrypt($data,$type,null);
}
/**
* 单条数据解密
* 非加密数据直接返回原文
*/
function decrypt($data,$type,$session)
{
if(empty($data) || empty($type)){
return $data;
}
$secretData = $this->securityUtil->getSecretDataByType($data,$type);
if(empty($secretData)){
return $data;
}
if($this->securityUtil->isPublicData($data,$type)){
$secretContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
} else {
$secretContext = $this->callSecretApiWithCache($session,$secretData->secretVersion);
}
$this->incrCounter(2,$type,$secretContext,true);
return $this->securityUtil->decrypt($data,$type,$secretContext);
}
/**
* 多条数据解密使用appkey级别公钥
* 非加密数据直接返回原文
*/
function decryptBatchPublic($array,$type)
{
if(empty($array) || empty($type)){
return null;
}
$result = array();
foreach ($array as $value) {
$secretData = $this->securityUtil->getSecretDataByType($value,$type);
$secretContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
if(empty($secretData)){
$result[$value] = $value;
}else{
$result[$value] = $this->securityUtil->decrypt($value,$type,$secretContext);
$this->incrCounter(2,$type,$secretContext,true);
}
$this->flushCounter($secretContext);
}
return $result;
}
/**
* 多条数据解密必须是同一个type和用户,返回结果是 KV结果
* 非加密数据直接返回原文
*/
function decryptBatch($array,$type,$session)
{
if(empty($array) || empty($type)){
return null;
}
$result = array();
foreach ($array as $value) {
$secretData = $this->securityUtil->getSecretDataByType($value,$type);
if(empty($secretData)){
$result[$value] = $value;
} else if($this->securityUtil->isPublicData($value,$type)){
$appContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
$result[$value] = $this->securityUtil->decrypt($value,$type,$appContext);
$this->incrCounter(2,$type,$appContext,false);
$this->flushCounter($appContext);
} else {
$secretContext = $this->callSecretApiWithCache($session,$secretData->secretVersion);
$result[$value] = $this->securityUtil->decrypt($value,$type,$secretContext);
$this->incrCounter(2,$type,$secretContext,false);
$this->flushCounter($secretContext);
}
}
return $result;
}
/**
* 使用上一版本秘钥解密app级别公钥
*/
function decryptPreviousPublic($data,$type)
{
$secretContext = $this->callSecretApiWithCache(null,-1);
return $this->securityUtil->decrypt($data,$type,$secretContext);
}
/**
* 使用上一版本秘钥解密,一般只用于更新秘钥
*/
function decryptPrevious($data,$type,$session)
{
if($this->securityUtil->isPublicData($data,$type)){
$secretContext = $this->callSecretApiWithCache(null,-1);
} else {
$secretContext = $this->callSecretApiWithCache($session,-1);
}
return $this->securityUtil->decrypt($data,$type,$secretContext);
}
/**
* 加密单条数据,使用app级别公钥
*/
function encryptPublic($data,$type,$version = null)
{
return $this->encrypt($data,$type,null,$version);
}
/**
* 加密单条数据
*/
function encrypt($data,$type,$session = null,$version = null)
{
if(empty($data) || empty($type)){
return null;
}
$secretContext = $this->callSecretApiWithCache($session,null);
$this->incrCounter(1,$type,$secretContext,true);
return $this->securityUtil->encrypt($data,$type,$version,$secretContext);
}
/**
* 加密多条数据使用app级别公钥
*/
function encryptBatchPublic($array,$type,$version = null)
{
if(empty($array) || empty($type)){
return null;
}
$secretContext = $this->callSecretApiWithCache(null,null);
$result = array();
foreach ($array as $value) {
$result[$value] = $this->securityUtil->encrypt($value,$type,$version,$secretContext);
$this->incrCounter(1,$type,$secretContext,false);
}
$this->flushCounter($secretContext);
return $result;
}
/**
* 加密多条数据必须是同一个type和用户,返回结果是 KV结果
*/
function encryptBatch($array,$type,$session,$version = null)
{
if(empty($array) || empty($type)){
return null;
}
$secretContext = $this->callSecretApiWithCache($session,null);
$result = array();
foreach ($array as $value) {
$result[$value] = $this->securityUtil->encrypt($value,$type,$version,$secretContext);
$this->incrCounter(1,$type,$secretContext,false);
}
$this->flushCounter($secretContext);
return $result;
}
/**
* 使用上一版本秘钥加密使用app级别公钥
*/
function encryptPreviousPublic($data,$type)
{
$secretContext = $this->callSecretApiWithCache(null,-1);
$this->incrCounter(1,$type,$secretContext,true);
return $this->securityUtil->encrypt($data,$type,$secretContext->version,$secretContext);
}
/**
* 使用上一版本秘钥加密,一般只用于更新秘钥
*/
function encryptPrevious($data,$type,$session)
{
$secretContext = $this->callSecretApiWithCache($session,-1);
$this->incrCounter(1,$type,$secretContext,true);
return $this->securityUtil->encrypt($data,$type,$secretContext);
}
/**
* 根据session生成秘钥
*/
function initSecret($session)
{
return $this->callSecretApiWithCache($session,null);
}
function buildCacheKey($session,$secretVersion)
{
if(empty($session)){
return $this->topClient->getAppkey();
}
if(empty($secretVersion)){
return $session ;
}
return $session.'_'.$secretVersion ;
}
function generateCustomerSession($userId)
{
return '_'.$userId ;
}
/**
* 判断是否是已加密的数据
*/
function isEncryptData($data,$type)
{
if(empty($data) || empty($type)){
return false;
}
return $this->securityUtil->isEncryptData($data,$type);
}
/**
* 判断是否是已加密的数据,数据必须是同一个类型
*/
function isEncryptDataArray($array,$type)
{
if(empty($array) || empty($type)){
return false;
}
return $this->securityUtil->isEncryptDataArray($array,$type);
}
/**
* 判断数组中的数据是否存在密文存在任何一个返回true,否则false
*/
function isPartEncryptData($array,$type)
{
if(empty($array) || empty($type)){
return false;
}
return $this->securityUtil->isPartEncryptData($array,$type);
}
/**
* 获取秘钥,使用缓存
*/
function callSecretApiWithCache($session,$secretVersion)
{
if($this->cacheClient)
{
$time = time();
$cacheKey = $this->buildCacheKey($session,$secretVersion);
$secretContext = $this->cacheClient->getCache($cacheKey);
if($secretContext)
{
if($this->canUpload($secretContext)){
if($this->report($secretContext)){
$this->clearReport($secretContext);
}
}
}
if($secretContext && $secretContext->invalidTime > $time)
{
return $secretContext;
}
}
$secretContext = $this->callSecretApi($session,$secretVersion);
if($this->cacheClient)
{
$secretContext->cacheKey = $cacheKey;
$this->cacheClient->setCache($cacheKey,$secretContext);
}
return $secretContext;
}
function incrCounter($op,$type,$secretContext,$flush)
{
if($op == 1){
switch ($type) {
case 'nick':
$secretContext->encryptNickNum ++ ;
break;
case 'simple':
$secretContext->encryptSimpleNum ++ ;
break;
case 'receiver_name':
$secretContext->encryptReceiverNameNum ++ ;
break;
case 'phone':
$secretContext->encryptPhoneNum ++ ;
break;
default:
break;
}
}else if($op == 2){
switch ($type) {
case 'nick':
$secretContext->decryptNickNum ++ ;
break;
case 'simple':
$secretContext->decryptSimpleNum ++ ;
break;
case 'receiver_name':
$secretContext->decryptReceiverNameNum ++ ;
break;
case 'phone':
$secretContext->decryptPhoneNum ++ ;
break;
default:
break;
}
}else{
switch ($type) {
case 'nick':
$secretContext->searchNickNum ++ ;
break;
case 'simple':
$secretContext->searchSimpleNum ++ ;
break;
case 'receiver_name':
$secretContext->searchReceiverNameNum ++ ;
break;
case 'phone':
$secretContext->searchPhoneNum ++ ;
break;
default:
break;
}
}
if($flush && $this->cacheClient){
$this->cacheClient->setCache($secretContext->cacheKey,$secretContext);
}
}
function flushCounter($secretContext)
{
if($this->cacheClient){
$this->cacheClient->setCache($secretContext->cacheKey,$secretContext);
}
}
function clearReport($secretContext)
{
$secretContext->encryptPhoneNum = 0;
$secretContext->encryptNickNum = 0;
$secretContext->encryptReceiverNameNum = 0;
$secretContext->encryptSimpleNum = 0;
$secretContext->encryptSearchNum = 0;
$secretContext->decryptPhoneNum = 0;
$secretContext->decryptNickNum = 0;
$secretContext->decryptReceiverNameNum = 0;
$secretContext->decryptSimpleNum = 0;
$secretContext->decryptSearchNum = 0;
$secretContext->searchPhoneNum = 0;
$secretContext->searchNickNum = 0;
$secretContext->searchReceiverNameNum = 0;
$secretContext->searchSimpleNum = 0;
$secretContext->searchSearchNum = 0;
$secretContext->lastUploadTime = time();
}
function canUpload($secretContext)
{
$current = time();
if($current - $secretContext->lastUploadTime > 300){
return true;
}
return false;
}
/*
* 上报信息
*/
function report($secretContext)
{
$request = new TopSdkFeedbackUploadRequest;
$request->setContent($secretContext->toLogString());
if(empty($secretContext->session)){
$request->setType(APP_SECRET_TYPE);
}else{
$request->setType(APP_USER_SECRET_TYPE);
}
$response = $this->topClient->execute($request,$secretContext->session);
if($response->code == 0){
return true;
}
return false;
}
/**
* 获取秘钥,不使用缓存
*/
function callSecretApi($session,$secretVersion)
{
$request = new TopSecretGetRequest;
$request->setRandomNum($this->randomNum);
if($secretVersion)
{
if(intval($secretVersion) < 0 || $session == null){
$session = null;
$secretVersion = -1 * intval($secretVersion < 0);
}
$request->setSecretVersion($secretVersion);
}
$topSession = $session;
if($session != null && $session[0] == '_')
{
$request->setCustomerUserId(substr($session,1));
$topSession = null;
}
$response = $this->topClient->execute($request,$topSession);
if($response->code != 0){
throw new Exception($response->msg);
}
$time = time();
$secretContext = new SecretContext();
$secretContext->maxInvalidTime = $time + intval($response->max_interval);
$secretContext->invalidTime = $time + intval($response->interval);
$secretContext->secret = strval($response->secret);
$secretContext->session = $session;
if(!empty($response->app_config)){
$tmpJson = json_decode($response->app_config);
$appConfig = array();
foreach ($tmpJson as $key => $value){
$appConfig[$key] = $value;
}
$secretContext->appConfig = $appConfig;
}
if(empty($session)){
$secretContext->secretVersion = -1 * intval($response->secret_version);
}else{
$secretContext->secretVersion = intval($response->secret_version);
}
return $secretContext;
}
}
?>

@ -0,0 +1,68 @@
<?php
include './SecurityClient.php';
include './YacCache.php';
$c = new TopClient;
$c->appkey = '576216';
$c->secretKey = 'd1e44cec2f6c8a2c73342595b711decc';
$c->gatewayUrl = 'https://10.218.128.111/router/rest';
$session = '6101701a21788e0e44743d5f1032ccd5276f00ea6a2d9092050695162';
$client = new SecurityClient($c,'S7/xdg4AD7WooWY7+g11qoBpaVsEkonULDJPEiMcXPE=');
$yac = new YacCache;
$client->setCacheClient($yac);
$type = 'phone';
$val = '13834566786';
echo "原文13834566786".PHP_EOL;
$encryptValue = $client->encrypt($val,$type,$session);
echo "加密后:".$encryptValue.PHP_EOL;
echo "search明文".$val." -->".$client->search("6786",$type,$session).PHP_EOL;
if($client->isEncryptData($encryptValue,$type))
{
$originalValue = $client->decrypt($encryptValue,$type,$session);
echo "解密后:".$originalValue.PHP_EOL;
}
$originalValue = $client->decrypt('~YjW+T6rCmKcc0tGqzWIDaQ==~-113~','nick',$session);
echo "公钥解密后:".$originalValue.PHP_EOL;
$secArray = array('~YjW+T6rCmKcc0tGqzWIDaQ==~-113~');
$client->decryptBatch($secArray,'nick',$session);
$typeArray = array('normal','nick','receiver_name');
$val2 = '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊看哦【啊啊啊的';
foreach ($typeArray as $type2) {
echo "==============================TOP================================".PHP_EOL;
$encty2 = $client->encrypt($val2,$type2,$session);
echo $type2."|明文:".$val2." ---->密文:".$encty2.PHP_EOL;
if($client->isEncryptData($encty2,$type2))
{
$originalValue = $client->decrypt($encty2,$type2,$session);
echo "解密后:".$originalValue.PHP_EOL;
echo "search明文".$originalValue." -->".$client->search($originalValue,$type2,$session).PHP_EOL;
}else{
echo "不是加密数据".PHP_EOL;
}
}
$encryptNick = $client->encrypt("xxxuxxxuxxxu","nick");
echo "加密后:".$encryptNick.PHP_EOL;
echo "search明文xxxuxxxuxxxu -->".$client->search("xxxu","nick").PHP_EOL;
if($client->isEncryptData($encryptNick,"nick"))
{
$originalNick = $client->decryptPublic($encryptNick,"nick");
echo "解密后:".$originalNick.PHP_EOL;
}else{
echo "不是加密数据 ".$encryptNick.PHP_EOL;
}
?>

@ -0,0 +1,589 @@
<?php
include './SecretContext.php';
include './MagicCrypt.php';
class SecurityUtil
{
private $BASE64_ARRAY = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
private $SEPARATOR_CHAR_MAP;
function __construct()
{
if(!defined("PHONE_SEPARATOR_CHAR"))
{
define('PHONE_SEPARATOR_CHAR','$');
}
if(!defined("NICK_SEPARATOR_CHAR"))
{
define('NICK_SEPARATOR_CHAR','~');
}
if(!defined("NORMAL_SEPARATOR_CHAR"))
{
define('NORMAL_SEPARATOR_CHAR',chr(1));
}
$this->SEPARATOR_CHAR_MAP['nick'] = NICK_SEPARATOR_CHAR;
$this->SEPARATOR_CHAR_MAP['simple'] = NICK_SEPARATOR_CHAR;
$this->SEPARATOR_CHAR_MAP['receiver_name'] = NICK_SEPARATOR_CHAR;
$this->SEPARATOR_CHAR_MAP['search'] = NICK_SEPARATOR_CHAR;
$this->SEPARATOR_CHAR_MAP['normal'] = NORMAL_SEPARATOR_CHAR;
$this->SEPARATOR_CHAR_MAP['phone'] = PHONE_SEPARATOR_CHAR;
}
/*
* 判断是否是base64格式的数据
*/
function isBase64Str($str)
{
$strLen = strlen($str);
for($i = 0; $i < $strLen ; $i++)
{
if(!$this->isBase64Char($str[$i]))
{
return false;
}
}
return true;
}
/*
* 判断是否是base64格式的字符
*/
function isBase64Char($char)
{
return strpos($this->BASE64_ARRAY,$char) !== false;
}
/*
* 使用sep字符进行trim
*/
function trimBySep($str,$sep)
{
$start = 0;
$end = strlen($str);
for($i = 0; $i < $end; $i++)
{
if($str[$i] == $sep)
{
$start = $i + 1;
}
else
{
break;
}
}
for($i = $end -1 ; $i >= 0; $i--)
{
if($str[$i] == $sep)
{
$end = $i - 1;
}
else
{
break;
}
}
return substr($str,$start,$end);
}
function checkEncryptData($dataArray)
{
if(count($dataArray) == 2){
return $this->isBase64Str($dataArray[0]);
}else{
return $this->isBase64Str($dataArray[0]) && $this->isBase64Str($dataArray[1]);
}
}
/*
* 判断是否是加密数据
*/
function isEncryptDataArray($array,$type)
{
foreach ($array as $value) {
if(!$this->isEncryptData($value,$type)){
return false;
}
}
return true;
}
/**
* 判断是否是已加密的数据,数据必须是同一个类型
*/
function isPartEncryptData($array,$type)
{
$result = false;
foreach ($array as $value) {
if($this->isEncryptData($value,$type)){
$result = true;
break;
}
}
return $result;
}
/*
* 判断是否是加密数据
*/
function isEncryptData($data,$type)
{
if(!is_string($data) || strlen($data) < 4)
{
return false;
}
$separator = $this->SEPARATOR_CHAR_MAP[$type];
$strlen = strlen($data);
if($data[0] != $separator || $data[$strlen -1] != $separator)
{
return false;
}
$dataArray = explode($separator,$this->trimBySep($data,$separator));
$arrayLength = count($dataArray);
if($separator == PHONE_SEPARATOR_CHAR)
{
if($arrayLength != 3)
{
return false;
}
if($data[$strlen - 2] == $separator)
{
return $this->checkEncryptData($dataArray);
}
else
{
$version = $dataArray[$arrayLength -1];
if(is_numeric($version))
{
$base64Val = $dataArray[$arrayLength -2];
return $this->isBase64Str($base64Val);
}
}
}else{
if($data[strlen($data) - 2] == $separator && $arrayLength == 3)
{
return $this->checkEncryptData($dataArray);
}
else if($arrayLength == 2)
{
return $this->checkEncryptData($dataArray);
}
else
{
return false;
}
}
}
function search($data, $type,$secretContext)
{
$separator = $this->SEPARATOR_CHAR_MAP[$type];
if('phone' == $type) {
if (strlen($data) != 4 ) {
throw new Exception("phoneNumber error");
}
return $separator.$this->hmacMD5EncryptToBase64($data, $secretContext->secret).$separator;
} else {
$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
$slideList = $this->getSlideWindows($data, $slideSize);
$builder = '';
foreach ($slideList as $slide) {
$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
}
return $builder;
}
}
/*
* 加密逻辑
*/
function encrypt($data,$type,$version,$secretContext)
{
if(!is_string($data))
{
return false;
}
$separator = $this->SEPARATOR_CHAR_MAP[$type];
$isIndexEncrypt = $this->isIndexEncrypt($type,$version,$secretContext);
if($isIndexEncrypt || $type == "search"){
if('phone' == $type) {
return $this->encryptPhoneIndex($data,$separator,$secretContext);
} else {
$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
return $this->encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext);
}
}else{
if('phone' == $type) {
return $this->encryptPhone($data,$separator,$secretContext);
} else {
return $this->encryptNormal($data,$separator,$secretContext);
}
}
}
/*
* 加密逻辑,手机号码格式
*/
function encryptPhone($data,$separator,$secretContext)
{
$len = strlen($data);
if($len < 11)
{
return $data;
}
$prefixNumber = substr($data,0,$len -8);
$last8Number = substr($data,$len -8,$len);
return $separator.$prefixNumber.$separator.Security::encrypt($last8Number,$secretContext->secret)
.$separator.$secretContext->secretVersion.$separator ;
}
/*
* 加密逻辑,非手机号码格式
*/
function encryptNormal($data,$separator,$secretContext)
{
return $separator.Security::encrypt($data,$secretContext->secret)
.$separator.$secretContext->secretVersion.$separator;
}
/*
* 解密逻辑
*/
function decrypt($data,$type,$secretContext)
{
if(!$this->isEncryptData($data,$type))
{
throw new Exception("数据[".$data."]不是类型为[".$type."]的加密数据");
}
$dataLen = strlen($data);
$separator = $this->SEPARATOR_CHAR_MAP[$type];
$secretData = null;
if($data[$dataLen - 2] == $separator){
$secretData = $this->getIndexSecretData($data,$separator);
}else{
$secretData = $this->getSecretData($data,$separator);
}
if($secretData == null){
return $data;
}
$result = Security::decrypt($secretData->originalBase64Value,$secretContext->secret);
if($separator == PHONE_SEPARATOR_CHAR && !$secretData->search)
{
return $secretData->originalValue.$result;
}
return $result;
}
/*
* 判断是否是公钥数据
*/
function isPublicData($data,$type)
{
$secretData = $this->getSecretDataByType($data,$type);
if(empty($secretData)){
return false;
}
if(intval($secretData->secretVersion) < 0){
return true;
}
return false;
}
function getSecretDataByType($data,$type)
{
$separator = $this->SEPARATOR_CHAR_MAP[$type];
$dataLen = strlen($data);
if($data[$dataLen - 2] == $separator){
return $secretData = $this->getIndexSecretData($data,$separator);
}else{
return $secretData = $this->getSecretData($data,$separator);
}
}
/*
* 分解密文
*/
function getSecretData($data,$separator)
{
$secretData = new SecretData;
$dataArray = explode($separator,$this->trimBySep($data,$separator));
$arrayLength = count($dataArray);
if($separator == PHONE_SEPARATOR_CHAR)
{
if($arrayLength != 3){
return null;
}else{
$version = $dataArray[2];
if(is_numeric($version))
{
$secretData->originalValue = $dataArray[0];
$secretData->originalBase64Value = $dataArray[1];
$secretData->secretVersion = $version;
}
}
}
else
{
if($arrayLength != 2){
return null;
}else{
$version = $dataArray[1];
if(is_numeric($version))
{
$secretData->originalBase64Value = $dataArray[0];
$secretData->secretVersion = $version;
}
}
}
return $secretData;
}
function getIndexSecretData($data,$separator) {
$secretData = new SecretData;
$dataArray = explode($separator,$this->trimBySep($data,$separator));
$arrayLength = count($dataArray);
if($separator == PHONE_SEPARATOR_CHAR) {
if ($arrayLength != 3) {
return null;
}else{
$version = $dataArray[2];
if(is_numeric($version))
{
$secretData->originalValue = $dataArray[0];
$secretData->originalBase64Value = $dataArray[1];
$secretData->secretVersion = $version;
}
}
} else {
if($arrayLength != 3){
return null;
} else {
$version = $dataArray[2];
if(is_numeric($version))
{
$secretData->originalBase64Value = $dataArray[0];
$secretData->originalValue = $dataArray[1];
$secretData->secretVersion = $version;
}
}
}
$secretData->search = true;
return $secretData;
}
/**
* 判断密文是否支持检索
*
* @param key
* @param version
* @return
*/
function isIndexEncrypt($key,$version,$secretContext)
{
if ($version != null && $version < 0) {
$key = "previous_".$key;
} else {
$key = "current_".$key;
}
return $secretContext->appConfig != null &&
array_key_exists($key,$secretContext->appConfig) &&
$secretContext->appConfig[$key] == "2";
}
function isLetterOrDigit($ch)
{
$code = ord($ch);
if (0 <= $code && $code <= 127) {
return true;
}
return false;
}
function utf8_strlen($string = null) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return count($match[0]);
}
function utf8_substr($string,$start,$end) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
$result = "";
for($i = $start; $i < $end; $i++){
$result .= $match[0][$i];
}
return $result;
}
function utf8_str_at($string,$index) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return $match[0][$index];
}
function compress($input,$toLength) {
if($toLength < 0) {
return null;
}
$output = array();
for($i = 0; $i < $toLength; $i++) {
$output[$i] = chr(0);
}
$input = $this->getBytes($input);
$inputLength = count($input);
for ($i = 0; $i < $inputLength; $i++) {
$index_output = $i % $toLength;
$output[$index_output] = $output[$index_output] ^ $input[$i];
}
return $output;
}
/**
* @see #hmacMD5Encrypt
*
* @param encryptText
* 被签名的字符串
* @param encryptKey
* 密钥
* @param compressLen压缩长度
* @return
* @throws Exception
*/
function hmacMD5EncryptToBase64($encryptText,$encryptKey,$compressLen = 0) {
$encryptResult = Security::hmac_md5($encryptText,$encryptKey);
if($compressLen != 0){
$encryptResult = $this->compress($encryptResult,$compressLen);
}
return base64_encode($this->toStr($encryptResult));
}
/**
* 生成滑动窗口
*
* @param input
* @param slideSize
* @return
*/
function getSlideWindows($input,$slideSize = 4)
{
$endIndex = 0;
$startIndex = 0;
$currentWindowSize = 0;
$currentWindow = null;
$dataLength = $this->utf8_strlen($input);
$windows = array();
while($endIndex < $dataLength || $currentWindowSize > $slideSize)
{
$startsWithLetterOrDigit = false;
if(!empty($currentWindow)){
$startsWithLetterOrDigit = $this->isLetterOrDigit($this->utf8_str_at($currentWindow,0));
}
if($endIndex == $dataLength && $startsWithLetterOrDigit == false){
break;
}
if($currentWindowSize == $slideSize &&
$startsWithLetterOrDigit == false &&
$this->isLetterOrDigit($this->utf8_str_at($input,$endIndex))) {
$endIndex ++;
$currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
$currentWindowSize = 5;
} else {
if($endIndex != 0){
if($startsWithLetterOrDigit){
$currentWindowSize -= 1;
}else{
$currentWindowSize -= 2;
}
$startIndex ++;
}
while ($currentWindowSize < $slideSize && $endIndex < $dataLength) {
$currentChar = $this->utf8_str_at($input,$endIndex);
if ($this->isLetterOrDigit($currentChar)) {
$currentWindowSize += 1;
} else {
$currentWindowSize += 2;
}
$endIndex++;
}
$currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
}
array_push($windows,$currentWindow);
}
return $windows;
}
function encryptPhoneIndex($data,$separator,$secretContext) {
$dataLength = strlen($data);
if($dataLength < 11) {
return $data;
}
$last4Number = substr($data,$dataLength -4 ,$dataLength);
return $separator.$this->hmacMD5EncryptToBase64($last4Number,$secretContext->secret).$separator
.Security::encrypt($data,$secretContext->secret).$separator.$secretContext->secretVersion
.$separator.$separator;
}
function encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext) {
$slideList = $this->getSlideWindows($data, $slideSize);
$builder = "";
foreach ($slideList as $slide) {
$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
}
return $separator.Security::encrypt($data,$secretContext->secret).$separator.$builder.$separator
.$secretContext->secretVersion.$separator.$separator;
}
function getArrayValue($array,$key,$default) {
if(array_key_exists($key, $array)){
return $array[$key];
}
return $default;
}
function getBytes($string) {
$bytes = array();
for($i = 0; $i < strlen($string); $i++){
$bytes[] = ord($string[$i]);
}
return $bytes;
}
function toStr($bytes) {
if(!is_array($bytes)){
return $bytes;
}
$str = '';
foreach($bytes as $ch) {
$str .= chr($ch);
}
return $str;
}
}
?>

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

Loading…
Cancel
Save