首页 > 代码库 > 关于阿里云物流查询SDK

关于阿里云物流查询SDK

在阿里云官网我们找到sdk(在文件夹之中有)

技术分享

解压之后就是酱紫的,其实很简单,ShowapiRequest.php那儿有个autoload方法将所有其他文件夹的类加载进去

反正不管他:

在THINKPHP之中,为了方便,将autoload方法去掉,手动引入所有类

技术分享

注册在命名空间:

技术分享

控制器:

技术分享

上面的控制器调用;本来想将类放在Vendor文件夹下面,但是总是类找不到,索性就酱紫;

 类文件:

  1 <?php
  2 namespace Com\Pay;
  3 class ShowapiRequest
  4 {
  5     
  6     
  7     protected  $appKey ;
  8     protected  $appSecret  ;
  9     protected  $host;
 10     protected  $path; 
 11     protected  $querys = array();
 12 
 13     
 14     function  __construct($appKey, $appSecret, $url  )
 15     {
 16         $this->appKey = $appKey;
 17         $this->appSecret = $appSecret;
 18         $ind= strpos($url,"/",8) ;//目的是截取path
 19         $this->path=substr($url,$ind);
 20         $this->host=substr($url,0,$ind);
 21         
 22     }
 23 
 24     
 25     
 26     
 27     public function addTextPara($key, $value)
 28     {
 29         $this->querys[$key] = $value;
 30         return $this;
 31     }
 32 
 33     /**
 34     *method=GET请求示例
 35     */
 36     public function get() {
 37         //echo ($this->host."\r\n");
 38         //echo ($this->path."\r\n");
 39         $request= new HttpRequest($this->host,$this->path, HttpMethod::GET, $this->appKey, $this->appSecret);
 40         foreach ($this->querys as $itemKey => $itemValue) {
 41                  //echo ($itemValue."\r\n");
 42                  $request->setQuery($itemKey, $itemValue);
 43         }
 44             
 45         $request->setHeader(HttpHeader::HTTP_HEADER_CONTENT_TYPE, ContentType::CONTENT_TYPE_TEXT);
 46         $request->setHeader(HttpHeader::HTTP_HEADER_ACCEPT, ContentType::CONTENT_TYPE_TEXT);
 47         $request->setSignHeader(SystemHeader::X_CA_TIMESTAMP);
 48         $response = HttpClient::execute($request);
 49         echo ("server return is:\r\n" );
 50         echo($response->getContent()."\r\n" );
 51         
 52         /*
 53         $result = json_decode($response->getBody()."\r\n");
 54         echo ("current temperatur is:\r\n");
 55         echo($result->showapi_res_body->now->temperature."\r\n" );
 56         return  $result;*/
 57     }
 58 
 59     /**
 60     *method=POST且是表单提交,请求示例
 61     */
 62     public function post() {
 63         $request =  new HttpRequest($this->host,$this->path, HttpMethod::POST, $this->appKey, $this->appSecret);
 64         foreach ($this->querys as $itemKey => $itemValue) {
 65                 echo ("aaaaaaaaaaa:\r\n" );
 66                 echo ($itemKey."\r\n");
 67                  echo ($itemValue."\r\n");
 68                  $request->setQuery($itemKey, $itemValue);
 69         }
 70         
 71         $request->setHeader(HttpHeader::HTTP_HEADER_CONTENT_TYPE, ContentType::CONTENT_TYPE_FORM);
 72         $request->setHeader(HttpHeader::HTTP_HEADER_ACCEPT, ContentType::CONTENT_TYPE_JSON);
 73         $request->setSignHeader(SystemHeader::X_CA_TIMESTAMP);
 74         $response = HttpClient::execute($request);
 75         echo ("server return is:\r\n" );
 76         echo($response->getBody()."\r\n" );
 77         
 78         $result = json_decode($response->getBody()."\r\n");
 79         echo ("current temperatur is:\r\n");
 80         echo($result->showapi_res_code."\r\n" );
 81         return  $result;
 82     }
 83 
 84      
 85     
 86      
 87 }
 88 
 89 class Constants
 90 {
 91     //签名算法HmacSha256
 92     const HMAC_SHA256 = "HmacSHA256";
 93     //编码UTF-8
 94     const ENCODING = "UTF-8";
 95     //UserAgent
 96     const USER_AGENT = "demo/aliyun/java";
 97     //换行符
 98     const LF = "\n";
 99     //分隔符1
100     const SPE1 = ",";
101     //分隔符2
102     const SPE2 = ":";
103     //默认请求超时时间,单位毫秒
104     const DEFAULT_TIMEOUT = 1000;
105     //参与签名的系统Header前缀,只有指定前缀的Header才会参与到签名中
106     const CA_HEADER_TO_SIGN_PREFIX_SYSTEM = "X-Ca-";
107 }
108 
109 class ContentType {
110     //表单类型Content-Type
111     const CONTENT_TYPE_FORM = "application/x-www-form-urlencoded; charset=UTF-8";
112     // 流类型Content-Type
113     const CONTENT_TYPE_STREAM = "application/octet-stream; charset=UTF-8";
114     //JSON类型Content-Type
115     const CONTENT_TYPE_JSON = "application/json; charset=UTF-8";
116     //XML类型Content-Type
117     const CONTENT_TYPE_XML = "application/xml; charset=UTF-8";
118     //文本类型Content-Type
119     const CONTENT_TYPE_TEXT = "application/text; charset=UTF-8";
120 }
121 
122 class HttpHeader {
123     //请求Header Accept
124     const HTTP_HEADER_ACCEPT = "Accept";
125     //请求Body内容MD5 Header
126     const HTTP_HEADER_CONTENT_MD5 = "Content-MD5";
127     //请求Header Content-Type
128     const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
129     //请求Header UserAgent
130     const HTTP_HEADER_USER_AGENT = "User-Agent";
131     //请求Header Date
132     const HTTP_HEADER_DATE = "Date";
133 }
134 class HttpMethod {
135     //GET
136     const GET = "GET";
137     //POST
138     const POST = "POST";
139     //PUT
140     const PUT = "PUT";
141     //DELETE
142     const DELETE = "DELETE";
143     //HEAD
144     const HEAD = "HEAD";
145 }
146 class HttpSchema {
147     //HTTP
148     const HTTP = "http://";
149     //HTTPS
150     const HTTPS = "https://";
151 
152 }
153 class SystemHeader {
154     //签名Header
155     const X_CA_SIGNATURE = "X-Ca-Signature";
156     //所有参与签名的Header
157     const X_CA_SIGNATURE_HEADERS = "X-Ca-Signature-Headers";
158     //请求时间戳
159     const X_CA_TIMESTAMP = "X-Ca-Timestamp";
160     //请求放重放Nonce,15分钟内保持唯一,建议使用UUID
161     const X_CA_NONCE = "X-Ca-Nonce";
162     //APP KEY
163     const X_CA_KEY = "X-Ca-Key";
164 }
165 class HttpClient
166 {
167     private static $connectTimeout = 30000;//30 second
168     private static $readTimeout = 80000;//80 second
169     
170     public static function execute($request)
171     {
172         return HttpUtil::send($request, self::$readTimeout, self::$connectTimeout);
173     }
174 }
175 
176 class HttpRequest
177 {
178     protected  $host;
179     protected  $path;
180     protected  $method;
181     protected  $appKey;
182     protected  $appSecret;
183     protected  $headers = array();
184     protected  $signHeaders = array();
185     protected  $querys = array();
186     protected  $bodys = array();
187 
188     function  __construct($host, $path, $method, $appKey, $appSecret)
189     {
190         $this->host = $host;
191         $this->path = $path;
192         $this->method = $method;
193         $this->appKey = $appKey;
194         $this->appSecret = $appSecret;
195     }
196 
197     public function getHeaders()
198     {
199         return $this->headers;
200     }
201 
202     public function setHeader($key, $value)
203     {
204         if (null == $this->headers) {
205             $this->headers = array();
206         }
207         $this->headers[$key] = $value;
208     }
209 
210     public function getHeader($key)
211     {
212         return $this->headers[$key];
213     }
214 
215     public function removeHeader($key)
216     {
217         unset($this->headers[$key]);
218     }
219 
220     public function getQuerys()
221     {
222         return $this->querys;
223     }
224 
225     public function setQuery($key, $value)
226     {
227         if (null == $this->querys) {
228             $this->querys = array();
229         }
230         $this->querys[$key] = $value;
231     }
232     
233      
234 
235     public function getQuery($key)
236     {
237         return $this->querys[$key];
238     }
239 
240     public function removeQuery($key)
241     {
242         unset($this->querys[$key]);
243     }
244 
245     public function getBodys()
246     {
247         return $this->bodys;
248     }
249 
250     public function setBody($key, $value)
251     {
252         if (null == $this->bodys) {
253             $this->bodys = array();
254         }
255         $this->bodys[$key] = $value;
256     }
257 
258     public function getBody($key)
259     {
260         return $this->bodys[$key];
261     }
262 
263     public function removeBody($key)
264     {
265         unset($this->bodys[$key]);
266     }
267 
268     public function setBodyStream($value)
269     {
270         if (null == $this->bodys) {
271             $this->bodys = array();
272         }
273         $this->bodys[""] = $value;
274     }
275 
276     public function setBodyString($value)
277     {
278         if (null == $this->bodys) {
279             $this->bodys = array();
280         }
281         $this->bodys[""] = $value;
282     }
283 
284 
285     public function getSignHeaders()
286     {
287         return $this->signHeaders;
288     }
289 
290     public function setSignHeader($value)
291     {
292         if (null == $this->signHeaders) {
293             $this->signHeaders = array();
294         }
295         if (!in_array($value, $this->signHeaders)) {
296             array_push($this->signHeaders, $value);
297         }
298     }
299 
300     public function removeSignHeader($value)
301     {
302         unset($this->signHeaders[$value]);
303     }
304 
305     public function getHost()
306     {
307         return $this->host;
308     }
309     
310     public function setHost($host)
311     {
312         $this->host = $host;
313     }
314 
315     public function getPath()
316     {
317         return $this->path;
318     }
319     
320     public function setPath($path)
321     {
322         $this->path = $path;
323     }
324 
325     public function getMethod()
326     {
327         return $this->method;
328     }
329     
330     public function setMethod($method)
331     {
332         $this->method = $method;
333     }
334 
335     public function getAppKey()
336     {
337         return $this->appKey;
338     }
339     
340     public function setAppKey($appKey)
341     {
342         $this->appKey = $appKey;
343     }
344 
345     public function getAppSecret()
346     {
347         return $this->appSecret;
348     }
349     
350     public function setAppSecret($appSecret)
351     {
352         $this->appSecret = $appSecret;
353     }
354 }
355 
356 class HttpResponse
357 {
358     private $content;
359     private $body;
360     private $header;
361     private $requestId;
362     private $errorMessage;
363     private $contentType;
364     private $httpStatusCode;
365     
366     public function getContent()
367     {
368         return $this->content;
369     }
370 
371     public function setContent($content)
372     {
373         $this->content = $content;
374     }
375 
376     public function setHeader($header)
377     {
378         $this->header = $header;
379     }
380 
381     public function getHeader()
382     {
383         return $this->header;
384     }
385 
386     public function setBody($body)
387     {
388         $this->body = $body;
389     }
390 
391     public function getBody()
392     {
393         return $this->body;
394     }
395 
396     public function getRequestId()
397     {
398         return $this->requestId;
399     }
400 
401     public function getErrorMessage()
402     {
403         return $this->errorMessage;
404     }
405     
406     public function getHttpStatusCode()
407     {
408         return $this->httpStatusCode;
409     }
410     
411     public function setHttpStatusCode($httpStatusCode)
412     {
413         $this->httpStatusCode  = $httpStatusCode;
414     }
415 
416     public function getContentType()
417     {
418         return $this->contentType;
419     }
420     
421     public function setContentType($contentType)
422     {
423         $this->contentType  = $contentType;
424     }
425     
426     public function getSuccess()
427     {
428         if(200 <= $this->httpStatusCode && 300 > $this->httpStatusCode)
429         {
430             return true;
431         }
432         return false;
433     }
434 
435     /**
436     *根据headersize大小,区分返回的header和body
437     */
438     public function setHeaderSize($headerSize) {
439         if (0 < $headerSize && 0 < strlen($this->content)) {
440             $this->header = substr($this->content, 0, $headerSize);
441             self::extractKey();
442         }
443         if (0 < $headerSize && $headerSize < strlen($this->content)) {
444             $this->body = substr($this->content, $headerSize);
445         }
446     }
447 
448     /**
449     *提取header中的requestId和errorMessage
450     */
451     private function extractKey() {
452         if (0 < strlen($this->header)) {
453             $headers = explode("\r\n", $this->header);
454             foreach ($headers as $value) {
455                 if(strpos($value, "X-Ca-Request-Id:") !== false) 
456                 {
457                     $this->requestId = trim(substr($value, strlen("X-Ca-Request-Id:")));
458                 }
459                 if(strpos($value, "X-Ca-Error-Message:") !== false) 
460                 {
461                     $this->errorMessage = trim(substr($value, strlen("X-Ca-Error-Message:")));
462                 }
463             }
464         }
465     }
466 }
467 
468 class DictionaryUtil 
469 {
470     public static function Add($dic, $key, $value) {
471         if (null == $value) {
472             return;
473         }
474         if (null == $dic)
475         {
476             $dic = Array();
477         }
478         foreach($dic as $itemKey=>$itemValue)
479         {
480             //区分大小写
481             if ($itemKey == $key) {
482                 $dic[$key] = $itemValue;
483                 return;
484             }
485         }
486         $dic[$key] = $value;
487 
488     }
489 
490     public static function Get($dic, $key)
491     {
492         if (array_key_exists($key, $dic)) {
493             return $dic[$key];
494         }
495 
496         return null;
497     }
498 
499     public static function Pop(&$dic, $key)
500     {
501         $value = null;
502         if (array_key_exists($key, $dic)) {
503             $value = $dic[$key];
504             unset($dic[$key]);
505         }
506 
507         return $value;
508     }
509 }
510 
511 class HttpUtil 
512 {
513     public static function send($request, $readtimeout, $connectTimeout)
514     {
515         return self::DoHttp($request->getHost(), 
516                             $request->getPath(),
517                             $request->getMethod(), 
518                             $request->getAppKey(), 
519                             $request->getAppSecret(), 
520                             $readtimeout, 
521                             $connectTimeout,
522                             $request->getHeaders(), 
523                             $request->getQuerys(), 
524                             $request->getBodys(), 
525                             $request->getSignHeaders());
526     }
527 
528     /**
529      *请求Request
530      */
531     private static function DoHttp($host, $path, $method, $appKey, $appSecret, $readtimeout, $connectTimeout, $headers, $querys, $bodys, $signHeaderPrefixList)
532     {
533         $response = new HttpResponse();
534         $headers = self::InitialBasicHeader($path, $appKey, $appSecret, $method, $headers, $querys, $bodys, $signHeaderPrefixList);
535         $curl = self::InitHttpRequest($host, $path, $method, $readtimeout, $connectTimeout, $headers, $querys);
536 
537         $streams = array();
538         if (is_array($bodys)) {
539             if (0 < count($bodys)) {
540                 $body = "";
541                 foreach ($bodys as $itemKey => $itemValue) {
542                     if (0 < strlen($body)) {
543                         $body .= "&";
544                     }
545                     if (0 < strlen($itemValue) && 0 == strlen($itemKey))
546                     {                       
547                         $body .= $itemValue;
548                         array_push($streams, $itemValue);
549                     }
550                     if (0 < strlen($itemKey)) {
551                         $body .= "=";
552                         if (0 < strlen($itemValue)) {
553                             $body .= URLEncode($itemValue);
554                         }
555                     }
556                 }
557                 if (count($bodys) == count($streams) && 1 == count($streams)) {
558                     curl_setopt($curl, CURLOPT_POSTFIELDS, $streams[0]);
559                 } elseif (0 < count($bodys)) {
560                     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($bodys));
561                 }
562             }       
563         }
564         $response->setContent(curl_exec($curl));
565         $response->setHttpStatusCode(curl_getinfo($curl, CURLINFO_HTTP_CODE));
566         $response->setContentType(curl_getinfo($curl, CURLINFO_CONTENT_TYPE));
567         $response->setHeaderSize(curl_getinfo($curl, CURLINFO_HEADER_SIZE));        
568         curl_close($curl);
569         return $response;
570     }
571 
572     /**
573      *准备请求Request
574      */
575     private static function InitHttpRequest($host, $path, $method, $readtimeout, $connectTimeout, $headers, $querys)
576     {
577         $url = $host;
578         if (0 < strlen($path)) {
579             $url.= $path;
580         }
581         $headerArray = array();
582         if (is_array($headers)) {
583             if (0 < count($headers)) {
584                 foreach ($headers as $itemKey => $itemValue) {
585                     if (0 < strlen($itemKey)) {
586                         array_push($headerArray, $itemKey.":".$itemValue);
587                     }
588                 }
589             }
590         }
591         if (is_array($querys)) {
592             if (0 < count($querys)) {
593                 $sb = "";
594                 foreach ($querys as $itemKey => $itemValue) {
595                     if (0 < strlen($sb)) {
596                         $sb .= "&";
597                     }
598                     if (0 < strlen($itemValue) && 0 == strlen($itemKey))
599                     {
600                         $sb .= $itemValue;
601                     }
602                     if (0 < strlen($itemKey)) {
603                         $sb .= $itemKey;
604                         if (0 < strlen($itemValue)) {
605                             $sb .= "=";
606                             $sb .= URLEncode($itemValue);
607                         }
608                     }
609                 }
610                 $url .= "?";
611                 $url .= $sb;
612             }
613         }
614         
615         $curl = curl_init();
616         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
617         curl_setopt($curl, CURLOPT_URL, $url);
618         curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
619         curl_setopt($curl, CURLOPT_FAILONERROR, false);
620         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
621         curl_setopt($curl, CURLOPT_TIMEOUT, $readtimeout);
622         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
623         curl_setopt($curl, CURLOPT_HEADER, true);
624 
625         if (1 == strpos("$".$host, HttpSchema::HTTPS))
626         {
627             curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
628             curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
629         }
630         curl_setopt($curl, CURLOPT_HEADER, true);
631         return $curl;
632     }
633 
634     /**
635      *准备请求的基本header
636      */
637     private static function InitialBasicHeader($path, $appKey, $appSecret, $method, $headers, $querys, $bodys, $signHeaderPrefixList) 
638     {
639         if (null == $headers) {
640             $headers = array();
641         }
642         $sb = "";
643         //时间戳
644         date_default_timezone_set(‘PRC‘);
645         $headers[SystemHeader::X_CA_TIMESTAMP] = strval(time()*1000);
646         //防重放,协议层不能进行重试,否则会报NONCE被使用;如果需要协议层重试,请注释此行
647         $headers[SystemHeader::X_CA_NONCE] = strval(self::NewGuid());
648 
649         $headers[SystemHeader::X_CA_KEY] = $appKey;
650         $headers[SystemHeader::X_CA_SIGNATURE] = SignUtil::Sign($path, $method, $appSecret, $headers, $querys, $bodys, $signHeaderPrefixList);
651 
652         return $headers;
653     }
654   
655     public static function CheckValidationResult($sender, $certificate, $chain, $errors)
656     {
657         return true;
658     }
659 
660     private static function NewGuid()
661     {
662         mt_srand((double)microtime()*10000);
663         $uuid = strtoupper(md5(uniqid(rand(), true)));
664         return $uuid;        
665     }
666 }
667 
668 class MessageDigestUtil
669 {
670     /**
671     * md5和base64处理
672     *
673     * @param $input
674     * @return
675     */
676     public static function Base64AndMD5($input) 
677     {
678         if ($input == null || strlen($input) == 0) {
679             throw new Exception("input can not be null");
680         }
681 
682         return base64_encode(md5(unpack(‘C*‘, $input)));
683     }
684 
685     /**
686     * UTF-8编码转换为ISO-9959-1
687     *
688     * @param str
689     * @return
690     */
691     public static function Utf8ToIso88591($input)
692     {
693         if ($input == null || strlen($input) == 0) {
694             return $input;
695         }
696         return mb_convert_encoding($input, "ISO-8859-1", "UTF-8");
697     }
698 }
699 class SignUtil
700 {
701     /**
702      * 构建待签名
703      */
704     public static function Sign($path, $method, $secret, &$headers, $querys, $bodys, $signHeaderPrefixList)
705     {
706         $signStr = self::BuildStringToSign($path, $method, $headers, $querys, $bodys, $signHeaderPrefixList);
707         return base64_encode(hash_hmac(‘sha256‘, $signStr, $secret, true));
708     }
709     /**
710      * 构建待签名path+(header+query+body)
711      */
712     private static function BuildStringToSign($path, $method, &$headers, $querys, $bodys, $signHeaderPrefixList)
713     {
714         $sb = "";
715         $sb.= strtoupper($method);
716         $sb.= Constants::LF;
717         if (array_key_exists(HttpHeader::HTTP_HEADER_ACCEPT, $headers) && null != $headers[HttpHeader::HTTP_HEADER_ACCEPT]) {
718             $sb.= $headers[HttpHeader::HTTP_HEADER_ACCEPT];
719         }
720         $sb.= Constants::LF;
721         if (array_key_exists(HttpHeader::HTTP_HEADER_CONTENT_MD5, $headers) && null != $headers[HttpHeader::HTTP_HEADER_ACCEPT]) {
722             $sb.= $headers[HttpHeader::HTTP_HEADER_CONTENT_MD5];
723         }
724         $sb.= Constants::LF;
725         if (array_key_exists(HttpHeader::HTTP_HEADER_CONTENT_TYPE, $headers) && null != $headers[HttpHeader::HTTP_HEADER_ACCEPT]) {
726             $sb.= $headers[HttpHeader::HTTP_HEADER_CONTENT_TYPE];
727         }
728         $sb.= Constants::LF;
729         if (array_key_exists(HttpHeader::HTTP_HEADER_DATE, $headers) && null != $headers[HttpHeader::HTTP_HEADER_ACCEPT]) {
730             $sb.= $headers[HttpHeader::HTTP_HEADER_DATE];
731         }
732         $sb.= Constants::LF;        
733         $sb.= self::BuildHeaders($headers, $signHeaderPrefixList);
734         $sb.= self::BuildResource($path, $querys, $bodys);
735 
736         return $sb;
737     }
738 
739     /**
740      * 构建待签名Path+Query+FormParams
741      */
742     private static function BuildResource($path, $querys, $bodys)
743     {
744         $sb = "";
745         if (0 < strlen($path))
746         {
747             $sb.=$path;
748         }
749         $sbParam = "";
750         $sortParams = array();
751 
752         //query参与签名
753         if (is_array($querys)) {
754             foreach ($querys as $itemKey => $itemValue) {
755                 if (0 < strlen($itemKey)) {
756                     $sortParams[$itemKey] = $itemValue;
757                 }
758             }
759         }
760         //body参与签名
761         if (is_array($bodys)) {
762             foreach ($bodys as $itemKey => $itemValue) {
763                 if (0 < strlen($itemKey)) {
764                     $sortParams[$itemKey] = $itemValue;
765                 }
766             }
767         }
768         //排序
769         ksort($sortParams);
770         //参数Key 
771         foreach ($sortParams as $itemKey => $itemValue) {
772             if (0 < strlen($itemKey)) {
773                 if (0 < strlen($sbParam)) {
774                     $sbParam.="&";
775                 }
776                 $sbParam.=$itemKey;
777                 if (null != $itemValue)
778                 {
779                     if (0 < strlen($itemValue)) {
780                         $sbParam.="=";
781                         $sbParam.=$itemValue;
782                     }
783                  }
784             }
785         }
786         if (0 < strlen($sbParam)) {
787             $sb.="?";
788             $sb.=$sbParam;
789         }
790 
791         return $sb;
792     }
793     
794     /**
795      * 构建待签名Http头
796      *
797      * @param headers              请求中所有的Http头
798      * @param signHeaderPrefixList 自定义参与签名Header前缀
799      * @return 待签名Http头
800     */
801     private static function BuildHeaders(&$headers, $signHeaderPrefixList)
802     {
803         $sb = "";
804 
805         if (null != $signHeaderPrefixList)
806         {
807             //剔除X-Ca-Signature/X-Ca-Signature-Headers/Accept/Content-MD5/Content-Type/Date
808             unset($signHeaderPrefixList[SystemHeader::X_CA_SIGNATURE]);
809             unset($signHeaderPrefixList[HttpHeader::HTTP_HEADER_ACCEPT]);
810             unset($signHeaderPrefixList[HttpHeader::HTTP_HEADER_CONTENT_MD5]);
811             unset($signHeaderPrefixList[HttpHeader::HTTP_HEADER_CONTENT_TYPE]);
812             unset($signHeaderPrefixList[HttpHeader::HTTP_HEADER_DATE]);
813             ksort($signHeaderPrefixList);
814             
815             if (is_array($headers)) {
816                 ksort($headers);
817                 $signHeadersStringBuilder = "";
818                 foreach ($headers as $itemKey => $itemValue)
819                 {
820                     if (self::IsHeaderToSign($itemKey, $signHeaderPrefixList))
821                     {
822                         $sb.=$itemKey;
823                         $sb.=Constants::SPE2;
824                         if (0 < strlen($itemValue)) {
825                             $sb.=$itemValue;
826                         }
827                         $sb.=Constants::LF;
828                         if (0 < strlen($signHeadersStringBuilder))
829                         {
830                             $signHeadersStringBuilder.= Constants::SPE1;
831                         }
832                         $signHeadersStringBuilder.= $itemKey;
833                     }
834                 }
835                 $headers[SystemHeader::X_CA_SIGNATURE_HEADERS] = $signHeadersStringBuilder;
836             }
837 
838         } 
839 
840         return $sb;
841      }  
842     /**
843     * Http头是否参与签名
844     * return
845     */
846     private static function IsHeaderToSign($headerName, $signHeaderPrefixList) 
847     {
848         if (NULL == $headerName) {
849             return false;
850         }
851         if (0 == strlen($headerName)) {
852             return false;
853         }
854         if (1 == strpos("$".$headerName, Constants::CA_HEADER_TO_SIGN_PREFIX_SYSTEM)) {
855             return true;
856         }
857         if (!is_array($signHeaderPrefixList) || empty($signHeaderPrefixList) ) {
858             return false;
859         }
860         if (array_key_exists($headerName, $signHeaderPrefixList)) {
861             return true;
862         }
863 
864         return false;
865     }
866 }

 

关于阿里云物流查询SDK