diff --git a/CHANGELOG.md b/CHANGELOG.md index c8e9d6a..d9df294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 5132533..b77c77d 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/common.php b/src/common.php index 50e2f7f..e28cdc8 100644 --- a/src/common.php +++ b/src/common.php @@ -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')) { /** diff --git a/src/service/taobao/TaoBaoService.php b/src/service/taobao/TaoBaoService.php new file mode 100644 index 0000000..1577eaf --- /dev/null +++ b/src/service/taobao/TaoBaoService.php @@ -0,0 +1,113 @@ +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; + } +} \ No newline at end of file diff --git a/src/service/taobao/bin/Autoloader.php b/src/service/taobao/bin/Autoloader.php new file mode 100644 index 0000000..fc56080 --- /dev/null +++ b/src/service/taobao/bin/Autoloader.php @@ -0,0 +1,78 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/OapiTest.php b/src/service/taobao/bin/OapiTest.php new file mode 100644 index 0000000..6b010d7 --- /dev/null +++ b/src/service/taobao/bin/OapiTest.php @@ -0,0 +1,12 @@ +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) + +?> \ No newline at end of file diff --git a/src/service/taobao/bin/QimenCloud/QimenCloudClient.php b/src/service/taobao/bin/QimenCloud/QimenCloudClient.php new file mode 100644 index 0000000..42e82b2 --- /dev/null +++ b/src/service/taobao/bin/QimenCloud/QimenCloudClient.php @@ -0,0 +1,384 @@ +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); + } +} diff --git a/src/service/taobao/bin/TopSdk.php b/src/service/taobao/bin/TopSdk.php new file mode 100644 index 0000000..8f623d2 --- /dev/null +++ b/src/service/taobao/bin/TopSdk.php @@ -0,0 +1,40 @@ +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); + } +} diff --git a/src/service/taobao/bin/dingtalk/DingTalkClient.php b/src/service/taobao/bin/dingtalk/DingTalkClient.php new file mode 100644 index 0000000..ad3b3b8 --- /dev/null +++ b/src/service/taobao/bin/dingtalk/DingTalkClient.php @@ -0,0 +1,653 @@ +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); + } +} diff --git a/src/service/taobao/bin/dingtalk/DingTalkConstant.php b/src/service/taobao/bin/dingtalk/DingTalkConstant.php new file mode 100644 index 0000000..f1ffad5 --- /dev/null +++ b/src/service/taobao/bin/dingtalk/DingTalkConstant.php @@ -0,0 +1,18 @@ +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); + } +} + +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/ClusterTopClient.php b/src/service/taobao/bin/top/ClusterTopClient.php new file mode 100644 index 0000000..8d1ca00 --- /dev/null +++ b/src/service/taobao/bin/top/ClusterTopClient.php @@ -0,0 +1,199 @@ +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); } +} +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/HttpdnsGetRequest.php b/src/service/taobao/bin/top/HttpdnsGetRequest.php new file mode 100644 index 0000000..13adcf0 --- /dev/null +++ b/src/service/taobao/bin/top/HttpdnsGetRequest.php @@ -0,0 +1,23 @@ +apiParas; + } + + public function check(){} + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/RequestCheckUtil.php b/src/service/taobao/bin/top/RequestCheckUtil.php new file mode 100644 index 0000000..3c3b21e --- /dev/null +++ b/src/service/taobao/bin/top/RequestCheckUtil.php @@ -0,0 +1,107 @@ + $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; + } + +} +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/ResultSet.php b/src/service/taobao/bin/top/ResultSet.php new file mode 100644 index 0000000..dc3684e --- /dev/null +++ b/src/service/taobao/bin/top/ResultSet.php @@ -0,0 +1,21 @@ + $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\w+)\[(?P\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); + } +} +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/TopClient.php b/src/service/taobao/bin/top/TopClient.php new file mode 100644 index 0000000..06f43dd --- /dev/null +++ b/src/service/taobao/bin/top/TopClient.php @@ -0,0 +1,377 @@ +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); + } +} diff --git a/src/service/taobao/bin/top/TopLogger.php b/src/service/taobao/bin/top/TopLogger.php new file mode 100644 index 0000000..536330a --- /dev/null +++ b/src/service/taobao/bin/top/TopLogger.php @@ -0,0 +1,43 @@ + "\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); + } +} +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Data.php b/src/service/taobao/bin/top/domain/Data.php new file mode 100644 index 0000000..d45b0bc --- /dev/null +++ b/src/service/taobao/bin/top/domain/Data.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Extend.php b/src/service/taobao/bin/top/domain/Extend.php new file mode 100644 index 0000000..6e9e7bc --- /dev/null +++ b/src/service/taobao/bin/top/domain/Extend.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/FavoritesDetail.php b/src/service/taobao/bin/top/domain/FavoritesDetail.php new file mode 100644 index 0000000..8a8204f --- /dev/null +++ b/src/service/taobao/bin/top/domain/FavoritesDetail.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/FavoritesInfo.php b/src/service/taobao/bin/top/domain/FavoritesInfo.php new file mode 100644 index 0000000..17fb0c0 --- /dev/null +++ b/src/service/taobao/bin/top/domain/FavoritesInfo.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Items.php b/src/service/taobao/bin/top/domain/Items.php new file mode 100644 index 0000000..afdd836 --- /dev/null +++ b/src/service/taobao/bin/top/domain/Items.php @@ -0,0 +1,110 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/KfcSearchResult.php b/src/service/taobao/bin/top/domain/KfcSearchResult.php new file mode 100644 index 0000000..d34257a --- /dev/null +++ b/src/service/taobao/bin/top/domain/KfcSearchResult.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/MapData.php b/src/service/taobao/bin/top/domain/MapData.php new file mode 100644 index 0000000..a398038 --- /dev/null +++ b/src/service/taobao/bin/top/domain/MapData.php @@ -0,0 +1,385 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/NTbkItem.php b/src/service/taobao/bin/top/domain/NTbkItem.php new file mode 100644 index 0000000..499deee --- /dev/null +++ b/src/service/taobao/bin/top/domain/NTbkItem.php @@ -0,0 +1,210 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/NTbkShop.php b/src/service/taobao/bin/top/domain/NTbkShop.php new file mode 100644 index 0000000..e975027 --- /dev/null +++ b/src/service/taobao/bin/top/domain/NTbkShop.php @@ -0,0 +1,45 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/OrderData.php b/src/service/taobao/bin/top/domain/OrderData.php new file mode 100644 index 0000000..7a8eb46 --- /dev/null +++ b/src/service/taobao/bin/top/domain/OrderData.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/OrderPage.php b/src/service/taobao/bin/top/domain/OrderPage.php new file mode 100644 index 0000000..c02e0bc --- /dev/null +++ b/src/service/taobao/bin/top/domain/OrderPage.php @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/PageResult.php b/src/service/taobao/bin/top/domain/PageResult.php new file mode 100644 index 0000000..96a99a5 --- /dev/null +++ b/src/service/taobao/bin/top/domain/PageResult.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/PaginationResult.php b/src/service/taobao/bin/top/domain/PaginationResult.php new file mode 100644 index 0000000..1ef5600 --- /dev/null +++ b/src/service/taobao/bin/top/domain/PaginationResult.php @@ -0,0 +1,60 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/PromotionExtend.php b/src/service/taobao/bin/top/domain/PromotionExtend.php new file mode 100644 index 0000000..337720a --- /dev/null +++ b/src/service/taobao/bin/top/domain/PromotionExtend.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/PromotionList.php b/src/service/taobao/bin/top/domain/PromotionList.php new file mode 100644 index 0000000..fca2252 --- /dev/null +++ b/src/service/taobao/bin/top/domain/PromotionList.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/PublisherOrderDto.php b/src/service/taobao/bin/top/domain/PublisherOrderDto.php new file mode 100644 index 0000000..0996c1a --- /dev/null +++ b/src/service/taobao/bin/top/domain/PublisherOrderDto.php @@ -0,0 +1,285 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RecommendItemList.php b/src/service/taobao/bin/top/domain/RecommendItemList.php new file mode 100644 index 0000000..32de96c --- /dev/null +++ b/src/service/taobao/bin/top/domain/RecommendItemList.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RegisterInfoDto.php b/src/service/taobao/bin/top/domain/RegisterInfoDto.php new file mode 100644 index 0000000..77e60b0 --- /dev/null +++ b/src/service/taobao/bin/top/domain/RegisterInfoDto.php @@ -0,0 +1,50 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Result.php b/src/service/taobao/bin/top/domain/Result.php new file mode 100644 index 0000000..3f481f2 --- /dev/null +++ b/src/service/taobao/bin/top/domain/Result.php @@ -0,0 +1,125 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Results.php b/src/service/taobao/bin/top/domain/Results.php new file mode 100644 index 0000000..5aad291 --- /dev/null +++ b/src/service/taobao/bin/top/domain/Results.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RightsInstanceCreateResult.php b/src/service/taobao/bin/top/domain/RightsInstanceCreateResult.php new file mode 100644 index 0000000..6fcfe6c --- /dev/null +++ b/src/service/taobao/bin/top/domain/RightsInstanceCreateResult.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RightsSendRelationRptDto.php b/src/service/taobao/bin/top/domain/RightsSendRelationRptDto.php new file mode 100644 index 0000000..fcb7a7e --- /dev/null +++ b/src/service/taobao/bin/top/domain/RightsSendRelationRptDto.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RightsSendRptDTO.php b/src/service/taobao/bin/top/domain/RightsSendRptDTO.php new file mode 100644 index 0000000..d40ede9 --- /dev/null +++ b/src/service/taobao/bin/top/domain/RightsSendRptDTO.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/RpcResult.php b/src/service/taobao/bin/top/domain/RpcResult.php new file mode 100644 index 0000000..33ff647 --- /dev/null +++ b/src/service/taobao/bin/top/domain/RpcResult.php @@ -0,0 +1,35 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/ServiceFeeDto.php b/src/service/taobao/bin/top/domain/ServiceFeeDto.php new file mode 100644 index 0000000..5af4400 --- /dev/null +++ b/src/service/taobao/bin/top/domain/ServiceFeeDto.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TbkSpread.php b/src/service/taobao/bin/top/domain/TbkSpread.php new file mode 100644 index 0000000..4e17c7e --- /dev/null +++ b/src/service/taobao/bin/top/domain/TbkSpread.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TbkSpreadRequest.php b/src/service/taobao/bin/top/domain/TbkSpreadRequest.php new file mode 100644 index 0000000..edda2fb --- /dev/null +++ b/src/service/taobao/bin/top/domain/TbkSpreadRequest.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TljInstanceReportDto.php b/src/service/taobao/bin/top/domain/TljInstanceReportDto.php new file mode 100644 index 0000000..bf51654 --- /dev/null +++ b/src/service/taobao/bin/top/domain/TljInstanceReportDto.php @@ -0,0 +1,70 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TopApiAfOrderOption.php b/src/service/taobao/bin/top/domain/TopApiAfOrderOption.php new file mode 100644 index 0000000..feffc0f --- /dev/null +++ b/src/service/taobao/bin/top/domain/TopApiAfOrderOption.php @@ -0,0 +1,70 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TopApiRefundRptOption.php b/src/service/taobao/bin/top/domain/TopApiRefundRptOption.php new file mode 100644 index 0000000..cb0e457 --- /dev/null +++ b/src/service/taobao/bin/top/domain/TopApiRefundRptOption.php @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TopDownloadRecordDo.php b/src/service/taobao/bin/top/domain/TopDownloadRecordDo.php new file mode 100644 index 0000000..86ca9bd --- /dev/null +++ b/src/service/taobao/bin/top/domain/TopDownloadRecordDo.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/TopItemQuery.php b/src/service/taobao/bin/top/domain/TopItemQuery.php new file mode 100644 index 0000000..6d6d7b6 --- /dev/null +++ b/src/service/taobao/bin/top/domain/TopItemQuery.php @@ -0,0 +1,45 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Trackparams.php b/src/service/taobao/bin/top/domain/Trackparams.php new file mode 100644 index 0000000..97d01e8 --- /dev/null +++ b/src/service/taobao/bin/top/domain/Trackparams.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/WordMapData.php b/src/service/taobao/bin/top/domain/WordMapData.php new file mode 100644 index 0000000..a5840ec --- /dev/null +++ b/src/service/taobao/bin/top/domain/WordMapData.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/domain/Youjiacouponinfo.php b/src/service/taobao/bin/top/domain/Youjiacouponinfo.php new file mode 100644 index 0000000..22b91c1 --- /dev/null +++ b/src/service/taobao/bin/top/domain/Youjiacouponinfo.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/fileTest.php b/src/service/taobao/bin/top/fileTest.php new file mode 100644 index 0000000..a4c6b54 --- /dev/null +++ b/src/service/taobao/bin/top/fileTest.php @@ -0,0 +1,26 @@ +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)); +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/request/AppipGetRequest.php b/src/service/taobao/bin/top/request/AppipGetRequest.php new file mode 100644 index 0000000..6d543f0 --- /dev/null +++ b/src/service/taobao/bin/top/request/AppipGetRequest.php @@ -0,0 +1,32 @@ +apiParas; + } + + public function check() + { + + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/request/FilesGetRequest.php b/src/service/taobao/bin/top/request/FilesGetRequest.php new file mode 100644 index 0000000..eacade8 --- /dev/null +++ b/src/service/taobao/bin/top/request/FilesGetRequest.php @@ -0,0 +1,81 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/HttpdnsGetRequest.php b/src/service/taobao/bin/top/request/HttpdnsGetRequest.php new file mode 100644 index 0000000..7f66e9c --- /dev/null +++ b/src/service/taobao/bin/top/request/HttpdnsGetRequest.php @@ -0,0 +1,32 @@ +apiParas; + } + + public function check() + { + + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/request/JuItemsSearchRequest.php b/src/service/taobao/bin/top/request/JuItemsSearchRequest.php new file mode 100644 index 0000000..37edb2f --- /dev/null +++ b/src/service/taobao/bin/top/request/JuItemsSearchRequest.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/KfcKeywordSearchRequest.php b/src/service/taobao/bin/top/request/KfcKeywordSearchRequest.php new file mode 100644 index 0000000..842c557 --- /dev/null +++ b/src/service/taobao/bin/top/request/KfcKeywordSearchRequest.php @@ -0,0 +1,85 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/OpenuidChangeRequest.php b/src/service/taobao/bin/top/request/OpenuidChangeRequest.php new file mode 100644 index 0000000..5eb2ca7 --- /dev/null +++ b/src/service/taobao/bin/top/request/OpenuidChangeRequest.php @@ -0,0 +1,65 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/OpenuidGetBymixnickRequest.php b/src/service/taobao/bin/top/request/OpenuidGetBymixnickRequest.php new file mode 100644 index 0000000..a9a2e63 --- /dev/null +++ b/src/service/taobao/bin/top/request/OpenuidGetBymixnickRequest.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/OpenuidGetBytradeRequest.php b/src/service/taobao/bin/top/request/OpenuidGetBytradeRequest.php new file mode 100644 index 0000000..88399fa --- /dev/null +++ b/src/service/taobao/bin/top/request/OpenuidGetBytradeRequest.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/OpenuidGetRequest.php b/src/service/taobao/bin/top/request/OpenuidGetRequest.php new file mode 100644 index 0000000..a5103f7 --- /dev/null +++ b/src/service/taobao/bin/top/request/OpenuidGetRequest.php @@ -0,0 +1,32 @@ +apiParas; + } + + public function check() + { + + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/request/TbkActivityInfoGetRequest.php b/src/service/taobao/bin/top/request/TbkActivityInfoGetRequest.php new file mode 100644 index 0000000..f32d553 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkActivityInfoGetRequest.php @@ -0,0 +1,113 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkCouponGetRequest.php b/src/service/taobao/bin/top/request/TbkCouponGetRequest.php new file mode 100644 index 0000000..6ee7a9f --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkCouponGetRequest.php @@ -0,0 +1,79 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgMaterialOptionalRequest.php b/src/service/taobao/bin/top/request/TbkDgMaterialOptionalRequest.php new file mode 100644 index 0000000..4fbd6ff --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgMaterialOptionalRequest.php @@ -0,0 +1,625 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgNewuserOrderGetRequest.php b/src/service/taobao/bin/top/request/TbkDgNewuserOrderGetRequest.php new file mode 100644 index 0000000..9e9c3ac --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgNewuserOrderGetRequest.php @@ -0,0 +1,130 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgNewuserOrderSumRequest.php b/src/service/taobao/bin/top/request/TbkDgNewuserOrderSumRequest.php new file mode 100644 index 0000000..ba60834 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgNewuserOrderSumRequest.php @@ -0,0 +1,132 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgOptimusMaterialRequest.php b/src/service/taobao/bin/top/request/TbkDgOptimusMaterialRequest.php new file mode 100644 index 0000000..168fe48 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgOptimusMaterialRequest.php @@ -0,0 +1,211 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgOptimusPromotionRequest.php b/src/service/taobao/bin/top/request/TbkDgOptimusPromotionRequest.php new file mode 100644 index 0000000..dc76ef1 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgOptimusPromotionRequest.php @@ -0,0 +1,98 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgPunishOrderGetRequest.php b/src/service/taobao/bin/top/request/TbkDgPunishOrderGetRequest.php new file mode 100644 index 0000000..9cc71d3 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgPunishOrderGetRequest.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgVegasSendReportRequest.php b/src/service/taobao/bin/top/request/TbkDgVegasSendReportRequest.php new file mode 100644 index 0000000..db032c1 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgVegasSendReportRequest.php @@ -0,0 +1,113 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgVegasTljCreateRequest.php b/src/service/taobao/bin/top/request/TbkDgVegasTljCreateRequest.php new file mode 100644 index 0000000..64b14d0 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgVegasTljCreateRequest.php @@ -0,0 +1,263 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkDgVegasTljInstanceReportRequest.php b/src/service/taobao/bin/top/request/TbkDgVegasTljInstanceReportRequest.php new file mode 100644 index 0000000..55756f2 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkDgVegasTljInstanceReportRequest.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkItemInfoGetRequest.php b/src/service/taobao/bin/top/request/TbkItemInfoGetRequest.php new file mode 100644 index 0000000..ea93cab --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkItemInfoGetRequest.php @@ -0,0 +1,80 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkOrderDetailsGetRequest.php b/src/service/taobao/bin/top/request/TbkOrderDetailsGetRequest.php new file mode 100644 index 0000000..c342bbd --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkOrderDetailsGetRequest.php @@ -0,0 +1,193 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkRelationRefundRequest.php b/src/service/taobao/bin/top/request/TbkRelationRefundRequest.php new file mode 100644 index 0000000..d5a9c0f --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkRelationRefundRequest.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkScInvitecodeGetRequest.php b/src/service/taobao/bin/top/request/TbkScInvitecodeGetRequest.php new file mode 100644 index 0000000..8b8d46c --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkScInvitecodeGetRequest.php @@ -0,0 +1,81 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkScPublisherInfoGetRequest.php b/src/service/taobao/bin/top/request/TbkScPublisherInfoGetRequest.php new file mode 100644 index 0000000..9d9ec17 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkScPublisherInfoGetRequest.php @@ -0,0 +1,145 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkScPublisherInfoSaveRequest.php b/src/service/taobao/bin/top/request/TbkScPublisherInfoSaveRequest.php new file mode 100644 index 0000000..a8446c5 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkScPublisherInfoSaveRequest.php @@ -0,0 +1,145 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkShopGetRequest.php b/src/service/taobao/bin/top/request/TbkShopGetRequest.php new file mode 100644 index 0000000..251b267 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkShopGetRequest.php @@ -0,0 +1,273 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkShopRecommendGetRequest.php b/src/service/taobao/bin/top/request/TbkShopRecommendGetRequest.php new file mode 100644 index 0000000..3f80398 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkShopRecommendGetRequest.php @@ -0,0 +1,97 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkSpreadGetRequest.php b/src/service/taobao/bin/top/request/TbkSpreadGetRequest.php new file mode 100644 index 0000000..430ec05 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkSpreadGetRequest.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TbkTpwdCreateRequest.php b/src/service/taobao/bin/top/request/TbkTpwdCreateRequest.php new file mode 100644 index 0000000..b36d8c0 --- /dev/null +++ b/src/service/taobao/bin/top/request/TbkTpwdCreateRequest.php @@ -0,0 +1,113 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TimeGetRequest.php b/src/service/taobao/bin/top/request/TimeGetRequest.php new file mode 100644 index 0000000..5c3d395 --- /dev/null +++ b/src/service/taobao/bin/top/request/TimeGetRequest.php @@ -0,0 +1,32 @@ +apiParas; + } + + public function check() + { + + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/request/TopAuthTokenCreateRequest.php b/src/service/taobao/bin/top/request/TopAuthTokenCreateRequest.php new file mode 100644 index 0000000..2475217 --- /dev/null +++ b/src/service/taobao/bin/top/request/TopAuthTokenCreateRequest.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TopAuthTokenRefreshRequest.php b/src/service/taobao/bin/top/request/TopAuthTokenRefreshRequest.php new file mode 100644 index 0000000..48d013f --- /dev/null +++ b/src/service/taobao/bin/top/request/TopAuthTokenRefreshRequest.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TopIpoutGetRequest.php b/src/service/taobao/bin/top/request/TopIpoutGetRequest.php new file mode 100644 index 0000000..4786ea8 --- /dev/null +++ b/src/service/taobao/bin/top/request/TopIpoutGetRequest.php @@ -0,0 +1,32 @@ +apiParas; + } + + public function check() + { + + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/request/TopSdkFeedbackUploadRequest.php b/src/service/taobao/bin/top/request/TopSdkFeedbackUploadRequest.php new file mode 100644 index 0000000..80045b8 --- /dev/null +++ b/src/service/taobao/bin/top/request/TopSdkFeedbackUploadRequest.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TopSecretGetRequest.php b/src/service/taobao/bin/top/request/TopSecretGetRequest.php new file mode 100644 index 0000000..e91acc5 --- /dev/null +++ b/src/service/taobao/bin/top/request/TopSecretGetRequest.php @@ -0,0 +1,80 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/request/TopSecretRegisterRequest.php b/src/service/taobao/bin/top/request/TopSecretRegisterRequest.php new file mode 100644 index 0000000..0de7bf6 --- /dev/null +++ b/src/service/taobao/bin/top/request/TopSecretRegisterRequest.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/security/MagicCrypt.php b/src/service/taobao/bin/top/security/MagicCrypt.php new file mode 100644 index 0000000..28c3ee5 --- /dev/null +++ b/src/service/taobao/bin/top/security/MagicCrypt.php @@ -0,0 +1,51 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/README.txt b/src/service/taobao/bin/top/security/README.txt new file mode 100644 index 0000000..455d616 --- /dev/null +++ b/src/service/taobao/bin/top/security/README.txt @@ -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 diff --git a/src/service/taobao/bin/top/security/SecretContext.php b/src/service/taobao/bin/top/security/SecretContext.php new file mode 100644 index 0000000..8f87970 --- /dev/null +++ b/src/service/taobao/bin/top/security/SecretContext.php @@ -0,0 +1,61 @@ +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() + { + + } + } +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/SecretCounterUtil.php b/src/service/taobao/bin/top/security/SecretCounterUtil.php new file mode 100644 index 0000000..114253c --- /dev/null +++ b/src/service/taobao/bin/top/security/SecretCounterUtil.php @@ -0,0 +1,97 @@ +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); + } + } + } +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/SecretGetRequest.php b/src/service/taobao/bin/top/security/SecretGetRequest.php new file mode 100644 index 0000000..0db24dc --- /dev/null +++ b/src/service/taobao/bin/top/security/SecretGetRequest.php @@ -0,0 +1,35 @@ +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; + } +} diff --git a/src/service/taobao/bin/top/security/SecurityClient.php b/src/service/taobao/bin/top/security/SecurityClient.php new file mode 100644 index 0000000..cf176de --- /dev/null +++ b/src/service/taobao/bin/top/security/SecurityClient.php @@ -0,0 +1,543 @@ +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; + } + } +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/SecurityTest.php b/src/service/taobao/bin/top/security/SecurityTest.php new file mode 100644 index 0000000..1ea923b --- /dev/null +++ b/src/service/taobao/bin/top/security/SecurityTest.php @@ -0,0 +1,68 @@ +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; + } +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/SecurityUtil.php b/src/service/taobao/bin/top/security/SecurityUtil.php new file mode 100644 index 0000000..df0b248 --- /dev/null +++ b/src/service/taobao/bin/top/security/SecurityUtil.php @@ -0,0 +1,589 @@ +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; + } + } +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/TopSdkFeedbackUploadRequest.php b/src/service/taobao/bin/top/security/TopSdkFeedbackUploadRequest.php new file mode 100644 index 0000000..2134ef9 --- /dev/null +++ b/src/service/taobao/bin/top/security/TopSdkFeedbackUploadRequest.php @@ -0,0 +1,62 @@ +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() + { + } + + public function putOtherTextParam($key, $value) { + $this->apiParas[$key] = $value; + $this->$key = $value; + } +} diff --git a/src/service/taobao/bin/top/security/YacCache.php b/src/service/taobao/bin/top/security/YacCache.php new file mode 100644 index 0000000..1388162 --- /dev/null +++ b/src/service/taobao/bin/top/security/YacCache.php @@ -0,0 +1,38 @@ +isEnable = false; + } + + public function getCache($key) + { + $key = md5($key); + if($this->isEnable){ + $yac = new Yac(); + return $yac->get($key); + }else{ + echo "yac is not enable ,skip getCache"; + } + } + + public function setCache($key,$var) + { + $key = md5($key); + if($this->isEnable){ + $yac = new Yac(); + $yac->set($key, $var); + }else{ + echo "yac is not enable ,skip setCache"; + } + } +} + +?> \ No newline at end of file diff --git a/src/service/taobao/bin/top/security/iCache.php b/src/service/taobao/bin/top/security/iCache.php new file mode 100644 index 0000000..6a24afe --- /dev/null +++ b/src/service/taobao/bin/top/security/iCache.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/src/service/taobao/bin/top/test.php b/src/service/taobao/bin/top/test.php new file mode 100644 index 0000000..9adfbd2 --- /dev/null +++ b/src/service/taobao/bin/top/test.php @@ -0,0 +1,14 @@ +appkey = '********'; + $c->secretKey = '*********************'; + + $req = new HttpdnsGetRequest; + + $req->putOtherTextParam("name","test"); + $req->putOtherTextParam("value",0); + + var_dump($c->execute($req)); +?> \ No newline at end of file