获取小程序页面二维码乱码
一、C接口小程序二维码文档示例值错误(2018.03.08)
{"path": "pages/index?query=1", "width": 430}
改为
{"path": "pages/index/index?query=1", "width": 430}
如果按照示例的开发,微信扫码会提示页面不存在。
二、接口返回的是"不可描述"的二进制数据(看起来就是很长很长很长很长的乱码),有两种方式处理(A接口B接口C接口适用)
1、将返回的数据base64并赋值,如下,假如$response是接口返回的数据
-
$data='image/png;base64,'.base64_encode($response);
-
echo '<img src="data:'.$data.'">';
2、将返回的数据保存成图片,假如$stream是返回的数据
-
/**
-
* 将二进制流以图片存入硬盘
-
* @param string $stream
-
* @param string $path
-
*/
-
function to_image($stream,$dir,$file_name){
-
$result=['status'=>self::RETURN_STATUS_ERR];
-
if(empty($stream))
-
{
-
$result['message']='nostream';;
-
return $result;
-
}
-
if (!is_dir($dir)){
-
$is_make=mkdir($dir,0777,true);
-
chmod($dir,0777);
-
var_dump($is_make);
-
}
-
$file_path=$dir.$file_name;
-
$file = fopen($file_path,"w");//打开文件准备写入
-
fwrite($file,$stream);//写入
-
fclose($file);//关闭
-
// $is_put=file_put_contents($file_path,$stream);
-
//图片是否存在
-
if(!file_exists($file_path))
-
{
-
$result['message']="文件写入失败:($file_path)";
-
return $result;
-
}
-
$result['message']='ok';
-
$result['data']['file_path']=$file_path;
-
return $result;
-
}
完。
--------------------- 本文来自 chenYoper-陈永鹏 的**** 博客 ,全文地址请点击:https://blog.****.net/chenyoper/article/details/79484775?utm_source=copy