wxCodeHttp($url, $post_data); try { $res = json_decode($result, true); if (is_array($res)) { return callBack(statusCode()['error'], $res['errmsg']); } } catch (\Exception $e) { } $arr = explode('/', $param['file_name']); unset($arr[count($arr) - 1]); $file_path = implode('/', $arr); $this->createDir($file_path); file_put_contents($param['file_name'], $result); return callBack(statusCode()['success'], '图片生成成功'); } /** * 创建微信券码发出请求 * @param $url * @param $data * @return bool|string */ public function wxCodeHttp($url, $data) { $ch = curl_init(); $header = "Accept-Charset: utf-8"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { return false; } else { return $tmpInfo; } } /** * 生成文件目录 * @param $directory_name 目录地址 */ public function createDir($directory_name) { if (!is_dir($directory_name)) { $temp = ltrim($directory_name, './'); $arr = explode('/', $temp); $str = '.'; foreach ($arr as $key => $sv) { if (!is_dir("{$str}/{$sv}")) { mkdir("{$str}/{$sv}", 0777); } $str = "{$str}/{$sv}"; } } } }