upload_verify_callback.php 913 B

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