upload_verify_callback.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. // 控制台获取密钥:https://portal.qiniu.com/user/key
  5. $accessKey = getenv('QINIU_ACCESS_KEY');
  6. $secretKey = getenv('QINIU_SECRET_KEY');
  7. $bucket = getenv('QINIU_TEST_BUCKET');
  8. $auth = new Auth($accessKey, $secretKey);
  9. // 获取回调的 body 信息
  10. $callbackBody = file_get_contents('php://input');
  11. // 回调的 contentType
  12. $contentType = 'application/x-www-form-urlencoded';
  13. // 回调的签名信息,可以验证该回调是否来自七牛
  14. $authorization = $_SERVER['HTTP_AUTHORIZATION'];
  15. // 七牛回调的 url,具体可以参考:https://developer.qiniu.com/kodo/manual/1206/put-policy
  16. $url = 'http://172.30.251.210/upload_verify_callback.php';
  17. //参考文档:https://developer.qiniu.com/kodo/manual/1653/callback
  18. $isQiniuCallback = $auth->verifyCallback($contentType, $authorization, $url, $callbackBody);
  19. if ($isQiniuCallback) {
  20. $resp = array('ret' => 'success');
  21. } else {
  22. $resp = array('ret' => 'failed');
  23. }
  24. echo json_encode($resp);