-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit abc520c
Showing
9 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
composer.lock | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
language: php | ||
|
||
php: | ||
- '5.4' | ||
- '5.5' | ||
- '5.6' | ||
- '7.0' | ||
- hhvm | ||
- nightly | ||
|
||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- php: hhvm | ||
- php: nightly | ||
|
||
services: | ||
- memcached | ||
|
||
before_install: | ||
- phpenv config-add tests/travis.ini | ||
|
||
install: | ||
- composer install --no-interaction | ||
|
||
script: | ||
- phpunit --verbose --stderr --coverage-clover build/logs/clover.xml | ||
|
||
after_success: | ||
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar | ||
- travis_retry php coveralls.phar -v --exclude-no-stmt | ||
|
||
notifications: | ||
webhooks: | ||
- http://build.miaoxingyun.com/travis-notifications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 二维码 | ||
|
||
[![Build Status](https://img.shields.io/travis/miaoxing/qrcode/master.svg?style=flat-square)](https://travis-ci.org/miaoxing/qrcode) | ||
[![Coverage Status](https://img.shields.io/coveralls/miaoxing/qrcode.svg?style=flat-square)](https://coveralls.io/r/miaoxing/qrcode?branch=master) | ||
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://www.opensource.org/licenses/MIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "miaoxing/qrcode", | ||
"description": "Miaoxing QR Code Plugin", | ||
"keywords": [ | ||
"miaoxing", "qrcode" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"miaoxing/app": "dev-master@dev", | ||
"t0k4rt/phpqrcode": "dev-master@dev" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Miaoxing\\Qrcode\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"MiaoxingTest\\Qrcode\\": "tests" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"repositories": [ | ||
{ | ||
"type": "package", | ||
"package": { | ||
"name": "t0k4rt/phpqrcode", | ||
"version": "dev-master", | ||
"source": { | ||
"url": "https://github.com/t0k4rt/phpqrcode", | ||
"type": "git", | ||
"reference": "origin/master" | ||
}, | ||
"autoload": { | ||
"classmap": ["phpqrcode.php"] | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/miaoxing/plugin/tests/bootstrap.php" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Default Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
<directory>resource</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Miaoxing\Qrcode\Controller; | ||
|
||
class Qrcode extends \miaoxing\plugin\BaseController | ||
{ | ||
protected $guestPages = ['qrcode/show']; | ||
|
||
public function showAction($req) | ||
{ | ||
$validator = wei()->validate([ | ||
'data' => $req, | ||
'rules' => [ | ||
'text' => [ | ||
|
||
] | ||
], | ||
'names' => [ | ||
'text' => '文本内容' | ||
] | ||
]); | ||
if (!$validator->isValid()) { | ||
return $this->err($validator->getFirstMessage()); | ||
} | ||
|
||
// 文本内容 | ||
$text = $req['text'] ?: ''; | ||
|
||
// 相对大小,内容越多,图片越大 | ||
$size = $req['size'] ?: 3; | ||
|
||
// 精度越高,图片越大,识别率越高,取值为0 - 4 | ||
$level = $req['level'] ?: 3; | ||
|
||
$logo = $req['logo']; | ||
|
||
$logoSize = $req['logoSize'] ?: 30; | ||
|
||
// 生成二维码图片资源对象 | ||
$enc = \QRencode::factory($level, $size, 0); | ||
$tab = $enc->encode($text); | ||
$maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab))); | ||
$image = \QRimage::image($tab, min($size, $maxSize), 0); | ||
|
||
// TODO 支持远程图片 | ||
// 将LOGO放置到图片中间 | ||
/*if ($logo && substr($logo, 0, 4) != 'http') { | ||
if (!file_exists($logo)) { | ||
return $this->err('图片无效或者不存在'); | ||
} | ||
$logoImg = null; | ||
switch (strtolower(substr($logo, strrpos($logo, '.') + 1))) { | ||
case 'jpg': | ||
$logoImg = imagecreatefromjpeg($logo); | ||
break; | ||
case 'png': | ||
$logoImg = imagecreatefrompng($logo); | ||
break; | ||
case 'gif': | ||
$logoImg = imagecreatefromgif($logo); | ||
break; | ||
default: | ||
return $this->err('不支持该图片类型'); | ||
} | ||
$bgX = imagesx($image); | ||
$bgY = imagesy($image); | ||
$logoX = imagesx($logoImg); | ||
$logoY = imagesy($logoImg); | ||
// 缩放logo | ||
$tmpImg = imagecreatetruecolor($logoSize, $logoSize); | ||
imagecopyresampled($tmpImg, $logoImg, 0, 0, 0, 0, $logoSize, $logoSize, $logoX, $logoY); | ||
imagecopyresized($image, $tmpImg, ($bgX - $logoSize) / 2, ($bgY - $logoSize) / 2, 0, 0, $logoSize, $logoSize, $logoSize, $logoSize); | ||
imagedestroy($logoImg); | ||
imagedestroy($tmpImg); | ||
}*/ | ||
|
||
// 生成图片内容 | ||
ob_start(); | ||
imagepng($image); | ||
$content = ob_get_clean(); | ||
imagedestroy($image); | ||
|
||
if (!$req['download']) { | ||
// 展示图片 | ||
$this->response->setHeader('Content-type', 'image/png'); | ||
} else { | ||
// 下载图片 | ||
$this->response->setHeader(array( | ||
'Content-Description' => 'File Transfer', | ||
'Content-Type' => 'application/x-download', | ||
'Content-Disposition' => 'attachment;filename=qrcode.png', | ||
'Content-Transfer-Encoding' => 'binary', | ||
'Expires' => '0', | ||
'Cache-Control' => 'must-revalidate', | ||
'Pragma' => 'public', | ||
'Content-Length' => strlen($content), | ||
)); | ||
} | ||
|
||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Miaoxing\Qrcode; | ||
|
||
class Plugin extends \miaoxing\plugin\BasePlugin | ||
{ | ||
public $name = '二维码'; | ||
|
||
public $description = '通过URL参数生成二维码'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace MiaoxingTest\Qrcode\Controller; | ||
|
||
use Miaoxing\Plugin\Test\BaseControllerTestCase; | ||
|
||
class QrcodeTest extends BaseControllerTestCase | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
date.timezone = "Asia/Shanghai" | ||
extension="memcached.so" |