curl执行生成二维码返回一堆乱码,查了资料终于解决了。由于网上的信息过于分散,不易查看,容易误导人等等,才有了写这篇文章的动力。文章主要分为界面和后端两部分。在接口curl执行时添加这样一个header:$header=header("Content-Type:image/jpg;charset=utf-8");(注:这是单个headervalue的写法,如果有多个headervalues如果要改成$header=array("Authorization:Basic","Content-Type:application/json");这个写法,注意单个header值不能写多个header值。)添加后,界面会正常返回二维码图片。后台和后台执行curl生成二维码的时候,像接口一样加header是不能正常返回二维码的图片的。需要保存到有file_put_contents的文件夹中,返回路径才能在img中正常显示。示例代码:json_encode(array('action_name'=>'QR_LIMIT_SCENE','action_info'=>array('scene'=>array('scene_id'=>$scene_id)))));$response=json_decode(ihttp_request($url,$_data)['content'],true);$ticket=!empty($response['ticket'])?$response['ticket']:"";$_url=$_W['siteroot']."app/index.php?i=".$_W['uniacid']."&t=0&v=1.1.1&from=wxapp&c=entry&a=wxapp&do=Showqrcode&m=hotmallstore&ticket=".$票;$code=ihttp_get($_url);$file_path=ATTACHMENT_ROOT.'images/qrcode/';如果(!is_dir($file_path)){$result=mkdir($file_path,0777,true);如果($result){$path_arr=explode('/',$path);$path_str='';foreach($path_arras$val){$path_str.=$val.'/';$a=chmod($path_str,0777);}}$文件路径=$结果;}$name=$scene_id.'.png';$img_path='图片/二维码/'.$name;$filename=$file_path.$name;if(!file_exists($filename)){file_put_contents($filename,!empty($code['content'])?$code['content']:"");}?>
