| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace common\services\mall\aliyunsts;
- use common\services\mall\aliyunsts\Sts\Sts\Request\V20150401\AssumeRoleRequest;
- use common\services\mall\aliyunsts\StsCode\DefaultAcsClient;
- use common\services\mall\aliyunsts\StsCode\Profile\DefaultProfile;
- use common\services\mall\aliyunsts\StsCode\Regions\Endpoint;
- use common\services\mall\aliyunsts\StsCode\Regions\EndpointProvider;
- use common\services\mall\aliyunsts\StsCode\Regions\ProductDomain;
- use Exception;
- class AliyunStsServices
- {
- public function getSts($mall_id, $params)
- {
- try {
- $accessKeyID = $params['storage_aliyun_accesskeyid'];
- $accessKeySecret = $params['storage_aliyun_accesskeysecret'];
- $roleArn = $params['arn'];
- $tokenExpire = 3600;
- $policy = '{
- "Statement": [
- {
- "Action": [
- "oss:*"
- ],
- "Effect": "Allow",
- "Resource": ["acs:oss:*"]
- }
- ],
- "Version": "1"
- }';
- $iClientProfile = DefaultProfile::getProfile("cn-hangzhou", $accessKeyID, $accessKeySecret);
- $this->setEndpoint("cn-hangzhou");
- // EndpointProvider::setEndpoints($params['storage_aliyun_endpoint']);
- $client = new DefaultAcsClient($iClientProfile);
- $request = new AssumeRoleRequest();
- $request->setRoleSessionName("bigVideo");
- $request->setRoleArn($roleArn);
- // $request->setPolicy($policy);
- $request->setDurationSeconds($tokenExpire);
- $response = $client->doAction($request);
- $rows = array();
- $body = $response->getBody();
- $content = json_decode($body, true);
- $rows['status'] = $response->getStatus();
- if ($rows['status'] != 200) throw new Exception($content['Message']);
- $rows['AccessKeyId'] = $content['Credentials']['AccessKeyId'];
- $rows['AccessKeySecret'] = $content['Credentials']['AccessKeySecret'];
- $rows['Expiration'] = $content['Credentials']['Expiration'];
- $rows['SecurityToken'] = $content['Credentials']['SecurityToken'];
- return $rows;
- } catch (\Exception $e) {
- throw new Exception($e->getMessage());
- }
- }
- public function setEndpoint($endpoint)
- {
- $regionIds = array("cn-hangzhou","cn-beijing","cn-qingdao","cn-hongkong","cn-shanghai","us-west-1","cn-shenzhen","ap-southeast-1");
- $productDomains =array(
- new ProductDomain("Ecs", "ecs.aliyuncs.com"),
- new ProductDomain("Rds", "rds.aliyuncs.com"),
- new ProductDomain("BatchCompute", "batchCompute.aliyuncs.com"),
- new ProductDomain("Bss", "bss.aliyuncs.com"),
- new ProductDomain("Oms", "oms.aliyuncs.com"),
- new ProductDomain("Slb", "slb.aliyuncs.com"),
- new ProductDomain("Oss", "oss-cn-hangzhou.aliyuncs.com"),
- new ProductDomain("OssAdmin", "oss-admin.aliyuncs.com"),
- new ProductDomain("Sts", "sts.aliyuncs.com"),
- new ProductDomain("Yundun", "yundun-cn-hangzhou.aliyuncs.com"),
- new ProductDomain("Risk", "risk-cn-hangzhou.aliyuncs.com"),
- new ProductDomain("Drds", "drds.aliyuncs.com"),
- new ProductDomain("M-kvstore", "m-kvstore.aliyuncs.com"),
- new ProductDomain("Ram", "ram.aliyuncs.com"),
- new ProductDomain("Cms", "metrics.aliyuncs.com"),
- new ProductDomain("Crm", "crm-cn-hangzhou.aliyuncs.com"),
- new ProductDomain("Ocs", "pop-ocs.aliyuncs.com"),
- new ProductDomain("Ots", "ots-pop.aliyuncs.com"),
- new ProductDomain("Dqs", "dqs.aliyuncs.com"),
- new ProductDomain("Location", "location.aliyuncs.com"),
- new ProductDomain("Ubsms", "ubsms.aliyuncs.com"),
- new ProductDomain("Ubsms-inner", "ubsms-inner.aliyuncs.com")
- );
- $endpoint = new Endpoint($endpoint, $regionIds, $productDomains);
- $endpoints = array($endpoint);
- EndpointProvider::setEndpoints($endpoints);
- }
- }
|