51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

腾讯图床API接口PHP代码

腾讯图床API:https://om.qq.com/image/orginalupload

PHP代码Demo:

<?php
`$file = './test.jpg'; //本地图片路径
$ch = curl_init();
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,'https://om.qq.com/image/orginalupload');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,[
'Filedata' => new \CURLFile(realpath($file)),
'subModule' => 'userAuth_individual_head',
'id' => 'FILE_0',
'name' => '1654159987.jpg',
'type' => 'image/jpeg',
'lastModifiedDate' => 'Thu Jun 02 2022 10:04:38 GMT+0800 (中国标准时间)',
'appkey' => '1',
'isRetImgAttr' => '1',
'from' => 'user'
]);
if(curl_exec($ch) === false){
echo 'Curl error: ' . curl_error($ch);
}
$result = curl_exec($ch);
curl_close($ch);
print_r($result);`

结果

{
   "response": {
   "code": 0,
   "msg": "success!"
},
"data": {
   "url": {
     "type": 2,
     "width": 650,
     "height": 650,
     "length": 102507,
     "isqrcode": 1,
     "url": "http://inews.gtimg.com/newsapp_ls/0/14966062446/0"
    }
 }
}

其中data->url->url 即为上传后的图片地址。

更多

直接在页面中引用该外链地址(http://inews.gtimg.com/newsapp_ls/0/14966062446/0)HTTP状态显示"403 Forbidden",图片防盗链。

可以在html的head中加上<meta name="referrer" content="no-referrer" />

或者

img标签上加referrerpolicy="no-referrer"

<img src='http://inews.gtimg.com/newsapp_ls/0/14966062446/0' width="200"  referrerpolicy="no-referrer" />

更多2

关于Referrer-Policy可参考下方链接,查看其中的一个即可。

A new default Referrer-Policy for Chrome -- strict-origin-when-cross-origin:https://developer.chrome.com/blog/referrer-policy-new-chrome-default/

Referrer-Policy -- HTTP:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Referrer-Policy

引荐来源 (Referer) 和引荐来源政策 (Referrer-Policy) 最佳实践:https://web.dev/referrer-best-practices/

Referrer Policy:https://www.w3.org/TR/referrer-policy/

赞(0)
未经允许不得转载:工具盒子 » 腾讯图床API接口PHP代码