Commit 1e0ee20d authored by hujun's avatar hujun

生成二维码中间带logo

parent a7264d59
......@@ -13,10 +13,12 @@ class GenerateCodeUntils {
*
* @param $param
* @param $file_name
* @param int $type
* @return string
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @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');
if (!file_exists($path)) {
......@@ -24,13 +26,19 @@ class GenerateCodeUntils {
}
$qrCode = new QrCode($param);
$qrCode->setSize(300);
$qrCode->setSize(400);
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
$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';
$qrCode->writeFile($path);
return $path;
......
......@@ -517,6 +517,8 @@ class Broker extends Basic
* 生成邀请二维码
*
* @return \think\Response
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @throws \Endroid\QrCode\Exception\InvalidWriterException
*/
public function qrCode() {
......@@ -534,8 +536,8 @@ class Broker extends Basic
}
$code = new GenerateCodeUntils();
$url = $this->request->domain().'/app.php/app/share_register?referrer_source=20&id='.$this->agentId;
$path = $code->getCode($url, $this->agentId);
$url = $this->request->domain().'/app/share_register?referrer_source=20&id='.$this->agentId;
$path = $code->getCode($url, $this->agentId, 2);
$data['data'] = ['path' => $this->request->domain().'/'.$path];
$data['status'] = 200;
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