Alibaba.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\extend\upload;
  3. class Alibaba
  4. {
  5. public $name = '阿里巴巴云存储';
  6. public $ver = '1.0';
  7. private $config = [];
  8. public function __construct($config = []) {
  9. $this->config = $config;
  10. }
  11. public function submit($file_path)
  12. {
  13. $filePath = ROOT_PATH . $file_path;
  14. $url = 'https://kfupload.alibaba.com/kupload';
  15. $data = [];
  16. $data['scene'] = 'aeMessageCenterV2ImageRule';
  17. $data['name'] = 'player.jpg';
  18. if (class_exists('CURLFile')) {
  19. $data['file'] = new \CURLFile(realpath($file_path));
  20. } else {
  21. $data['file'] = '@'.realpath($file_path);
  22. }
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, $url);
  25. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  26. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  27. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
  28. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  29. $httpheader[] = "Accept:application/json";
  30. $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
  31. $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
  32. $httpheader[] = "Connection:close";
  33. $ip = mt_rand(48, 140) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240); //随机 ip
  34. $httpheader[] = 'CLIENT-IP:' . $ip;
  35. $httpheader[] = 'X-FORWARDED-FOR:' . $ip;
  36. curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
  37. curl_setopt($ch, CURLOPT_POST, 1);
  38. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  39. curl_setopt($ch, CURLOPT_USERAGENT, 'Dalvik/2.1.0 (Linux; U; Android 10; ONEPLUS A5010 Build/QKQ1.191014.012)');
  40. curl_setopt($ch, CURLOPT_ENCODING, "gzip");
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  42. $html = @curl_exec($ch);
  43. curl_close($ch);
  44. $json = @json_decode($html,true);
  45. if($json['code']=='0'){
  46. $file_path = $json['url'];
  47. empty($this->config['keep_local']) && @unlink($filePath);
  48. }
  49. return $file_path;
  50. }
  51. }