//XML转数组
if (!function_exists('xmlToArray')) {
/**
* XML转数组
* @param xml XML数组
* @return string 返回图片地址
*/
function xmlToArray(string $xml, $oldStr = [], $newStr = [])
{
//过滤特殊xml 格式
if (!empty($oldStr)) {
$xml = str_replace($oldStr, $newStr, $xml);
}
$objectXml = simplexml_load_string($xml); //将文件转换成对象
$xmlJson = json_encode($objectXml); //将对象转换个JSON
$xmlArray = json_decode($xmlJson, true); //将json转换成数组
return $xmlArray;
}
}
use Endroid\QrCode\QrCode;
//生成二维码
if (!function_exists('create_code')) {
/**
* 生成二维码
* @param url $url 地址
* @return string 返回图片地址
*/
function create_code($url="", $name,$logo="")
{
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$qrCode = new QrCode();
$qrCode->setText($url);
if(!empty($logo)){
$qrCode->setLogoPath(ROOT_PATH . 'public/image/logo/'.$logo);
}
$qrCode->setSize(150);
$qrCode->setWriterByName('png');
$qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
if (!is_dir($qrcodePath)) {
@mkdir($qrcodePath);
}
if (is_really_writable($qrcodePath)) {
$filePath = $qrcodePath . $name . '.' . 'png';
$qrCode->writeFile($filePath);
}
return '/uploads/qrcode/' . $name . '.' . 'png';
}
}