Download.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Spider\Lib;
  3. use Dever;
  4. class Download
  5. {
  6. private $data;
  7. public function __construct($url, $param)
  8. {
  9. if (isset($param['request_type']) && $param['request_type'] == 2) {
  10. $param['request_type'] = 'post';
  11. } else {
  12. $param['request_type'] = 'get';
  13. }
  14. if (isset($param['content_type']) && $param['content_type'] == 2) {
  15. $param['content_type'] = true;
  16. } else {
  17. $param['content_type'] = false;
  18. }
  19. if (!isset($param['param'])) {
  20. $param['param'] = array();
  21. }
  22. if (!isset($param['header'])) {
  23. $param['header'] = false;
  24. }
  25. $this->data = Dever::curl($url, $param['param'], $param['request_type'], $param['content_type'], $param['header']);
  26. }
  27. public function get($type)
  28. {
  29. return $this->filter($this->data, $type);
  30. }
  31. private function filter($string, $type)
  32. {
  33. if ($type != 'json') {
  34. $encode = mb_detect_encoding($string, array('GB2312','GBK','UTF-8'));
  35. $config = array('GB2312', 'GBK', 'EUC-CN', 'CP936');
  36. if (in_array($encode, $config)) {
  37. $string = iconv('GBK', 'UTF-8', $string);
  38. }
  39. /*
  40. if ($encode == 'CP936') {
  41. $string = iconv('SJIS', 'UTF-8', $string);
  42. }
  43. */
  44. $string = str_replace(PHP_EOL, '', $string);
  45. }
  46. return $string;
  47. }
  48. }