lnmp添加fileinfo扩展

开始编译

cd /root/oneinstack/src
tar zxvf php-5.6.20.tar.gz  # 解压已经安装的php版本
cd php-5.6.20/ext/fileinfo
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd /usr/local/php/lib/php/extensions
ls  #看到no-debug-non-zts-20131226类似文件夹
cd no-debug-non-zts-20131226
ls  #查看有没有 fileinfo.so,如果有,证明编译成功
加载fileinfo
echo 'extension=fileinfo.so' > /usr/local/php/etc/php.d/ext-fileinfo.ini

lnmp为何没有fileinfo扩展

https://www.cnblogs.com/wamptao/p/6100534.html

endroid/qrcode php生成二维码

QR Code

By endroid

Latest Stable Version Build Status Total Downloads Monthly Downloads License Donate

This library helps you generate QR codes in a jiffy.

Installation

Use Composer to install the library.

$ composer require endroid/qrcode

Basic usage

use Endroid\QrCode\QrCode;

$qrCode = new QrCode('Life is too short to be generating QR codes');

header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();

Advanced usage

use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
use Symfony\Component\HttpFoundation\Response;

// Create a basic QR code
$qrCode = new QrCode('Life is too short to be generating QR codes');
$qrCode->setSize(300);

// Set advanced options
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
$qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER);
$qrCode->setLogoPath(__DIR__.'/../assets/images/symfony.png');
$qrCode->setLogoWidth(150);
$qrCode->setValidateResult(false);

// Directly output the QR code
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();

// Save it to a file
$qrCode->writeFile(__DIR__.'/qrcode.png');

// Create a response object
$response = new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);

QR Code

Built-in validation reader

You can enable the built-in validation reader (disabled by default) by calling setValidateResult(true). This validation reader does not guarantee that the QR code will be readable by all readers but it helps you provide a minimum level of quality.

The readability of a QR code is primarily determined by the size, the input length, the error correction level and any possible logo over the image so you can tweak these parameters if you are looking for optimal results. Take note that the validator can consume quite amount of additional resources.

Symfony integration

The endroid/qrcode-bundle integrates the QR code library in Symfony for an even better experience.

  • Configure your defaults (like image size, default writer etc.)
  • Generate QR codes quickly from anywhere via the factory service
  • Generate QR codes directly by typing an URL like /qrcode/<text>.png?size=300
  • Generate QR codes or URLs directly from Twig using dedicated functions

Read the bundle documentation for more information.

Versioning

Version numbers follow the MAJOR.MINOR.PATCH scheme. Backwards compatibility breaking changes will be kept to a minimum but be aware that these can occur. Lock your dependencies for production and test your code when upgrading.

License

This bundle is under the MIT license. For the full copyright and license information please view the LICENSE file that was distributed with this source code.

Donation

If this project help you reduce time to develop, you can give me a cup of coffee 🙂

https://packagist.org/packages/endroid/qrcode

https://github.com/endroid/QrCode

 

<pre><?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;

use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\QrCode;
use Symfony\Component\HttpFoundation\Response;
/**
 *
 */
class QrcodeController extends Controller
{


    public function actionIndex()
    {
        $rgbs=[
            '0'=>['r'=>'5','g'=>'152','b'=>'71'],//绿色
            '1'=>['r'=>'0','g'=>'100','b'=>'172'],//蓝色
            '2'=>['r'=>'78','g'=>'200','b'=>'149'],//青色
            '3'=>['r'=>'15','g'=>'162','b'=>'255'],//蓝色
            '4'=>['r'=>'249','g'=>'145','b'=>'10'],//黄色
            '5'=>['r'=>'90','g'=>'175','b'=>'156'],//青色
            '6'=>['r'=>'255','g'=>'107','b'=>'149'],//粉色
            '7'=>['r'=>'7','g'=>'170','b'=>'255'],//蓝色
            '8'=>['r'=>'0','g'=>'0','b'=>'0'],//黑色
            '9'=>['r'=>'18','g'=>'219','b'=>'226'],//水蓝色
        ];
        $random_keys=array_rand($rgbs,1);
        $rgb=$rgbs[$random_keys];
        $qrCode = new QrCode('http://m.biaobai.xin');
        $qrCode->setSize(300);
        // Set advanced options
        $qrCode->setWriterByName('png');
        $qrCode->setMargin(10);
        $qrCode->setEncoding('UTF-8');
        $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
        $qrCode->setForegroundColor($rgb);
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
//        $qrCode->setLabel('Scan the code', 16, __DIR__.'/../assets/fonts/noto_sans.otf', LabelAlignment::CENTER);
        $qrCode->setLogoPath(__DIR__.'/../logo.png');
        $qrCode->setLogoWidth(80);
        $qrCode->setValidateResult(false);

         // Directly output the QR code
        header('Content-Type: '.$qrCode->getContentType());
        echo $qrCode->writeString();

        // Save it to a file
        //$qrCode->writeFile(__DIR__.'/../qrcode.png');

        // Create a response object
        $response = new Response($qrCode->writeString(), Response::HTTP_OK, ['Content-Type' => $qrCode->getContentType()]);
    }

}


