异步抓取第三方资源
文档里有 尝试了但是总是返回bad token
https://developer.qiniu.com/k...
主要问题 出现 鉴权上
Authorization: Qiniu <AccessToken>
PHP sdk 里生成的不能用
自己尝试按照文档里组装 但是一直不成功
七牛如何异步抓取第三方资源
异步抓取第三方资源
文档里有 尝试了但是总是返回bad token
https://developer.qiniu.com/k...
主要问题 出现 鉴权上
Authorization: Qiniu <AccessToken>
PHP sdk 里生成的不能用
自己尝试按照文档里组装 但是一直不成功
七牛如何异步抓取第三方资源
composer require qiniu/php-sdk -vvv
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Qiniu\Auth;
use Qiniu\Http\Client;
class SisyphusFetch
{
private $accessKey;
private $secretKey;
private $auth;
function __construct($accessKey,$secretKey)
{
$this->accessKey = $accessKey;
$this->secretKey = $secretKey;
$this->auth = new Auth($this->accessKey,$this->secretKey);
}
/*
* $zone 华东:z0;华北z1;华南:z2;北美:na0;东南亚:as0
* @return Qiniu\Http\Response Object
*/
public function post(string $body,$zone = 'z0')
{
$url = 'http://api-'.$zone.'.qiniu.com/sisyphus/fetch';
$method = 'POST';
$contentType = 'application/json';
$rtcToken = $this->auth->authorizationV2($url, $method, $body, $contentType);
$rtcToken['Content-Type'] = $contentType;
return Client::post($url, $body, $rtcToken);
}
}
$accessKey = 'Your Qiniu accessKey';
$secretKey = 'Your Qiniu secretKey';
$sisyphusFetch = new SisyphusFetch($accessKey,$secretKey);
/*
* url:你要上传的第三方资源
* bucket:你的七牛对象存储的空间名称
* 以上两个参数是必填的,其他host、key等选填
* 文档:https://developer.qiniu.com/kodo/api/4097/asynch-fetch
*/
$bodyArr = ["url" => "http://httpbin.org/robots.txt", "bucket" => "Your bucket"];
$body = json_encode($bodyArr);
$zone = 'z2';
$result = $sisyphusFetch->post($body,$zone);
print_r($result);
php index.php
https://github.com/qiniu/php-...
用这个方法鉴权就可以了