微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将二进制的数据流转为图片

  public function getQrcode(){
        $userId = $this->request->param('user_id');
        $member_app_id = $this->request->param('appid');
        $token = $this->getToken($member_app_id);
        $url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=".$token;
        $data = [
            'path' =>"pages/network/network?userId=".$userId,'scene'=>'1001','width'=>430,'auto_color'=>false,];
        $data=json_encode($data);
        $res = $this->request($url,$data);
        $data='image/png;base64,'.base64_encode($res);

        $imageName = rand(1111,9999).'.png';
        if (strstr($data,",")){
            $image = explode(',',$data);
            $image = $image[1];
        }

        $path = "./attachs/uploads/".date("Ymd",time());
        if (!is_dir($path)){ //判断目录是否存在 不存在就创建
            mkdir($path,0777,true);
        }
        $imageSrc=  $path."/". $imageName;  //图片名字

        $r = file_put_contents(ROOT_PATH .$imageSrc,base64_decode($image));//返回的是字节数
        if (!$r) {
            return json(['data'=>null,"code"=>1,"msg"=>"图片生成失败"]);
        }else{
            return json(['data'=>1,"code"=>0,"msg"=>"图片生成成功"]);
        }
        $this->result($data,200,'获取二维码成功','json');
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。