Commit 1e0ee20d authored by hujun's avatar hujun

生成二维码中间带logo

parent a7264d59
...@@ -13,10 +13,12 @@ class GenerateCodeUntils { ...@@ -13,10 +13,12 @@ class GenerateCodeUntils {
* *
* @param $param * @param $param
* @param $file_name * @param $file_name
* @param int $type
* @return string * @return string
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @throws \Endroid\QrCode\Exception\InvalidWriterException * @throws \Endroid\QrCode\Exception\InvalidWriterException
*/ */
public function getCode($param, $file_name) { public function getCode($param, $file_name, $type = 1) {
$path = 'static'.DS.'qrcode'.DS.date('Ymd'); $path = 'static'.DS.'qrcode'.DS.date('Ymd');
if (!file_exists($path)) { if (!file_exists($path)) {
...@@ -24,13 +26,19 @@ class GenerateCodeUntils { ...@@ -24,13 +26,19 @@ class GenerateCodeUntils {
} }
$qrCode = new QrCode($param); $qrCode = new QrCode($param);
$qrCode->setSize(300); $qrCode->setSize(400);
$qrCode->setWriterByName('png'); $qrCode->setWriterByName('png');
$qrCode->setMargin(10); $qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8'); $qrCode->setEncoding('UTF-8');
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]); $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]); $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
$qrCode->setValidateResult(false); $qrCode->setValidateResult(false);
if ($type == 2) {
$qrCode->setLogoPath(ROOT_PATH.'/public/static/qrcode/agent_app_logo.png');
$qrCode->setLogoWidth(80);
$qrCode->setValidateResult(false);
}
$path = $path.DS.$file_name.'.png'; $path = $path.DS.$file_name.'.png';
$qrCode->writeFile($path); $qrCode->writeFile($path);
return $path; return $path;
......
...@@ -517,6 +517,8 @@ class Broker extends Basic ...@@ -517,6 +517,8 @@ class Broker extends Basic
* 生成邀请二维码 * 生成邀请二维码
* *
* @return \think\Response * @return \think\Response
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @throws \Endroid\QrCode\Exception\InvalidWriterException
*/ */
public function qrCode() { public function qrCode() {
...@@ -534,8 +536,8 @@ class Broker extends Basic ...@@ -534,8 +536,8 @@ class Broker extends Basic
} }
$code = new GenerateCodeUntils(); $code = new GenerateCodeUntils();
$url = $this->request->domain().'/app.php/app/share_register?referrer_source=20&id='.$this->agentId; $url = $this->request->domain().'/app/share_register?referrer_source=20&id='.$this->agentId;
$path = $code->getCode($url, $this->agentId); $path = $code->getCode($url, $this->agentId, 2);
$data['data'] = ['path' => $this->request->domain().'/'.$path]; $data['data'] = ['path' => $this->request->domain().'/'.$path];
$data['status'] = 200; $data['status'] = 200;
return $this->response($data['status'], $data['msg'], $data['data']); return $this->response($data['status'], $data['msg'], $data['data']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment