Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shaunthegeek/39c8ce69e78d12287789606208e3901c to your computer and use it in GitHub Desktop.

Select an option

Save shaunthegeek/39c8ce69e78d12287789606208e3901c to your computer and use it in GitHub Desktop.
阿里云OSS PHP SDK补丁:使用Carbon替代time(),修复代码可测性
--- vendor/aliyuncs/oss-sdk-php/composer.json 2018-01-08 14:59:35.000000000 +0800
+++ stonecutter/aliyun-oss-php-sdk/composer.json 2019-04-18 11:13:06.799247597 +0800
@@ -11,6 +11,7 @@
}
],
"require": {
+ "nesbot/carbon": ">=1.0",
"php":">=5.3"
},
"require-dev" : {
--- vendor/aliyuncs/oss-sdk-php/src/OSS/OssClient.php 2019-04-18 10:18:13.339150087 +0800
+++ stonecutter/aliyun-oss-php-sdk/src/OSS/OssClient.php 2019-04-18 11:12:42.171426765 +0800
@@ -1,6 +1,7 @@
<?php
namespace OSS;
+use Carbon\Carbon;
use OSS\Core\MimeTypes;
use OSS\Core\OssException;
use OSS\Http\RequestCore;
@@ -789,7 +790,7 @@
public function signRtmpUrl($bucket, $channelName, $timeout = 60, $options = NULL)
{
$this->precheckCommon($bucket, $channelName, $options, false);
- $expires = time() + $timeout;
+ $expires = Carbon::now()->addSeconds($timeout)->timestamp;
$proto = 'rtmp://';
$hostname = $this->generateHostname($bucket);
$cano_params = '';
@@ -1864,7 +1865,7 @@
if (!isset($options[self::OSS_CONTENT_TYPE])) {
$options[self::OSS_CONTENT_TYPE] = '';
}
- $timeout = time() + $timeout;
+ $timeout = Carbon::now()->addSeconds($timeout)->timestamp;
$options[self::OSS_PREAUTH] = $timeout;
$options[self::OSS_DATE] = $timeout;
$this->setSignStsInUrl(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment