From eda8511bda577a2794c86adc3c21c5b3704eb737 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Wed, 24 Jul 2024 08:19:52 +0800 Subject: [PATCH] Force endpoint to use https --- aliyun-oss-wordpress.php | 18 ++++++------------ readme.txt | 6 +++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/aliyun-oss-wordpress.php b/aliyun-oss-wordpress.php index 9f729e8..25106aa 100644 --- a/aliyun-oss-wordpress.php +++ b/aliyun-oss-wordpress.php @@ -3,7 +3,7 @@ Plugin Name: OSS Aliyun Plugin URI: https://github.com/sy-records/aliyun-oss-wordpress Description: 使用阿里云对象存储 OSS 作为附件存储空间。(This is a plugin that uses Aliyun Object Storage Service for attachments remote saving.) -Version: 1.4.15 +Version: 1.4.16 Author: 沈唁 Author URI: https://qq52o.me License: Apache2.0 @@ -19,7 +19,7 @@ use OSS\Credentials\CredentialsProvider; use AlibabaCloud\Credentials\Credential; use OSS\Credentials\StaticCredentialsProvider; -define('OSS_VERSION', '1.4.15'); +define('OSS_VERSION', '1.4.16'); define('OSS_BASEFOLDER', plugin_basename(dirname(__FILE__))); if (!function_exists('get_home_path')) { @@ -78,7 +78,6 @@ function oss_get_client() $oss_options = get_option('oss_options', true); $role_name = esc_attr($oss_options['role_name'] ?? ''); $endpoint = oss_get_bucket_endpoint($oss_options); - $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://'; if (!empty($role_name)) { $ecsRamRole = new Credential([ @@ -94,7 +93,7 @@ function oss_get_client() } $config = [ 'provider' => $provider, - 'endpoint' => $protocol . $endpoint, + 'endpoint' => $endpoint, 'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4, 'region' => str_replace('oss-', '', esc_attr($oss_options['regional'])), ]; @@ -103,12 +102,12 @@ function oss_get_client() function oss_get_bucket_endpoint($oss_options) { - $oss_regional = esc_attr($oss_options['regional']); + $regional = esc_attr($oss_options['regional']); if ($oss_options['is_internal'] == 'true') { - return "{$oss_regional}-internal.aliyuncs.com"; + return "https://{$regional}-internal.aliyuncs.com"; } - return "{$oss_regional}.aliyuncs.com"; + return "https://{$regional}.aliyuncs.com"; } function oss_get_bucket_name() @@ -576,11 +575,6 @@ function oss_setting_post_thumbnail_style($html, $post_id, $post_image_id) return $html; } -/** - * @link https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints - * @param string $regional - * @return void - */ function oss_get_regional($regional) { $options = [ diff --git a/readme.txt b/readme.txt index a898331..02d862d 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: oss, 阿里云, 对象存储, aliyun Requires at least: 4.6 Tested up to: 6.6 Requires PHP: 7.1 -Stable tag: 1.4.15 +Stable tag: 1.4.16 License: Apache2.0 License URI: http://www.apache.org/licenses/LICENSE-2.0.html @@ -78,6 +78,10 @@ License URI: http://www.apache.org/licenses/LICENSE-2.0.html = 1.4.15 = +- 强制 endpoint 使用 https + += 1.4.15 = + - 将阿里云V1签名升级为V4签名 = 1.4.14 =