?></pre>

基于ThinkPHP5实现微信自动登录、微信支付、支付宝支付、Web推送、阿里云短信、极光推送、二维码生成

ThinkPHP5

基于ThinkPHP5实现微信自动登录、微信支付、支付宝支付、Web推送、阿里云短信、极光推送、二维码生成 严格按照TP5框架目录方式上传

有些功能大家可以加以修改直接做成一个公共接口,放在application的common.php中,这样在其他控制器的方法中有需要调用的时候,直接传入参数进行调用

https://github.com/SperkJJ/ThinkPHP5

ThinkPHP5-master

使用pushState()改变url而不刷新

原文链接:http://caibaojian.com/pushstate.html

编者注:这个pushState()是一个HTML5的新接口,你可能在一些科技博客如36kr上看到过,ajax加载新的文章,并且改变网址却不需要刷新页面,本站也用到了这个,当你在首页往下拉时,加载分页内容,网址也随着改变,有利于后退和增加用户体验。

HTML5 的 pushState+Ajax

HTML5提供history接口,把URL以state的形式添加或者替换到浏览器中,其实现函数正是 pushState 和 replaceState。

pushState 例子

pushState() 的基本参数是:

window.history.pushState(state, title, url);

其中state和title都可以为空,但是推荐不为空,应当创建state来配合popstate监听。·

例如,我们通过pushState现改变URL而不刷新页面。

var state = ( {

url: ~href, title: ~title, ~additionalKEY: ~additionalVALUE

} );

window.history.pushState(state, ~title, ~href);

其中带有“~”符号的是自定义内容。就可以把这个~href(URL)推送到浏览器的历史里。如果想要改变网页的标题,应该:

document.title= ~newTitle;

注意只是pushState是不能改变网页标题的哦。

Demo 演示

(实现函数onclick = history.pushState( null, null, ‘/test-string’); )。实际上这个博客在文章之间也部署了这个技术。

replaceState 同理

window.history.replaceState( state, ~title, ~href);

pushState、replaceState 的区别

pushState()可以创建历史,可以配合popstate事件,而replaceState()则是替换掉当前的URL,不会产生历史。

限制因素

只能用同域的URL替换,例如你不能用http://baidu.com去替换http://google.com。而且state对象不存储不可序列化的对象如DOM。

Ajax 配合 pushState 例子

现在用Ajax + pushState来提供全新的ajax调用风格。以jQuery为例,为了seo需要,应该为a标签的onclick添加方法。

//code from http://caibaojian.com/pushstate.html
$("~target a").click(function(evt){

evt.preventDefault(); // 阻止默认的跳转操作

var uri=$(this).attr('href');

var newTitle=ajax_Load(uri); // 你自定义的Ajax加载函数,例如它会返回newTitle

document.title=newTitle; // 分配新的页面标题

if(history.pushState){

var state=({

url: uri, title: newTitle

});

window.history.pushState(state, newTitle, uri);

}else{ window.location.href="#!"+~fakeURI; } // 如果不支持,使用旧的解决方案

return false;

});

function ajax_Load(uri){ ... return newTitle; } // 你自定义的ajax函数,例如它会返回newTitle

即可完成pushState。至于新标题newTitle的获取就是另外的问题了,例如你可以为a标签分配data-newtitle=~title属性并届时读取,或者如果你用的$.ajax()函数,可以用$(result).filter(“title”).text()来获取。

另外如果需要对新加载的页面的连接同样使用这个ajax,则需要对新内容的a标签重新部署,例如

$("~newContentTarget a").click(function(evt){ ... });

pushState 配合 popstate 监听

想要良好的支持浏览器的历史前进后退操作,应当部署popstate监听:

window.addEventListener('popstate', function(evt){

var state = evt.state;

var newTitle = ajax_Load(state.url); //你自定义的ajax加载函数,例如它会返回newTitle

document.title=newTitle;

}, false);

来源:前端开发博客