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'); }