<?php
namespace app\common\service\qrcode;
use app\common\library\wechat\Qrcode;
use app\common\model\Wxapp as WxappModel;
class Base
{
public function __construct()
{
}
protected function saveQrcode($wxapp_id, $scene, $page = null)
{
$dirPath = RUNTIME_PATH . 'image' . '/' . $wxapp_id;
!is_dir($dirPath) && mkdir($dirPath, 0755, true);
$fileName = 'qrcode_' . md5($wxapp_id . $scene . $page) . '.png';
$savePath = "{$dirPath}/{$fileName}";
if (file_exists($savePath)) return $savePath;
$wxConfig = WxappModel::getWxappCache($wxapp_id);
$Qrcode = new Qrcode($wxConfig['app_id'], $wxConfig['app_secret']);
$content = $Qrcode->getQrcode($scene, $page);
file_put_contents($savePath, $content);
return $savePath;
}
protected function saveTempImage($wxapp_id, $url, $mark = 'temp')
{
$dirPath = RUNTIME_PATH . 'image' . '/' . $wxapp_id;
!is_dir($dirPath) && mkdir($dirPath, 0755, true);
$savePath = $dirPath . '/' . $mark . '_' . md5($url) . '.png';
if (file_exists($savePath)) return $savePath;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$img = curl_exec($ch);
curl_close($ch);
$fp = fopen($savePath, 'w');
fwrite($fp, $img);
fclose($fp);
return $savePath;
}
}