6
0
Fork 0

添加OSSsts上传凭证获取

release
vine_liutk 2021-12-22 18:50:00 +08:00
parent e18715e608
commit f2c77c457b
7 changed files with 680 additions and 7 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace App\Endpoint\Api\Http\Controllers;
use App\Services\AliStsService;
use Illuminate\Http\Request;
class AliOssController extends Controller
{
/**
* @param \Illuminate\Http\Request $request
* @return void
*/
public function sts(Request $request, AliStsService $aliStsService)
{
return response()->json(array_merge([
'bucket'=>config('settings.aliyun_oss_bucket'),
], $aliStsService->createSts($request->user()->phone)));
}
}

View File

@ -4,6 +4,7 @@ use App\Endpoint\Api\Http\Controllers\Account\ChangePasswordController;
use App\Endpoint\Api\Http\Controllers\Account\UserController;
use App\Endpoint\Api\Http\Controllers\AdController;
use App\Endpoint\Api\Http\Controllers\AfterSaleController;
use App\Endpoint\Api\Http\Controllers\AliOssController;
use App\Endpoint\Api\Http\Controllers\AppVersionController;
use App\Endpoint\Api\Http\Controllers\ArticleController;
use App\Endpoint\Api\Http\Controllers\Auth\LoginController;
@ -126,6 +127,9 @@ Route::group([
Route::get('share-bgs', [ShareBgController::class, 'index']);
Route::post('user-qr-code', [ShareBgController::class, 'userQrCode']);
//OSS上传凭证
Route::post('oss-sts', [AliOssController::class, 'sts']);
// 订单
Route::get('order/statistics', StatisticsController::class);
Route::post('order/verify-order', OrderVerifyController::class);

View File

@ -0,0 +1,56 @@
<?php
namespace App\Services;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use Illuminate\Support\Arr;
class AliStsService
{
/**
* 创建临时凭证
*
* @param string $sessionName
* @param integer $expireSeconds
* @return array
*/
public function createSts(string $sessionName, int $expireSeconds = 3600)
{
//构建一个阿里云客户端,用于发起请求。
//构建阿里云客户端时需要设置AccessKey ID和AccessKey Secret。
AlibabaCloud::accessKeyClient(config('settings.aliyun_oss_access_id'), config('settings.aliyun_oss_access_key'))
->regionId('cn-chengdu')
->asDefaultClient();
//设置参数发起请求。关于参数含义和设置方法请参见《API参考》。
try {
$result = AlibabaCloud::rpc()
->product('Sts')
->scheme('https') // https | http
->version('2015-04-01')
->action('AssumeRole')
->method('POST')
->host('sts.cn-chengdu.aliyuncs.com')
->options([
'query' => [
'RegionId' => 'cn-chengdu',
'RoleArn' => config('settings.aliyun_oss_sts_arn'),
'RoleSessionName' => $sessionName,
'DurationSeconds' => $expireSeconds,
],
])
->request();
// dd($result->toArray());
return Arr::get($result->toArray(), 'Credentials', []);
} catch (ClientException $e) {
report($e);
// dd($e->getErrorMessage());
// echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
report($e);
// echo $e->getErrorMessage() . PHP_EOL;
}
return [];
}
}

View File

@ -25,11 +25,13 @@ class MallUnipushService extends UniPushService
public function push(string $sn, Message $message)
{
$res = false;
if ($message->user_id > 0) {
$this->pushMessage($sn, $message);
$res = $this->pushMessage($sn, $message);
} else {
$this->pushAllMessage($sn, $message);
$res = $this->pushAllMessage($sn, $message);
}
return $res;
}
/**
@ -40,7 +42,7 @@ class MallUnipushService extends UniPushService
*/
public function pushAllMessage(string $sn, Message $message)
{
$this->pushAll($sn, $message->title, $message->content, [
return $this->pushAll($sn, $message->title, $message->content, [
'jump_type' => $message->jump_type == 0 ? 1 : $message->jump_type,
'jump_link' => $message->type == 1 || empty($message->jump_link) ? '/pages/news/index' : $message->jump_link,
]);
@ -56,13 +58,13 @@ class MallUnipushService extends UniPushService
{
//如果不是指定消息,直接退出;
if (is_null($message->user)) {
return;
return false;
}
//如果拿不到u_cid直接退出
if (!$message->user->cid->u_cid) {
return;
return false;
}
$this->pushCid($sn, $message->user->cid->u_cid, $message->title, $message->content, [
return $this->pushCid($sn, $message->user->cid->u_cid, $message->title, $message->content, [
'jump_type' => $message->jump_type == 0 ? 1 : $message->jump_type,
'jump_link' => $message->type == 1 || empty($message->jump_link) ? '/pages/news/index' : $message->jump_link,
]);

View File

@ -12,6 +12,8 @@
},
"require": {
"php": "^8.0",
"alibabacloud/sts": "^1.8",
"alphasnow/aliyun-oss-laravel": "^3.0",
"dcat/laravel-admin": "2.1.5-beta",
"fruitcake/laravel-cors": "^2.0",
"gregwar/captcha": "^1.1",

582
composer.lock generated
View File

@ -4,8 +4,397 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8cdaea8176b066b5f779a5fe80f806af",
"content-hash": "3e960fc2a6ca526d5a9910e13a6668f0",
"packages": [
{
"name": "adbario/php-dot-notation",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/adbario/php-dot-notation.git",
"reference": "eee4fc81296531e6aafba4c2bbccfc5adab1676e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/adbario/php-dot-notation/zipball/eee4fc81296531e6aafba4c2bbccfc5adab1676e",
"reference": "eee4fc81296531e6aafba4c2bbccfc5adab1676e",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"ext-json": "*",
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0|^6.0",
"squizlabs/php_codesniffer": "^3.0"
},
"type": "library",
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Adbar\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Riku Särkinen",
"email": "riku@adbar.io"
}
],
"description": "PHP dot notation access to arrays",
"homepage": "https://github.com/adbario/php-dot-notation",
"keywords": [
"ArrayAccess",
"dotnotation"
],
"support": {
"issues": "https://github.com/adbario/php-dot-notation/issues",
"source": "https://github.com/adbario/php-dot-notation/tree/2.x"
},
"time": "2019-01-01T23:59:15+00:00"
},
{
"name": "alibabacloud/client",
"version": "1.5.31",
"source": {
"type": "git",
"url": "https://github.com/aliyun/openapi-sdk-php-client.git",
"reference": "19224d92fe27ab8ef501d77d4891e7660bc023c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aliyun/openapi-sdk-php-client/zipball/19224d92fe27ab8ef501d77d4891e7660bc023c1",
"reference": "19224d92fe27ab8ef501d77d4891e7660bc023c1",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"adbario/php-dot-notation": "^2.2",
"clagiordano/weblibs-configmanager": "^1.0",
"danielstjules/stringy": "^3.1",
"ext-curl": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-simplexml": "*",
"ext-xmlwriter": "*",
"guzzlehttp/guzzle": "^6.3|^7.0",
"mtdowling/jmespath.php": "^2.5",
"php": ">=5.5"
},
"require-dev": {
"composer/composer": "^1.8",
"drupal/coder": "^8.3",
"ext-dom": "*",
"ext-pcre": "*",
"ext-sockets": "*",
"ext-spl": "*",
"league/climate": "^3.2.4",
"mikey179/vfsstream": "^1.6",
"monolog/monolog": "^1.24",
"phpunit/phpunit": "^5.7.27|^6.1",
"psr/cache": "^1.0",
"symfony/dotenv": "^3.4",
"symfony/var-dumper": "^3.4"
},
"suggest": {
"ext-sockets": "To use client-side monitoring"
},
"type": "library",
"autoload": {
"psr-4": {
"AlibabaCloud\\Client\\": "src"
},
"files": [
"src/Functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Alibaba Cloud SDK",
"email": "sdk-team@alibabacloud.com",
"homepage": "http://www.alibabacloud.com"
}
],
"description": "Alibaba Cloud Client for PHP - Use Alibaba Cloud in your PHP project",
"homepage": "https://www.alibabacloud.com/",
"keywords": [
"alibaba",
"alibabacloud",
"aliyun",
"client",
"cloud",
"library",
"sdk",
"tool"
],
"support": {
"issues": "https://github.com/aliyun/openapi-sdk-php-client/issues",
"source": "https://github.com/aliyun/openapi-sdk-php-client"
},
"time": "2021-05-13T06:26:38+00:00"
},
{
"name": "alibabacloud/sts",
"version": "1.8.884",
"source": {
"type": "git",
"url": "https://github.com/alibabacloud-sdk-php/sts.git",
"reference": "c9807a06c7047381b8a2ab4952eb11e8d686a488"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/alibabacloud-sdk-php/sts/zipball/c9807a06c7047381b8a2ab4952eb11e8d686a488",
"reference": "c9807a06c7047381b8a2ab4952eb11e8d686a488",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"alibabacloud/client": "^1.5",
"php": ">=5.5"
},
"type": "library",
"autoload": {
"psr-4": {
"AlibabaCloud\\Sts\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Alibaba Cloud SDK",
"email": "sdk-team@alibabacloud.com",
"homepage": "http://www.alibabacloud.com"
}
],
"description": "Alibaba Cloud Sts SDK for PHP",
"homepage": "https://www.alibabacloud.com/",
"keywords": [
"alibaba",
"alibabacloud",
"aliyun",
"cloud",
"library",
"sdk",
"sts"
],
"support": {
"issues": "https://github.com/alibabacloud-sdk-php/sts/issues",
"source": "https://github.com/alibabacloud-sdk-php/sts"
},
"time": "2019-05-30T05:03:57+00:00"
},
{
"name": "aliyuncs/oss-sdk-php",
"version": "v2.4.3",
"source": {
"type": "git",
"url": "https://github.com/aliyun/aliyun-oss-php-sdk.git",
"reference": "4ccead614915ee6685bf30016afb01aabd347e46"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aliyun/aliyun-oss-php-sdk/zipball/4ccead614915ee6685bf30016afb01aabd347e46",
"reference": "4ccead614915ee6685bf30016afb01aabd347e46",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "*",
"satooshi/php-coveralls": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"OSS\\": "src/OSS"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Aliyuncs",
"homepage": "http://www.aliyun.com"
}
],
"description": "Aliyun OSS SDK for PHP",
"homepage": "http://www.aliyun.com/product/oss/",
"support": {
"issues": "https://github.com/aliyun/aliyun-oss-php-sdk/issues",
"source": "https://github.com/aliyun/aliyun-oss-php-sdk/tree/v2.4.3"
},
"time": "2021-08-25T13:03:58+00:00"
},
{
"name": "alphasnow/aliyun-oss-flysystem",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/alphasnow/aliyun-oss-flysystem.git",
"reference": "4d9e11de0f8d9035f02181f440631acaffba2b05"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/alphasnow/aliyun-oss-flysystem/zipball/4d9e11de0f8d9035f02181f440631acaffba2b05",
"reference": "4d9e11de0f8d9035f02181f440631acaffba2b05",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"aliyuncs/oss-sdk-php": "^2.4",
"league/flysystem": "^1.0",
"php": ">=7.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.1",
"mockery/mockery": "^1.3",
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^8.5"
},
"type": "library",
"autoload": {
"psr-4": {
"AlphaSnow\\Flysystem\\AliyunOss\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "AlphaSnow",
"email": "wind91@foxmail.com"
}
],
"description": "Flysystem adapter for the Aliyun storage",
"homepage": "https://alphasnow.github.io/aliyun-oss-flysystem/",
"keywords": [
"adapter",
"aliyun",
"filesystem",
"oss"
],
"support": {
"issues": "https://github.com/alphasnow/aliyun-oss-flysystem/issues",
"source": "https://github.com/alphasnow/aliyun-oss-flysystem/tree/1.3.1"
},
"time": "2021-10-15T03:12:13+00:00"
},
{
"name": "alphasnow/aliyun-oss-laravel",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/alphasnow/aliyun-oss-laravel.git",
"reference": "c77b8332020bf3fafe7a5d8510c6193a9014a5df"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/alphasnow/aliyun-oss-laravel/zipball/c77b8332020bf3fafe7a5d8510c6193a9014a5df",
"reference": "c77b8332020bf3fafe7a5d8510c6193a9014a5df",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"alphasnow/aliyun-oss-flysystem": "^1.3",
"php": ">=7.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.2",
"mockery/mockery": "^1.3",
"orchestra/testbench": "^5.20",
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^8.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"AlphaSnow\\AliyunOss\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"AlphaSnow\\AliyunOss\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "alphasnow",
"email": "wind91@foxmail.com"
}
],
"description": "alibaba cloud object storage service for laravel",
"homepage": "https://alphasnow.github.io/aliyun-oss-laravel/",
"keywords": [
"aliyun",
"filesystems",
"laravel",
"oss",
"storage"
],
"support": {
"issues": "https://github.com/alphasnow/aliyun-oss-laravel/issues",
"source": "https://github.com/alphasnow/aliyun-oss-laravel/tree/3.0.2"
},
"time": "2021-10-12T07:16:16+00:00"
},
{
"name": "asm89/stack-cors",
"version": "v2.0.3",
@ -193,6 +582,64 @@
],
"time": "2021-08-15T20:50:18+00:00"
},
{
"name": "clagiordano/weblibs-configmanager",
"version": "v1.2.0",
"source": {
"type": "git",
"url": "https://github.com/clagiordano/weblibs-configmanager.git",
"reference": "5c8ebcc62782313b1278afe802b120d18c07a059"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/clagiordano/weblibs-configmanager/zipball/5c8ebcc62782313b1278afe802b120d18c07a059",
"reference": "5c8ebcc62782313b1278afe802b120d18c07a059",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"clagiordano/phpunit-result-printer": "^1",
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"psr-4": {
"clagiordano\\weblibs\\configmanager\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "Claudio Giordano",
"email": "claudio.giordano@autistici.org",
"role": "Developer"
}
],
"description": "weblibs-configmanager is a tool library for easily read and access to php config array file and direct read/write configuration file / object",
"keywords": [
"clagiordano",
"configuration",
"manager",
"tool",
"weblibs"
],
"support": {
"issues": "https://github.com/clagiordano/weblibs-configmanager/issues",
"source": "https://github.com/clagiordano/weblibs-configmanager/tree/v1.2.0"
},
"time": "2021-05-18T17:55:57+00:00"
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.4",
@ -272,6 +719,72 @@
],
"time": "2021-09-13T08:41:34+00:00"
},
{
"name": "danielstjules/stringy",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/danielstjules/Stringy.git",
"reference": "df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/danielstjules/Stringy/zipball/df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e",
"reference": "df24ab62d2d8213bbbe88cc36fc35a4503b4bd7e",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=5.4.0",
"symfony/polyfill-mbstring": "~1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Stringy\\": "src/"
},
"files": [
"src/Create.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel St. Jules",
"email": "danielst.jules@gmail.com",
"homepage": "http://www.danielstjules.com"
}
],
"description": "A string manipulation library with multibyte support",
"homepage": "https://github.com/danielstjules/Stringy",
"keywords": [
"UTF",
"helpers",
"manipulation",
"methods",
"multibyte",
"string",
"utf-8",
"utility",
"utils"
],
"support": {
"issues": "https://github.com/danielstjules/Stringy/issues",
"source": "https://github.com/danielstjules/Stringy"
},
"time": "2017-06-12T01:10:27+00:00"
},
{
"name": "dasprid/enum",
"version": "1.0.3",
@ -2705,6 +3218,73 @@
],
"time": "2021-10-01T21:08:31+00:00"
},
{
"name": "mtdowling/jmespath.php",
"version": "2.6.1",
"source": {
"type": "git",
"url": "https://github.com/jmespath/jmespath.php.git",
"reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
"reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^5.4 || ^7.0 || ^8.0",
"symfony/polyfill-mbstring": "^1.17"
},
"require-dev": {
"composer/xdebug-handler": "^1.4 || ^2.0",
"phpunit/phpunit": "^4.8.36 || ^7.5.15"
},
"bin": [
"bin/jp.php"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
}
},
"autoload": {
"psr-4": {
"JmesPath\\": "src/"
},
"files": [
"src/JmesPath.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Declaratively specify how to extract elements from a JSON document",
"keywords": [
"json",
"jsonpath"
],
"support": {
"issues": "https://github.com/jmespath/jmespath.php/issues",
"source": "https://github.com/jmespath/jmespath.php/tree/2.6.1"
},
"time": "2021-06-14T00:11:39+00:00"
},
{
"name": "nesbot/carbon",
"version": "2.55.2",

View File

@ -4,6 +4,15 @@ return [
// 应用名称
'app_name' => '子春生',
//阿里云OSS信息
'aliyun_oss_access_id' => 'LTAI5tFMaynxgZ9aDMNLxpU9',
'aliyun_oss_access_key' => 'pecJA3LX2sQyWxWDMUUb5NhsMe4Czu',
'aliyun_oss_bucket' => 'zcs-mall',
'aliyun_oss_endpoint' => 'oss-cn-chengdu.aliyuncs.com',
'aliyun_oss_domain' => 'cdn.zichunsheng.cn',
'aliyun_oss_use_ssl' => true,
'aliyun_oss_sts_arn' => 'acs:ram::1367535826984495:role/ossstsrole',
// 订单支付过期时间(秒)
'order_payment_expires_at' => 1800,