@@ -75,7 +75,7 @@ |
||
75 | 75 | public function check() |
76 | 76 | { |
77 | 77 | |
78 | - RequestCheckUtil::checkNotNull($this->content,"content"); |
|
78 | + RequestCheckUtil::checkNotNull($this->content, "content"); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | public function putOtherTextParam($key, $value) { |
@@ -38,7 +38,7 @@ |
||
38 | 38 | public function check() |
39 | 39 | { |
40 | 40 | |
41 | - RequestCheckUtil::checkNotNull($this->rightsId,"rightsId"); |
|
41 | + RequestCheckUtil::checkNotNull($this->rightsId, "rightsId"); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function putOtherTextParam($key, $value) { |
@@ -198,10 +198,10 @@ |
||
198 | 198 | public function check() |
199 | 199 | { |
200 | 200 | |
201 | - RequestCheckUtil::checkNotNull($this->adzoneId,"adzoneId"); |
|
202 | - RequestCheckUtil::checkNotNull($this->materialId,"materialId"); |
|
203 | - RequestCheckUtil::checkMaxValue($this->pageSize,100,"pageSize"); |
|
204 | - RequestCheckUtil::checkMinValue($this->pageSize,1,"pageSize"); |
|
201 | + RequestCheckUtil::checkNotNull($this->adzoneId, "adzoneId"); |
|
202 | + RequestCheckUtil::checkNotNull($this->materialId, "materialId"); |
|
203 | + RequestCheckUtil::checkMaxValue($this->pageSize, 100, "pageSize"); |
|
204 | + RequestCheckUtil::checkMinValue($this->pageSize, 1, "pageSize"); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | public function putOtherTextParam($key, $value) { |
@@ -38,7 +38,7 @@ |
||
38 | 38 | public function check() |
39 | 39 | { |
40 | 40 | |
41 | - RequestCheckUtil::checkNotNull($this->refreshToken,"refreshToken"); |
|
41 | + RequestCheckUtil::checkNotNull($this->refreshToken, "refreshToken"); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function putOtherTextParam($key, $value) { |
@@ -3,56 +3,56 @@ discard block |
||
3 | 3 | |
4 | 4 | private static $dnsconfig; |
5 | 5 | private static $syncDate = 0; |
6 | - private static $applicationVar ; |
|
6 | + private static $applicationVar; |
|
7 | 7 | private static $cfgDuration = 10; |
8 | 8 | |
9 | - public function __construct($appkey = "",$secretKey = ""){ |
|
9 | + public function __construct($appkey = "", $secretKey = "") { |
|
10 | 10 | ClusterTopClient::$applicationVar = new ApplicationVar; |
11 | 11 | $this->appkey = $appkey; |
12 | - $this->secretKey = $secretKey ; |
|
12 | + $this->secretKey = $secretKey; |
|
13 | 13 | $saveConfig = ClusterTopClient::$applicationVar->getValue(); |
14 | 14 | |
15 | - if($saveConfig){ |
|
15 | + if ($saveConfig) { |
|
16 | 16 | $tmpConfig = $saveConfig['dnsconfig']; |
17 | 17 | ClusterTopClient::$dnsconfig = $this->object_to_array($tmpConfig); |
18 | 18 | unset($tmpConfig); |
19 | 19 | |
20 | 20 | ClusterTopClient::$syncDate = $saveConfig['syncDate']; |
21 | - if(!ClusterTopClient::$syncDate) |
|
21 | + if (!ClusterTopClient::$syncDate) |
|
22 | 22 | ClusterTopClient::$syncDate = 0; |
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - public function __destruct(){ |
|
27 | - if(ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate){ |
|
28 | - ClusterTopClient::$applicationVar->setValue("dnsconfig",ClusterTopClient::$dnsconfig); |
|
29 | - ClusterTopClient::$applicationVar->setValue("syncDate",ClusterTopClient::$syncDate); |
|
26 | + public function __destruct() { |
|
27 | + if (ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate) { |
|
28 | + ClusterTopClient::$applicationVar->setValue("dnsconfig", ClusterTopClient::$dnsconfig); |
|
29 | + ClusterTopClient::$applicationVar->setValue("syncDate", ClusterTopClient::$syncDate); |
|
30 | 30 | ClusterTopClient::$applicationVar->write(); |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - public function execute($request = null, $session = null,$bestUrl = null){ |
|
34 | + public function execute($request = null, $session = null, $bestUrl = null) { |
|
35 | 35 | $currentDate = date('U'); |
36 | 36 | $syncDuration = $this->getDnsConfigSyncDuration(); |
37 | - $bestUrl = $this->getBestVipUrl($this->gatewayUrl,$request->getApiMethodName(),$session); |
|
38 | - if($currentDate - ClusterTopClient::$syncDate > $syncDuration * 60){ |
|
37 | + $bestUrl = $this->getBestVipUrl($this->gatewayUrl, $request->getApiMethodName(), $session); |
|
38 | + if ($currentDate-ClusterTopClient::$syncDate > $syncDuration*60) { |
|
39 | 39 | $httpdns = new HttpdnsGetRequest; |
40 | - ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns,null,$bestUrl)->result,true); |
|
40 | + ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns, null, $bestUrl)->result, true); |
|
41 | 41 | $syncDate = date('U'); |
42 | - ClusterTopClient::$syncDate = $syncDate ; |
|
42 | + ClusterTopClient::$syncDate = $syncDate; |
|
43 | 43 | } |
44 | - return parent::execute($request,$session,$bestUrl); |
|
44 | + return parent::execute($request, $session, $bestUrl); |
|
45 | 45 | } |
46 | 46 | |
47 | - private function getDnsConfigSyncDuration(){ |
|
48 | - if(ClusterTopClient::$cfgDuration){ |
|
47 | + private function getDnsConfigSyncDuration() { |
|
48 | + if (ClusterTopClient::$cfgDuration) { |
|
49 | 49 | return ClusterTopClient::$cfgDuration; |
50 | 50 | } |
51 | - if(!ClusterTopClient::$dnsconfig){ |
|
51 | + if (!ClusterTopClient::$dnsconfig) { |
|
52 | 52 | return ClusterTopClient::$cfgDuration; |
53 | 53 | } |
54 | 54 | $config = json_encode(ClusterTopClient::$dnsconfig); |
55 | - if(!$config){ |
|
55 | + if (!$config) { |
|
56 | 56 | return ClusterTopClient::$cfgDuration; |
57 | 57 | } |
58 | 58 | $config = ClusterTopClient::$dnsconfig['config']; |
@@ -62,59 +62,59 @@ discard block |
||
62 | 62 | return ClusterTopClient::$cfgDuration; |
63 | 63 | } |
64 | 64 | |
65 | - private function getBestVipUrl($url,$apiname = null,$session = null){ |
|
65 | + private function getBestVipUrl($url, $apiname = null, $session = null) { |
|
66 | 66 | $config = ClusterTopClient::$dnsconfig['config']; |
67 | 67 | $degrade = $config['degrade']; |
68 | - if(strcmp($degrade,'true') == 0){ |
|
68 | + if (strcmp($degrade, 'true') == 0) { |
|
69 | 69 | return $url; |
70 | 70 | } |
71 | - $currentEnv = $this->getEnvByApiName($apiname,$session); |
|
72 | - $vip = $this->getVipByEnv($url,$currentEnv); |
|
73 | - if($vip) |
|
71 | + $currentEnv = $this->getEnvByApiName($apiname, $session); |
|
72 | + $vip = $this->getVipByEnv($url, $currentEnv); |
|
73 | + if ($vip) |
|
74 | 74 | return $vip; |
75 | 75 | return $url; |
76 | 76 | } |
77 | 77 | |
78 | - private function getVipByEnv($comUrl,$currentEnv){ |
|
78 | + private function getVipByEnv($comUrl, $currentEnv) { |
|
79 | 79 | $urlSchema = parse_url($comUrl); |
80 | - if(!$urlSchema) |
|
80 | + if (!$urlSchema) |
|
81 | 81 | return null; |
82 | - if(!ClusterTopClient::$dnsconfig['env']) |
|
82 | + if (!ClusterTopClient::$dnsconfig['env']) |
|
83 | 83 | return null; |
84 | 84 | |
85 | - if(!array_key_exists($currentEnv,ClusterTopClient::$dnsconfig['env'])) |
|
85 | + if (!array_key_exists($currentEnv, ClusterTopClient::$dnsconfig['env'])) |
|
86 | 86 | return null; |
87 | 87 | |
88 | 88 | $hostList = ClusterTopClient::$dnsconfig['env'][$currentEnv]; |
89 | - if(!$hostList) |
|
90 | - return null ; |
|
89 | + if (!$hostList) |
|
90 | + return null; |
|
91 | 91 | |
92 | 92 | $vipList = null; |
93 | 93 | foreach ($hostList as $key => $value) { |
94 | - if(strcmp($key,$urlSchema['host']) == 0 && strcmp($value['proto'],$urlSchema['scheme']) == 0){ |
|
94 | + if (strcmp($key, $urlSchema['host']) == 0 && strcmp($value['proto'], $urlSchema['scheme']) == 0) { |
|
95 | 95 | $vipList = $value; |
96 | 96 | break; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | $vip = $this->getRandomWeightElement($vipList['vip']); |
100 | 100 | |
101 | - if($vip){ |
|
101 | + if ($vip) { |
|
102 | 102 | return $urlSchema['scheme']."://".$vip.$urlSchema['path']; |
103 | 103 | } |
104 | 104 | return null; |
105 | 105 | } |
106 | 106 | |
107 | - private function getEnvByApiName($apiName,$session=""){ |
|
107 | + private function getEnvByApiName($apiName, $session = "") { |
|
108 | 108 | $apiCfgArray = ClusterTopClient::$dnsconfig['api']; |
109 | - if($apiCfgArray){ |
|
110 | - if(array_key_exists($apiName,$apiCfgArray)){ |
|
109 | + if ($apiCfgArray) { |
|
110 | + if (array_key_exists($apiName, $apiCfgArray)) { |
|
111 | 111 | $apiCfg = $apiCfgArray[$apiName]; |
112 | - if(array_key_exists('user',$apiCfg)){ |
|
112 | + if (array_key_exists('user', $apiCfg)) { |
|
113 | 113 | $userFlag = $apiCfg['user']; |
114 | 114 | $flag = $this->getUserFlag($session); |
115 | - if($userFlag && $flag ){ |
|
116 | - return $this->getEnvBySessionFlag($userFlag,$flag); |
|
117 | - }else{ |
|
115 | + if ($userFlag && $flag) { |
|
116 | + return $this->getEnvBySessionFlag($userFlag, $flag); |
|
117 | + }else { |
|
118 | 118 | return $this->getRandomWeightElement($apiCfg['rule']); |
119 | 119 | } |
120 | 120 | } |
@@ -123,42 +123,42 @@ discard block |
||
123 | 123 | return $this->getDeafultEnv(); |
124 | 124 | } |
125 | 125 | |
126 | - private function getUserFlag($session){ |
|
127 | - if($session && strlen($session) > 5){ |
|
128 | - if($session[0] == '6' || $session[0] == '7'){ |
|
129 | - return $session[strlen($session) -1]; |
|
130 | - }else if($session[0] == '5' || $session[0] == '8'){ |
|
126 | + private function getUserFlag($session) { |
|
127 | + if ($session && strlen($session) > 5) { |
|
128 | + if ($session[0] == '6' || $session[0] == '7') { |
|
129 | + return $session[strlen($session)-1]; |
|
130 | + }else if ($session[0] == '5' || $session[0] == '8') { |
|
131 | 131 | return $session[5]; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | return null; |
135 | 135 | } |
136 | 136 | |
137 | - private function getEnvBySessionFlag($targetConfig,$flag){ |
|
138 | - if($flag){ |
|
137 | + private function getEnvBySessionFlag($targetConfig, $flag) { |
|
138 | + if ($flag) { |
|
139 | 139 | $userConf = ClusterTopClient::$dnsconfig['user']; |
140 | 140 | $cfgArry = $userConf[$targetConfig]; |
141 | 141 | foreach ($cfgArry as $key => $value) { |
142 | - if(in_array($flag,$value)) |
|
142 | + if (in_array($flag, $value)) |
|
143 | 143 | return $key; |
144 | 144 | } |
145 | - }else{ |
|
145 | + }else { |
|
146 | 146 | return null; |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | - private function getRandomWeightElement($elements){ |
|
150 | + private function getRandomWeightElement($elements) { |
|
151 | 151 | $totalWeight = 0; |
152 | - if($elements){ |
|
152 | + if ($elements) { |
|
153 | 153 | foreach ($elements as $ele) { |
154 | 154 | $weight = $this->getElementWeight($ele); |
155 | - $r = $this->randomFloat() * ($weight + $totalWeight); |
|
156 | - if($r >= $totalWeight){ |
|
155 | + $r = $this->randomFloat()*($weight+$totalWeight); |
|
156 | + if ($r >= $totalWeight) { |
|
157 | 157 | $selected = $ele; |
158 | 158 | } |
159 | 159 | $totalWeight += $weight; |
160 | 160 | } |
161 | - if($selected){ |
|
161 | + if ($selected) { |
|
162 | 162 | return $this->getElementValue($selected); |
163 | 163 | } |
164 | 164 | } |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | |
167 | 167 | } |
168 | 168 | |
169 | - private function getElementWeight($ele){ |
|
169 | + private function getElementWeight($ele) { |
|
170 | 170 | $params = explode('|', $ele); |
171 | 171 | return floatval($params[1]); |
172 | 172 | } |
173 | - private function getElementValue($ele){ |
|
173 | + private function getElementValue($ele) { |
|
174 | 174 | $params = explode('|', $ele); |
175 | 175 | return $params[0]; |
176 | 176 | } |
177 | 177 | |
178 | - private function getDeafultEnv(){ |
|
178 | + private function getDeafultEnv() { |
|
179 | 179 | return ClusterTopClient::$dnsconfig['config']['def_env']; |
180 | 180 | } |
181 | 181 | |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | |
186 | 186 | private function object_to_array($obj) |
187 | 187 | { |
188 | - $_arr= is_object($obj) ? get_object_vars($obj) : $obj; |
|
189 | - foreach($_arr as $key=> $val) |
|
188 | + $_arr = is_object($obj) ? get_object_vars($obj) : $obj; |
|
189 | + foreach ($_arr as $key=> $val) |
|
190 | 190 | { |
191 | - $val= (is_array($val) || is_object($val))? $this->object_to_array($val) : $val; |
|
191 | + $val = (is_array($val) || is_object($val)) ? $this->object_to_array($val) : $val; |
|
192 | 192 | $arr[$key] = $val; |
193 | 193 | } |
194 | 194 | return$arr; |
195 | 195 | } |
196 | 196 | |
197 | - private function randomFloat($min = 0, $max = 1) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); } |
|
197 | + private function randomFloat($min = 0, $max = 1) { return $min+mt_rand()/mt_getrandmax()*($max-$min); } |
|
198 | 198 | } |
199 | 199 | ?> |
200 | 200 | \ No newline at end of file |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | |
10 | 10 | public $format = "json"; |
11 | 11 | |
12 | - public $connectTimeout = 3000;//3秒 |
|
12 | + public $connectTimeout = 3000; //3秒 |
|
13 | 13 | |
14 | - public $readTimeout = 80000;//80秒 |
|
14 | + public $readTimeout = 80000; //80秒 |
|
15 | 15 | |
16 | 16 | /** 是否打开入参check**/ |
17 | 17 | public $checkRequest = true; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | public function execute($request) |
28 | 28 | { |
29 | - if($this->checkRequest) { |
|
29 | + if ($this->checkRequest) { |
|
30 | 30 | try { |
31 | 31 | $request->check(); |
32 | 32 | } catch (Exception $e) { |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $apiParams = $request->getApiParas(); |
40 | 40 | //组装系统参数 |
41 | 41 | $apiParams["AccessKeyId"] = $this->accessKeyId; |
42 | - $apiParams["Format"] = $this->format;// |
|
42 | + $apiParams["Format"] = $this->format; // |
|
43 | 43 | $apiParams["SignatureMethod"] = $this->signatureMethod; |
44 | 44 | $apiParams["SignatureVersion"] = $this->signatureVersion; |
45 | 45 | $apiParams["SignatureNonce"] = uniqid(); |
@@ -47,17 +47,17 @@ discard block |
||
47 | 47 | $apiParams["TimeStamp"] = date($this->dateTimeFormat); |
48 | 48 | $apiParams["partner_id"] = $this->sdkVersion; |
49 | 49 | |
50 | - $apiNameArray = split("\.", $request->getApiMethodName()); |
|
50 | + $apiNameArray = split("\.", $request->getApiMethodName()); |
|
51 | 51 | $apiParams["Action"] = $apiNameArray[3]; |
52 | 52 | $apiParams["Version"] = $apiNameArray[4]; |
53 | 53 | //签名 |
54 | 54 | $apiParams["Signature"] = $this->computeSignature($apiParams, $this->accessKeySecret); |
55 | 55 | |
56 | 56 | //系统参数放入GET请求串 |
57 | - $requestUrl = rtrim($this->serverUrl,"/") . "/?"; |
|
57 | + $requestUrl = rtrim($this->serverUrl, "/")."/?"; |
|
58 | 58 | foreach ($apiParams as $apiParamKey => $apiParamValue) |
59 | 59 | { |
60 | - $requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&"; |
|
60 | + $requestUrl .= "$apiParamKey=".urlencode($apiParamValue)."&"; |
|
61 | 61 | } |
62 | 62 | $requestUrl = substr($requestUrl, 0, -1); |
63 | 63 | //发起HTTP请求 |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | } |
68 | 68 | catch (Exception $e) |
69 | 69 | { |
70 | - $this->logCommunicationError($apiParams["Action"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage()); |
|
70 | + $this->logCommunicationError($apiParams["Action"], $requestUrl, "HTTP_ERROR_".$e->getCode(), $e->getMessage()); |
|
71 | 71 | if ("json" == $this->format) |
72 | 72 | { |
73 | 73 | return json_decode($e->getMessage()); |
74 | 74 | } |
75 | - else if("xml" == $this->format) |
|
75 | + else if ("xml" == $this->format) |
|
76 | 76 | { |
77 | 77 | return @simplexml_load_string($e->getMessage()); |
78 | 78 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $respWellFormed = true; |
89 | 89 | } |
90 | 90 | } |
91 | - else if("xml" == $this->format) |
|
91 | + else if ("xml" == $this->format) |
|
92 | 92 | { |
93 | 93 | $respObject = @simplexml_load_string($resp); |
94 | 94 | if (false !== $respObject) |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | //返回的HTTP文本不是标准JSON或者XML,记下错误日志 |
101 | 101 | if (false === $respWellFormed) |
102 | 102 | { |
103 | - $this->logCommunicationError($apiParams["Action"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp); |
|
103 | + $this->logCommunicationError($apiParams["Action"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp); |
|
104 | 104 | $result->code = 0; |
105 | 105 | $result->message = "HTTP_RESPONSE_NOT_WELL_FORMED"; |
106 | 106 | return $result; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | if (isset($respObject->code)) |
111 | 111 | { |
112 | 112 | $logger = new LtLogger; |
113 | - $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log"; |
|
113 | + $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_biz_err_".$this->appkey."_".date("Y-m-d").".log"; |
|
114 | 114 | $logger->log(array( |
115 | 115 | date("Y-m-d H:i:s"), |
116 | 116 | $resp |
@@ -127,19 +127,19 @@ discard block |
||
127 | 127 | } |
128 | 128 | $inflector = new LtInflector; |
129 | 129 | $inflector->conf["separator"] = "."; |
130 | - $requestClassName = ucfirst($inflector->camelize(substr($paramsArray["Action"], 7))) . "Request"; |
|
130 | + $requestClassName = ucfirst($inflector->camelize(substr($paramsArray["Action"], 7)))."Request"; |
|
131 | 131 | if (!class_exists($requestClassName)) |
132 | 132 | { |
133 | - trigger_error("No such api: " . $paramsArray["Action"]); |
|
133 | + trigger_error("No such api: ".$paramsArray["Action"]); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | $req = new $requestClassName; |
137 | - foreach($paramsArray as $paraKey => $paraValue) |
|
137 | + foreach ($paramsArray as $paraKey => $paraValue) |
|
138 | 138 | { |
139 | 139 | $inflector->conf["separator"] = "_"; |
140 | 140 | $setterMethodName = $inflector->camelize($paraKey); |
141 | 141 | $inflector->conf["separator"] = "."; |
142 | - $setterMethodName = "set" . $inflector->camelize($setterMethodName); |
|
142 | + $setterMethodName = "set".$inflector->camelize($setterMethodName); |
|
143 | 143 | if (method_exists($req, $setterMethodName)) |
144 | 144 | { |
145 | 145 | $req->$setterMethodName($paraValue); |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | |
166 | 166 | // 生成规范化请求字符串 |
167 | 167 | $canonicalizedQueryString = ''; |
168 | - foreach($parameters as $key => $value) |
|
168 | + foreach ($parameters as $key => $value) |
|
169 | 169 | { |
170 | - $canonicalizedQueryString .= '&' . $this->percentEncode($key) |
|
171 | - . '=' . $this->percentEncode($value); |
|
170 | + $canonicalizedQueryString .= '&'.$this->percentEncode($key) |
|
171 | + . '='.$this->percentEncode($value); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // 生成用于计算签名的字符串 stringToSign |
175 | - $stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1)); |
|
175 | + $stringToSign = 'GET&%2F&'.$this->percentencode(substr($canonicalizedQueryString, 1)); |
|
176 | 176 | |
177 | 177 | // 计算签名,注意accessKeySecret后面要加上字符'&' |
178 | - $signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret . '&', true)); |
|
178 | + $signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret.'&', true)); |
|
179 | 179 | return $signature; |
180 | 180 | } |
181 | 181 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout); |
193 | 193 | } |
194 | 194 | //https 请求 |
195 | - if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) { |
|
195 | + if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { |
|
196 | 196 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
197 | 197 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
198 | 198 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | $postMultipart = false; |
204 | 204 | foreach ($postFields as $k => $v) |
205 | 205 | { |
206 | - if("@" != substr($v, 0, 1))//判断是不是文件上传 |
|
206 | + if ("@" != substr($v, 0, 1))//判断是不是文件上传 |
|
207 | 207 | { |
208 | - $postBodyString .= "$k=" . urlencode($v) . "&"; |
|
208 | + $postBodyString .= "$k=".urlencode($v)."&"; |
|
209 | 209 | } |
210 | 210 | else//文件上传用multipart/form-data,否则用www-form-urlencoded |
211 | 211 | { |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | } |
221 | 221 | else |
222 | 222 | { |
223 | - curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1)); |
|
223 | + curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1)); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | $reponse = curl_exec($ch); |
227 | 227 | |
228 | 228 | if (curl_errno($ch)) |
229 | 229 | { |
230 | - throw new Exception(curl_error($ch),0); |
|
230 | + throw new Exception(curl_error($ch), 0); |
|
231 | 231 | } |
232 | 232 | curl_close($ch); |
233 | 233 | return $reponse; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | { |
238 | 238 | $localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI"; |
239 | 239 | $logger = new LtLogger; |
240 | - $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->accessKeyId . "_" . date("Y-m-d") . ".log"; |
|
240 | + $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_comm_err_".$this->accessKeyId."_".date("Y-m-d").".log"; |
|
241 | 241 | $logger->conf["separator"] = "^_^"; |
242 | 242 | $logData = array( |
243 | 243 | date("Y-m-d H:i:s"), |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $this->sdkVersion, |
249 | 249 | $requestUrl, |
250 | 250 | $errorCode, |
251 | - str_replace("\n","",$responseTxt) |
|
251 | + str_replace("\n", "", $responseTxt) |
|
252 | 252 | ); |
253 | 253 | $logger->log($logData); |
254 | 254 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Autoloader{ |
|
3 | +class Autoloader { |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * 类库自动加载,写死路径,确保不加载其他文件。 |
@@ -9,65 +9,65 @@ discard block |
||
9 | 9 | */ |
10 | 10 | public static function autoload($class) { |
11 | 11 | $name = $class; |
12 | - if(false !== strpos($name,'\\')){ |
|
12 | + if (false !== strpos($name, '\\')) { |
|
13 | 13 | $name = strstr($class, '\\', true); |
14 | 14 | } |
15 | 15 | |
16 | 16 | $filename = TOP_AUTOLOADER_PATH."/top/".$name.".php"; |
17 | - if(is_file($filename)) { |
|
17 | + if (is_file($filename)) { |
|
18 | 18 | include $filename; |
19 | 19 | return; |
20 | 20 | } |
21 | 21 | |
22 | 22 | $filename = TOP_AUTOLOADER_PATH."/top/request/".$name.".php"; |
23 | - if(is_file($filename)) { |
|
23 | + if (is_file($filename)) { |
|
24 | 24 | include $filename; |
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
28 | 28 | $filename = TOP_AUTOLOADER_PATH."/top/domain/".$name.".php"; |
29 | - if(is_file($filename)) { |
|
29 | + if (is_file($filename)) { |
|
30 | 30 | include $filename; |
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $filename = TOP_AUTOLOADER_PATH."/aliyun/".$name.".php"; |
35 | - if(is_file($filename)) { |
|
35 | + if (is_file($filename)) { |
|
36 | 36 | include $filename; |
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $filename = TOP_AUTOLOADER_PATH."/aliyun/request/".$name.".php"; |
41 | - if(is_file($filename)) { |
|
41 | + if (is_file($filename)) { |
|
42 | 42 | include $filename; |
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | 46 | $filename = TOP_AUTOLOADER_PATH."/aliyun/domain/".$name.".php"; |
47 | - if(is_file($filename)) { |
|
47 | + if (is_file($filename)) { |
|
48 | 48 | include $filename; |
49 | 49 | return; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $filename = TOP_AUTOLOADER_PATH."/dingtalk/".$name.".php"; |
53 | - if(is_file($filename)) { |
|
53 | + if (is_file($filename)) { |
|
54 | 54 | include $filename; |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | $filename = TOP_AUTOLOADER_PATH."/dingtalk/request/".$name.".php"; |
58 | - if(is_file($filename)) { |
|
58 | + if (is_file($filename)) { |
|
59 | 59 | include $filename; |
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $filename = TOP_AUTOLOADER_PATH."/dingtalk/domain/".$name.".php"; |
64 | - if(is_file($filename)) { |
|
64 | + if (is_file($filename)) { |
|
65 | 65 | include $filename; |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | 69 | $filename = TOP_AUTOLOADER_PATH."/QimenCloud/".$name.".php"; |
70 | - if(is_file($filename)) { |
|
70 | + if (is_file($filename)) { |
|
71 | 71 | include $filename; |
72 | 72 | return; |
73 | 73 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace DtApp\ThinkLibrary\service\taobao; |
4 | 4 | |
5 | -require_once __DIR__ . '/bin/TopSdk.php'; |
|
5 | +require_once __DIR__.'/bin/TopSdk.php'; |
|
6 | 6 | |
7 | 7 | use DtApp\ThinkLibrary\Service; |
8 | 8 | use TbkScInvitecodeGetRequest; |
@@ -942,20 +942,20 @@ discard block |
||
942 | 942 | $sign = $this->createSign(); |
943 | 943 | //组织参数 |
944 | 944 | $strParam = $this->createStrParam(); |
945 | - $strParam .= 'sign=' . $sign; |
|
945 | + $strParam .= 'sign='.$sign; |
|
946 | 946 | //访问服务 |
947 | 947 | if ($this->protocol === 'http') { |
948 | 948 | if (empty($this->sandbox)) { |
949 | - $url = 'http://gw.api.taobao.com/router/rest?' . $strParam; |
|
950 | - } else { |
|
951 | - $url = 'http://gw.api.tbsandbox.com/router/rest?' . $strParam; |
|
949 | + $url = 'http://gw.api.taobao.com/router/rest?'.$strParam; |
|
950 | + }else { |
|
951 | + $url = 'http://gw.api.tbsandbox.com/router/rest?'.$strParam; |
|
952 | 952 | } |
953 | 953 | } |
954 | 954 | if ($this->protocol === 'https') { |
955 | 955 | if (empty($this->sandbox)) { |
956 | - $url = 'https://eco.taobao.com/router/rest?' . $strParam; |
|
957 | - } else { |
|
958 | - $url = 'https://gw.api.tbsandbox.com/router/rest?' . $strParam; |
|
956 | + $url = 'https://eco.taobao.com/router/rest?'.$strParam; |
|
957 | + }else { |
|
958 | + $url = 'https://gw.api.tbsandbox.com/router/rest?'.$strParam; |
|
959 | 959 | } |
960 | 960 | } |
961 | 961 | $result = file_get_contents($url); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | ksort($this->param); |
981 | 981 | foreach ($this->param as $key => $val) { |
982 | 982 | if ($key !== '' && $val !== '') { |
983 | - $sign .= $key . $val; |
|
983 | + $sign .= $key.$val; |
|
984 | 984 | } |
985 | 985 | } |
986 | 986 | $sign .= $this->app_secret; |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | $strParam = ''; |
998 | 998 | foreach ($this->param as $key => $val) { |
999 | 999 | if ($key !== '' && $val !== '') { |
1000 | - $strParam .= $key . '=' . urlencode($val) . '&'; |
|
1000 | + $strParam .= $key.'='.urlencode($val).'&'; |
|
1001 | 1001 | } |
1002 | 1002 | } |
1003 | 1003 | return $strParam; |