diff --git a/WeChat/Contracts/MyCurlFile.php b/WeChat/Contracts/MyCurlFile.php new file mode 100644 index 0000000..291c27e --- /dev/null +++ b/WeChat/Contracts/MyCurlFile.php @@ -0,0 +1,55 @@ +mimetype = $mimetype; + $this->postname = $postname; + $this->content = base64_encode(file_get_contents($filename)); + $this->extension = pathinfo($filename, PATHINFO_EXTENSION); + if (empty($this->extension)) $this->extension = 'tmp'; + if (empty($this->mimetype)) $this->mimetype = Tools::getExtMine($this->extension); + if (empty($this->postname)) $this->postname = pathinfo($filename, PATHINFO_BASENAME); + } + + /** + * 获取文件信息 + * @return \CURLFile|string + * @throws \WeChat\Exceptions\LocalCacheException + */ + public function get() + { + $this->tempname = rand(100000, 999999) . ".{$this->extension}"; + $this->filename = Tools::pushFile($this->tempname, base64_decode($this->content)); + if (class_exists('CURLFile')) { + return new \CURLFile($this->filename, $this->mimetype, $this->postname); + } + return "@{$this->tempname};filename={$this->postname};type={$this->mimetype}"; + } + + /** + * 类销毁处理 + */ + public function __destruct() + { + Tools::delCache($this->tempname); + } + +} \ No newline at end of file diff --git a/WeChat/Contracts/Tools.php b/WeChat/Contracts/Tools.php index 40e2371..1037836 100644 --- a/WeChat/Contracts/Tools.php +++ b/WeChat/Contracts/Tools.php @@ -50,7 +50,7 @@ class Tools /** * 根据文件后缀获取文件MINE - * @param array $ext 文件后缀 + * @param string|array $ext 文件后缀 * @param array $mine 文件后缀MINE信息 * @return string * @throws LocalCacheException