<?php
|
|
namespace app\common\service\qrcode;
|
|
use Endroid\QrCode\QrCode;
|
|
/**
|
* 公众号登录二维码
|
*/
|
class MpLoginService extends Base
|
{
|
private $appId;
|
|
/**
|
* 构造方法
|
*/
|
public function __construct($appId)
|
{
|
parent::__construct();
|
$this->appId = $appId;
|
}
|
|
/**
|
* 获取
|
*/
|
public function getImage()
|
{
|
// 判断二维码文件存在则直接返回url
|
if (file_exists($this->getPosterPath())) {
|
return $this->getPosterUrl();
|
}
|
$qrcode = new QrCode(base_url().'h5/pages2/login/mplogin?app_id=' . $this->appId);
|
$qrcode = $this->saveMpQrcode($qrcode, $this->appId, '', 'image_mplogin');
|
return $this->getPosterUrl();
|
}
|
|
/**
|
* 二维码文件路径
|
*/
|
private function getPosterPath()
|
{
|
$web_path = $_SERVER['DOCUMENT_ROOT'];
|
// 保存路径
|
$tempPath = $web_path . "/temp/{$this->appId}/image_mplogin/";
|
!is_dir($tempPath) && mkdir($tempPath, 0755, true);
|
return $tempPath . $this->getPosterName();
|
}
|
|
/**
|
* 二维码文件名称
|
*/
|
private function getPosterName()
|
{
|
return 'qrcode_' . md5("{$this->appId}") . '.png';
|
}
|
|
/**
|
* 二维码url
|
*/
|
private function getPosterUrl()
|
{
|
return \base_url() . "temp/{$this->appId}/image_mplogin/{$this->getPosterName()}" . '?t=' . time();
|
}
|
|
}
|