Procházet zdrojové kódy

修改阿里云的api模块获取

lvhao před 12 hodinami
rodič
revize
36b5a580e5

+ 2 - 2
core/CoreApp/controllers/Lyerpapi/v1/Order.php

@@ -9,7 +9,7 @@ class Order extends Lyapi_Controller{
         // 简便做法:复制 Lyapi_Controller 的部分代码但不调用 _check_api_auth
        // $this->load->driver('cache'); // 加载缓存驱动
        $this->load->_model("Model_logic_order","logic_order");
-       $this->load->_model("Model_aliyunoss","aliyunoss");
+       $this->load->_model("Model_aliyunossnew","aliyunossnew");
     }
 
     public function getinfo(){
@@ -90,7 +90,7 @@ class Order extends Lyapi_Controller{
         if($data['qr'] != 'aliyuncheck'){
             $this->_json_error('参数错误','500');
         }
-        $res = $this->aliyunoss->getOssSignType("scanlibrary");
+        $res = $this->aliyunossnew->getOssSignType("scanlibrary");
         if($res['code'] == -1){
             $this->_json_error($res["msg"],'500');
         }else{

+ 137 - 0
core/CoreApp/models/Model_aliyunossnew.php

@@ -0,0 +1,137 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
+class Model_aliyunossnew extends Lin_Model 
+{
+	function __construct(){
+        parent::__construct();
+    }
+    private $oss_basic_url = "https://lyerp-product-source.oss-cn-beijing.aliyuncs.com";
+    private $show_basie_url ="https://lyerposs.wepolicy.cn"; 
+    private function get_oss_config(){
+
+        $query1 = $this->db->get_where('setting',array('skey' => 'oss_aliyun_id'));
+        $oss_aliyun_id_info = $query1->row_array();
+		$query2 = $this->db->get_where('setting',array('skey' => 'oss_aliyun_key'));
+        $oss_aliyun_key_info = $query2->row_array();
+        
+
+
+
+        $oss_aliyun_id_info = $this->setting->find('skey = "oss_aliyun_id"');
+        $oss_aliyun_key_info = $this->setting->find('skey = "oss_aliyun_key"');
+        $accessKeyId =  $oss_aliyun_id_info['svalue'];
+        $accessKeySecret = $oss_aliyun_key_info['svalue'];
+        $bucket = "lyerp-product-source";
+        $endpoint = "oss-cn-beijing.aliyuncs.com";
+        $region = "oss-cn-beijing";
+        $host = $bucket.".".$endpoint;
+
+        return [
+            'accessKeyId' => $accessKeyId,
+            'accessKeySecret' => $accessKeySecret,
+            'bucket' => $bucket,
+            'endpoint' => $endpoint,
+            'region'     => $region,
+            'host' => $host,
+        ];
+
+    }
+
+    public function getOssSign(){
+        $conf = $this->get_oss_config();
+        $accessKeyId = $conf['accessKeyId'];
+        $accessKeySecret = $conf['accessKeySecret'];
+        $region = $conf['region'];
+        $bucket = $conf['bucket'];
+        $endpoint = $conf['endpoint'];
+        $host = $conf['host'];
+
+        // 1. 获取OSS的签名信息
+        $date_folder = date('Ymd');
+        $dir = "uploads/{$date_folder}/";
+
+        //1 .设置上传子目录(按日期分类)
+        $expiration = date('Y-m-d\TH:i:s\Z', time() + 300); // 5分钟后过期
+        $conditions = [
+            ["content-length-range", 0, 1048576000], // 限制文件大小,这里设置为最大1GB
+            ["starts-with", '$key', $dir] // 限制文件上传的目录前缀
+        ];
+        $policy = json_encode(['expiration' => $expiration, 'conditions' => $conditions]);
+        $base64Policy = base64_encode($policy);
+        // 2. 计算签名
+        $signature = base64_encode(hash_hmac('sha1', $base64Policy, $accessKeySecret, true));
+
+        // 3. 返回给前端的数据
+        $response = [
+            'accessKeyId'  => $accessKeyId,
+            'accessKeySecret'=>$accessKeySecret,
+            'bucket'    => $bucket,
+            'region'    => $region,
+            'dir'       => $dir,
+            'policy'    => $base64Policy,
+            'signature' => $signature,
+            'host'      => $host,
+            'expire'    => time() + 3600,
+            'oss_url'=>$this->oss_basic_url,
+            'show_url'=>$this->show_basie_url
+        ];
+        return [
+            'code'=>1,
+            'msg'=>'success',
+            'data'=>$response
+        ];
+    }
+
+    //对于存到阿里云的oss 进行类别区分
+    public function getOssSignType($type){
+        if(empty($type)){
+            return [
+                "code"=>-1,
+                "msg"=>"存储类别不对",
+                "data"=>[]
+            ];
+        }
+        $conf = $this->get_oss_config();
+        $accessKeyId = $conf['accessKeyId'];
+        $accessKeySecret = $conf['accessKeySecret'];
+        $region = $conf['region'];
+        $bucket = $conf['bucket'];
+        $endpoint = $conf['endpoint'];
+        $host = $conf['host'];
+
+        // 1. 获取OSS的签名信息
+        $date_folder = date('Ymd');
+        $dir = "{$type}/{$date_folder}/";
+
+        //1 .设置上传子目录(按日期分类)
+        $expiration = date('Y-m-d\TH:i:s\Z', time() + 300); // 5分钟后过期
+        $conditions = [
+            ["content-length-range", 0, 1048576000], // 限制文件大小,这里设置为最大1GB
+            ["starts-with", '$key', $dir] // 限制文件上传的目录前缀
+        ];
+        $policy = json_encode(['expiration' => $expiration, 'conditions' => $conditions]);
+        $base64Policy = base64_encode($policy);
+        // 2. 计算签名
+        $signature = base64_encode(hash_hmac('sha1', $base64Policy, $accessKeySecret, true));
+
+        // 3. 返回给前端的数据
+        $response = [
+            'accessKeyId'  => $accessKeyId,
+            'accessKeySecret'=>$accessKeySecret,
+            'bucket'    => $bucket,
+            'region'    => $region,
+            'dir'       => $dir,
+            'policy'    => $base64Policy,
+            'signature' => $signature,
+            'host'      => $host,
+            'expire'    => time() + 3600,
+            'oss_url'=>$this->oss_basic_url,
+            'show_url'=>$this->show_basie_url
+        ];
+        return [
+            'code'=>1,
+            'msg'=>'success',
+            'data'=>$response
+        ];
+    }
+
+}