cls_oss_mts.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * Krpano100 oss媒体转码
  4. * ============================================================================
  5. * 技术支持:2015-2099 成都世纪川翔科技有限公司
  6. * 官网地址: http://www.krpano100.com
  7. * ----------------------------------------------------------------------------
  8. * $Author: wanghao 932625974#qq.com $
  9. * $Id: index.php 28028 2016-03-09Z wanghao $
  10. */
  11. if(!defined('IN_T'))
  12. {
  13. die('hacking attempt');
  14. }
  15. class Oss_mts
  16. {
  17. private $accessid;
  18. private $accesskey;
  19. function __construct($accessid, $accesskey){
  20. $this->accessid = $accessid;
  21. $this->accesskey = $accesskey;
  22. }
  23. public function getSignUrl($parms){
  24. date_default_timezone_set('GMT');
  25. $params_all = array(
  26. 'Format' => 'json',
  27. 'Version' => '2014-06-18',
  28. 'AccessKeyId' => $this->accessid,
  29. 'SignatureMethod' => 'HMAC-SHA1',
  30. 'Timestamp' => date("Y-m-d\TH:i:s\Z",time()),
  31. 'SignatureVersion' => '1.0',
  32. 'SignatureNonce' => Common::guid()
  33. );
  34. foreach ($parms as $k => $v) {
  35. $params_all[$k] = $v;
  36. }
  37. ksort($params_all);
  38. $strToSing = 'GET'.'&'.$this->percentEncode('/').'&';
  39. $str = '';
  40. foreach ($params_all as $k => $v) {
  41. $str.=('&'.$this->percentEncode($k).'='.$this->percentEncode($v));
  42. }
  43. $url_formt = substr($str, 1);
  44. $strToSing .= $this->percentEncode($url_formt);
  45. $strToSing = $this->getSignature($strToSing,$this->accesskey.'&');
  46. $mts_location = substr($GLOBALS['_lang']['oss_config']['location'], 4);
  47. return 'http://mts.'.$mts_location.'.aliyuncs.com?Signature='.$this->percentEncode($strToSing).'&'.$url_formt;
  48. }
  49. private function getSignature($str, $key) {
  50. $signature = "";
  51. if (function_exists('hash_hmac')) {
  52. $signature = base64_encode(hash_hmac("sha1", $str, $key, true));
  53. } else {
  54. $blocksize = 64;
  55. $hashfunc = 'sha1';
  56. if (strlen($key) > $blocksize) {
  57. $key = pack('H*', $hashfunc($key));
  58. }
  59. $key = str_pad($key, $blocksize, chr(0x00));
  60. $ipad = str_repeat(chr(0x36), $blocksize);
  61. $opad = str_repeat(chr(0x5c), $blocksize);
  62. $hmac = pack(
  63. 'H*', $hashfunc(
  64. ($key ^ $opad) . pack(
  65. 'H*', $hashfunc(
  66. ($key ^ $ipad) . $str
  67. )
  68. )
  69. )
  70. );
  71. $signature = base64_encode($hmac);
  72. }
  73. return $signature;
  74. }
  75. private function percentEncode($str){
  76. $str = urlencode($str);
  77. $str = str_replace('+','%20',$str);
  78. $str = str_replace('*','%2A',$str);
  79. $str = str_replace('%7E','~',$str);
  80. return $str;
  81. }
  82. }
  83. ?>