首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >数据万象添加盲水印的时候报错怎么解决?

数据万象添加盲水印的时候报错怎么解决?

提问于 2019-08-07 12:07:22
回答 0关注 0查看 163

签名是正确的,但是给图片添加盲水印的时候,报400错误,报错信息如我上传的截图所示,请问是为什么?

报错信息如图所示

代码语言:javascript
复制
<?php
    namespace App\Http\Controllers;

    use App\Extensions\Tencent\Signature;

    class IndexController extends Controller
    {
        protected $text = 'http://watermark-1256115051.picgz.myqcloud.com/tengxunyun.png';

        protected $type = 2;

        protected $host = 'watermark-1256115051.pic.ap-guangzhou.myqcloud.com';

        protected $fileid = 'water.jpg';

        protected $key = '123.jpg';

        protected $authorization;

        protected $guzzleHttpClient;

        protected $filePath;

        protected $fileSource;

        public function __construct()
        {
            $this->guzzleHttpClient = new \GuzzleHttp\Client([
                'base_uri' => 'http://pic.ap-guangzhou.myqcloud.com',
                'timeout'  => 30,
            ]);
            $signature = new Signature(env('TENCENT_SECRETID'), env('TENCENT_SECRETKEY'));
            $this->authorization = $signature->getAuthorization('PUT', $this->key);
            $this->filePath = public_path('upload/images/20190511/abc.jpg');
            $this->fileSource = fopen($this->filePath, 'rb');
        }

        public function index()
        {
            $picOperations = array(
                'is_pic_info' => 1,
                'rules' => [
                    [
                        'fileid' => $this->fileid,
                        'rule' => 'watermark/3/type/2/image/'.base64_encode($this->text)
                    ]
                ]
            );
            $result = $this->guzzleHttpClient->request('PUT', '/'.$this->key, [
                'headers'=>[
                    'Authorization' => $this->authorization,
                    'Host' => $this->host,
                    'Content-Length' => filesize($this->filePath),
                    'Pic-Operations' => json_encode($picOperations)
                ],
                'body' => $this->fileSource
            ]);
            dd($result->getBody()->getContents());
        }

        public function urlsafeB64encode($string) {
            return base64_encode($string);
        }
    }
?>

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档