mingyun / mingyun.github.io

github主页
158 stars 92 forks source link

php 生成图片 #102

Open mingyun opened 7 years ago

mingyun commented 7 years ago
<?php
error_reporting(7);
define('ROOT', getcwd());
define('BASEDIR', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if ($_POST['text']) {
    $ret  = array();
    $text = $_POST['text'];
    try {
        $ret['imgurl'] = text2img($text, (array) $_REQUEST['config']);
    }
    catch (Exception $e) {
        $ret['imgurl'] = print_r($e, true);
    }
    echo str_replace('\\/', '/', json_encode($ret));
    exit(0);
}
function text2img($text, $options = array())
{

    //http://yuncode.net/code/c_51dd01a4d547f26
    $rows      = substr_count($text, "\n") + 1;
    $font_path = $options['fontfile'] ? $options['fontfile'] : ROOT . '/simhei.ttf';//cp /c/Windows/Fonts/simhei.ttf .
    if (!file_exists($font_path))
        throw new Exception(" 找不到字体文件:$font_path  ");
    $font_size       = $options['fontsize'] ? $options['fontsize'] : 12;
    $padding         = $options['padding'] ? $options['padding'] : 30;
    $row_plus_height = $options['row_plus_height'] ? $options['row_plus_height'] : 4;
    $border          = 1;
    $im_width        = 430;
    $im_height       = ($row_plus_height + ($font_size * 4) / 3) * $rows + ($padding + $border) * 2;
    $im              = @imagecreatetruecolor($im_width, $im_height);
    if (!$im)
        throw new Exception("初始化图片失败,请检查 GD 配置");
    imagefilledrectangle($im, $border, $border, ($im_width - 2 * $border), ($im_height - 2 * $border), imagecolorallocate($im, 255, 255, 255));
    imagettftext($im, $font_size, 0, ($border + $padding), (($font_size * 4) / 3 + $border + $padding), imagecolorallocate($im, 0, 0, 0), $font_path, $text);
    $base_path      = '/files';
    $base_filename  = date("Y-m-d,H-i-s") . '.png';
    $short_filename = $base_path . '/' . $base_filename;
    $short_url      = rtrim(BASEDIR, '/') . $short_filename;
    @mkdir(ROOT . $base_path, 0777, true);
    $filename = ROOT . $short_filename;
    if (!imagepng($im, $filename)) {
        throw new Exception("创建图片时出错。");
    }
    @imagedestroy($im);
    return $short_url;
}

?>

<!DOCTYPE HTML><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>长微博工具</title>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6.2/jquery.min.js"></script> 
</head>
<body>
<h1>长微博工具</h1>
<p><textarea name="text" id="text" rows="20" cols="60"></textarea></p>
<pre id="pre"></pre>
<p><a target="_blank" href="" id="url"></a></p>
<p><input type="button" id="format" value="格式化" /><input type="button" id="button" value="生成长微博" /> <br/><br/><br/><br/> <a href="http://changweibo.debake.com/" style="font-size:9px; color:#666; text-decoration:none">长微博</a></p>
<script type="text/javascript">
BIG_FONT_WIDTH = 44;

function f(v,w,c){
    c = 0;
    w = w || BIG_FONT_WIDTH;
    return v.replace(/[\S\s]/g,function(a){
        if(/[\r\n]/.test(a)) {
            c = -2;
            return "\r\n";
        }
        c += /[\x00-\xFF]/.test(a) ? 1 : 2;
        if(c>=w){
            c = 0;
            return "\r\n"+a;
        }
        return a;
    });
}
$(function(){
    $("#format").click(function(){$("#text").val(f($("#text").val()));});
    $("#button").click(function(){
        if($("#text").val().length<1){
            alert("无内容");
        } else {
            $.ajax({
                type:"POST",
                url:location.pathname,
                data:"text="+$("#text").val(),
                dataType:"json",
                success:function(m){
                    if(m.message)$("#pre").innerHTML(m.message);
                    if(m.imgurl)$("#url").attr("href", m.imgurl).text(m.imgurl);
                }
            });
        }
    });
});
</script>
</body>
</html>
//https://github.com/xiaomingplus/text2pic https://www.canva.com/ 图片相似度https://github.com/jenssegers/imagehash 
/*
* array unique_rand( int $min, int $max, int $num )
* 生成一定数量的不重复随机数
* $min 和 $max: 指定随机数的范围
* $num: 指定生成数量http://yuncode.net/code/c_54793886b082e24
*/
function unique_rand($min, $max, $num) {
    $count = 0;
    $return = array();
    while ($count < $num) {
        $return[] = mt_rand($min, $max);
        $return = array_flip(array_flip($return));
        $count = count($return);
    }
    shuffle($return);
    return $return;
}

$arr = unique_rand(1, 25, 16);
mingyun commented 7 years ago
$figureDataRaw=[['user_id'=>1,'fee'=>3],['user_id'=>10,'fee'=>30000],['user_id'=>100,'fee'=>34512],['user_id'=>666,'fee'=>66666]];
$spans =[
            '5万以下' => [0, 50000],
            '5万-10万' => [50000, 100000],
            '10万-20万' => [100000, 200000],
            '20万-50万' => [200000, 500000],
            '50万-100万' => [500000, 1000000],
            '100万以上' => [1000000, '~']
        ];
        $figureData = [];
        // 初始化表格数据
        foreach ($spans as $name => $spanItem){
            $figureData[$name] = 0;
        }
        foreach ($figureDataRaw as $row){
            foreach ($spans as $name => $span) {
                $leftBound = $span[0];
                $rightBound = $span[1];

                if($row['fee'] > $leftBound && ($row['fee'] <= $rightBound || $rightBound == '~')){
                    if(isset($figureData[$name])){
                        $figureData[$name]+=1;
                    }else{
                        $figureData[$name] = 0;
                    }
                }

            }
        }
        print_r($figureData);
Array
(
    [5万以下] => 3
    [5万-10万] => 1
    [10万-20万] => 0
    [20万-50万] => 0
    [50万-100万] => 0
    [100万以上] => 0
)
$datesStr = implode("','", $unCachedDates);
$sql = 'select DATE_FORMAT(user_vips.created_at, \'%Y-%m-%d\') date, count(*) count from user_vips join users on users.id=user_vips.user_id where  user_vips.is_payed = 1 and users.parent_id=0 and DATE_FORMAT(user_vips.created_at, \'%Y-%m-%d\') in (\''.$datesStr.'\') group by date';
$start_times = Date("Y-m")."-01 00:00:00";
$week_start = Date("Y-m-d",strtotime('last Monday'))." 00:00:00";
>>> Date("Y-m-d",strtotime('-2 Monday'))
=> "2017-09-18"
$d = new DateTime( '2010-01-08' );
$d->modify( 'first day of next month' );//$d->modify( 'first day of +1 month' );
        if(date("m",strtotime($week_start))!=date("m")){
            $week_start = $start_times;
        }
        $week_end = Date("Y-m-d",strtotime('next Sunday'))." 23:59:59";

$file = $this->request->file('resfile');
$file_src=Upload::uploadFileLocal($file,'exel');//echo $file_src;die;
            $file_src=storage_path().DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR.$file_src;
            $data_arr = Excel::selectSheets('Sheet1')->load($file_src, function($reader) {})->toArray();
            if(file_exists($file_src)){
                @unlink($file_src);
            }
function checkStingAllow($value)
    {
        $value = trim($value);
        $value = trim($value, "\xEF\xBB\xBF");

        if (mb_strwidth($value, 'utf-8') > 16) {//中文2个字符英文1个
            throw new \Exception('字符长度超过限制');
        }

        $strMatch = "/^[\w\x{4e00}-\x{9fa5}]+$/u";

        if (!preg_match_all($strMatch, $value)) {
            throw new \Exception('当前处理数据中有特殊字符');
        }
    }
$file = Request::file('suggest_batch');

        $file = file_get_contents($file->getRealPath());
select max(count) from (select DATE_FORMAT(created_at, '%Y-%m-%d') date, count(*) count from users group by date) t;
gethostbyname('')//本机ip

小人举牌图片生成 抓取网页截图https://www.v2ex.com/t/71136 https://gist.github.com/vibbow/5702882 网页截图https://wkhtmltopdf.org/downloads.html wkhtmltoimage http://www.oschina.net/ oschina.jpg 如果wkhtmltopdf中文显示空白或者乱码方框,打开windows c:\Windows\fonts\simsun.ttc(在网上下载simsun.ttc也可以)拷贝到linux服务器/usr/share/fonts/目录下,再次生成pdf中文显示正常 http://blog.csdn.net/qq_14873105/article/details/51394026 $r=shell_exec("/user/bin/wkhtmltoimage -q {$filename}.html {$filename}.jpg"); php文字生成图片https://github.com/xiaomingplus/text2pic 中文字体/c/windows/fonts/sihei.ttf

https://github.com/mikehaertl/phpwkhtmltopdf  https://stackoverflow.com/questions/5663814/how-do-i-get-wkhtmltopdf-to-execute-via-php https://github.com/knplabs/snappy http://www.jianshu.com/p/4d65857ffe5e
exec("/path/to/binary/wkhtmltopdf http://www.google.com pdf1.pdf", $out);
exec('wkhtmltopdf http://somesite.com /home/user/file.pdf 2>&1');
exec("/usr/local/bin/wkhtmltopdf ../uploads/test.pdf");
$file = "../uploads/test.pdf";
$pdf = file_get_contents("../uploads/test.pdf");

header('Content-Type: application/pdf');
header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Length: '.strlen($pdf));
header('Content-Disposition: inline; filename="'.basename($file).'";');
ob_clean(); 
flush(); 
echo $pdf;

composer require mikehaertl/phpwkhtmltopdf
require './vendor/autoload.php';
use mikehaertl\wkhtmlto\Image;
use Knp\Snappy\Pdf as newpdf;
// You can pass a filename, a HTML string, an URL or an options array to the constructor
$image = new Image('/path/to/page.html');
$image->saveAs('/path/to/page.png');//保存

// ... or send to client for inline display
$image->send();//浏览器显示

// ... or send to client as file download
$image->send('page.png');//浏览器显示并下载

$snappy = new newpdf('wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
// echo $snappy->getOutput('http://www.github.com');
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', 'bill-123.pdf');
http://blog.csdn.net/aa584235166/article/details/50512338 http://blog.csdn.net/zgyulongfei/article/details/48845373
function ip2num($ip)
{
$ipa=explode(".",$ip);
return $ipa[0]*256*256*256+$ipa[1]*256*256+$ipa[2]*256+$ipa[3];
}
>>> import socket
>>> import struct
>>> ip = '119.75.218.77'
>>> num_ip=socket.ntohl(struct.unpack("I",socket.inet_aton(str(ip)))[0])
>>> num_ip
2001459789L
>>> ip = socket.inet_ntoa(struct.pack('I',socket.htonl(num_ip)))
>>> ip
'119.75.218.77'

查看Windows 7的历史开机/关机时间https://blog.vsean.net/page/8 https://blog.vsean.net/post/178

mingyun commented 6 years ago
<html>
<head>
<meta charset="UTF-8">
<title>省市二级联动</title>
</head> 
<body onload="init()"> 
<select id="province" size=1 onchange="getCity()"> 
<option value= 0 >北京</option> 
<option value= 1 >上海</option> 
<option value= 2 >天津</option> 
<option value= 3 >重庆</option> 
<option value= 4 >河北</option> 
<option value= 5 >山西</option> 
<option value= 6 >内蒙古</option> 
<option value= 7 >辽宁</option> 
<option value= 8 >吉林</option> 
<option value= 9 >黑龙江</option> 
<option value= 10 >江苏</option> 
<option value= 11 >浙江</option> 
<option value= 12 >安徽</option> 
<option value= 13 >福建</option> 
<option value= 14 >江西</option> 
<option value= 15 >山东</option> 
<option value= 16 >河南</option> 
<option value= 17 >湖北</option> 
<option value= 18 >湖南</option> 
<option value= 19 >广东</option> 
<option value= 20 >广西</option> 
<option value= 21 >海南</option> 
<option value= 22 >四川</option> 
<option value= 23 >贵州</option> 
<option value= 24 >云南</option> 
<option value= 25 >西藏</option> 
<option value= 26 >陕西</option> 
<option value= 27 >甘肃</option> 
<option value= 28 >宁夏</option> 
<option value= 29 >青海</option> 
<option value= 30 >新疆</option> 
<option value= 31 >香港</option> 
<option value= 32 >澳门</option> 
<option value= 33 >台湾</option> 
</select>

<select id="city" style="width:60px"> 
</select> 
<script> 
var arr = new  Array();
arr[0 ]="东城,西城,崇文,宣武,朝阳,丰台,石景山,海淀,门头沟,房山,通州,顺义,昌平,大兴,平谷,怀柔,密云,延庆" 
arr[1 ]="黄浦,卢湾,徐汇,长宁,静安,普陀,闸北,虹口,杨浦,闵行,宝山,嘉定,浦东,金山,松江,青浦,南汇,奉贤,崇明" 
arr[2 ]="和平,东丽,河东,西青,河西,津南,南开,北辰,河北,武清,红挢,塘沽,汉沽,大港,宁河,静海,宝坻,蓟县" 
arr[3 ]="万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,秀山,酉阳,彭水,江津,合川,永川,南川" 
arr[4 ]="石家庄,邯郸,邢台,保定,张家口,承德,廊坊,唐山,秦皇岛,沧州,衡水" 
arr[5 ]="太原,大同,阳泉,长治,晋城,朔州,吕梁,忻州,晋中,临汾,运城" 
arr[6 ]="呼和浩特,包头,乌海,赤峰,呼伦贝尔盟,阿拉善盟,哲里木盟,兴安盟,乌兰察布盟,锡林郭勒盟,巴彦淖尔盟,伊克昭盟" 
arr[7 ]="沈阳,大连,鞍山,抚顺,本溪,丹东,锦州,营口,阜新,辽阳,盘锦,铁岭,朝阳,葫芦岛" 
arr[8 ]="长春,吉林,四平,辽源,通化,白山,松原,白城,延边" 
arr[9 ]="哈尔滨,齐齐哈尔,牡丹江,佳木斯,大庆,绥化,鹤岗,鸡西,黑河,双鸭山,伊春,七台河,大兴安岭" 
arr[10 ]="南京,镇江,苏州,南通,扬州,盐城,徐州,连云港,常州,无锡,宿迁,泰州,淮安" 
arr[11 ]="杭州,宁波,温州,嘉兴,湖州,绍兴,金华,衢州,舟山,台州,丽水" 
arr[12 ]="合肥,芜湖,蚌埠,马鞍山,淮北,铜陵,安庆,黄山,滁州,宿州,池州,淮南,巢湖,阜阳,六安,宣城,亳州" 
arr[13 ]="福州,厦门,莆田,三明,泉州,漳州,南平,龙岩,宁德" 
arr[14 ]="南昌市,景德镇,九江,鹰潭,萍乡,新馀,赣州,吉安,宜春,抚州,上饶" 
arr[15 ]="济南,青岛,淄博,枣庄,东营,烟台,潍坊,济宁,泰安,威海,日照,莱芜,临沂,德州,聊城,滨州,菏泽" 
arr[16 ]="郑州,开封,洛阳,平顶山,安阳,鹤壁,新乡,焦作,濮阳,许昌,漯河,三门峡,南阳,商丘,信阳,周口,驻马店,济源" 
arr[17 ]="武汉,宜昌,荆州,襄樊,黄石,荆门,黄冈,十堰,恩施,潜江,天门,仙桃,随州,咸宁,孝感,鄂州" 
arr[18 ]="长沙,常德,株洲,湘潭,衡阳,岳阳,邵阳,益阳,娄底,怀化,郴州,永州,湘西,张家界" 
arr[19 ]="广州,深圳,珠海,汕头,东莞,中山,佛山,韶关,江门,湛江,茂名,肇庆,惠州,梅州,汕尾,河源,阳江,清远,潮州,揭阳,云浮" 
arr[20 ]="南宁,柳州,桂林,梧州,北海,防城港,钦州,贵港,玉林,南宁地区,柳州地区,贺州,百色,河池" 
arr[21 ]="海口,三亚" 
arr[22 ]="成都,绵阳,德阳,自贡,攀枝花,广元,内江,乐山,南充,宜宾,广安,达川,雅安,眉山,甘孜,凉山,泸州" 
arr[23 ]="贵阳,六盘水,遵义,安顺,铜仁,黔西南,毕节,黔东南,黔南" 
arr[24 ]="昆明,大理,曲靖,玉溪,昭通,楚雄,红河,文山,思茅,西双版纳,保山,德宏,丽江,怒江,迪庆,临沧" 
arr[25 ]="拉萨,日喀则,山南,林芝,昌都,阿里,那曲" 
arr[26 ]="西安,宝鸡,咸阳,铜川,渭南,延安,榆林,汉中,安康,商洛" 
arr[27 ]="兰州,嘉峪关,金昌,白银,天水,酒泉,张掖,武威,定西,陇南,平凉,庆阳,临夏,甘南" 
arr[28 ]="银川,石嘴山,吴忠,固原" 
arr[29 ]="西宁,海东,海南,海北,黄南,玉树,果洛,海西" 
arr[30 ]="乌鲁木齐,石河子,克拉玛依,伊犁,巴音郭勒,昌吉,克孜勒苏柯尔克孜,博 尔塔拉,吐鲁番,哈密,喀什,和田,阿克苏" 
arr[31 ]="香港" 
arr[32 ]="澳门" 
arr[33 ]="台北,高雄,台中,台南,屏东,南投,云林,新竹,彰化,苗栗,嘉义,花莲,桃园,宜兰,基隆,台东,金门,马祖,澎湖" 

function init()
{
    var city = document.getElementById("city");
    var cityArr = arr[0].split(",");
    for(var i=0;i<cityArr.length;i++)
    {
             city[i]=new Option(cityArr[i],cityArr[i]);
    }
}

function getCity()
{    
    var pro = document.getElementById("province");
    var city = document.getElementById("city");
    var index = pro.selectedIndex;
    var cityArr = arr[index].split(",");   

    city.length = 0;
    //将城市数组中的值填充到城市下拉框中
    for(var i=0;i<cityArr.length;i++)
    {
             city[i]=new Option(cityArr[i],cityArr[i]);
         }
}
</script>
</body>
</html>

https://github.com/danfengcao/binlog2sql

mingyun commented 6 years ago
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/10
 * Time: 16:57
 */
// 其中encrypt加密方式是:encrypt=AES(原串,密钥) ,使用128位的AES/ECB/PKCS5Padding对json串加密 最新的 php7 不是不支持这个了吗,改openssl
// 原串:{"userid":"guest"} 
// 密文:9b0faa7312c53d69d4de83b364112ac78557595e97159d6092d065acfb7fa8c6
print_r((new AES)->encrypt('{"userid":"guest"}'));

class AES
{
    protected $cipher = MCRYPT_RIJNDAEL_128;
    protected $mode = MCRYPT_MODE_ECB;
    protected $pad_method = NULL;
    protected $secret_key = '';
    protected $iv = '';

    public function set_cipher($cipher)
    {
        $this->cipher = $cipher;
    }

    public function set_mode($mode)
    {
        $this->mode = $mode;
    }

    public function set_iv($iv)
    {
        $this->iv = $iv;
    }

    public function set_key($key)
    {
        $this->secret_key = bin2hex($key);
    }

    public function require_pkcs5()
    {
        $this->pad_method = 'pkcs5';
    }

    protected function pad_or_unpad($str, $ext)
    {
        if ( is_null($this->pad_method) )
        {
            return $str;
        }
        else
        {
            $func_name = __CLASS__ . '::' . $this->pad_method . '_' . $ext . 'pad';
            if ( is_callable($func_name) )
            {
                $size = mcrypt_get_block_size($this->cipher, $this->mode);
                return call_user_func($func_name, $str, $size);
            }
        }
        return $str;
    }

    protected function pad($str)
    {
        return $this->pad_or_unpad($str, '');
    }

    protected function unpad($str)
    {
        return $this->pad_or_unpad($str, 'un');
    }

    public function encrypt($str)
    {
        $str = $this->pad($str);
        $td = mcrypt_module_open($this->cipher, '', $this->mode, '');

        if ( empty($this->iv) )
        {
            $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        }
        else
        {
            $iv = $this->iv;
        }

        mcrypt_generic_init($td, hex2bin($this->secret_key), $iv);
        $cyper_text = mcrypt_generic($td, $str);
        $rt = strtoupper(bin2hex($cyper_text));
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);

        return $rt;
    }

    public function decrypt($str){
        $td = mcrypt_module_open($this->cipher, '', $this->mode, '');

        if ( empty($this->iv) )
        {
            $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        }
        else
        {
            $iv = $this->iv;
        }

        mcrypt_generic_init($td, $this->secret_key, $iv);
        //$decrypted_text = mdecrypt_generic($td, self::hex2bin($str));
        $decrypted_text = mdecrypt_generic($td, base64_decode($str));
        $rt = $decrypted_text;
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);

        return $this->unpad($rt);
    }

    public static function hex2bin($hexdata) {
        $bindata = '';
        $length = strlen($hexdata);
        for ($i=0; $i< $length; $i += 2)
        {
            $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
        }
        return $bindata;
    }

    public static function pkcs5_pad($text, $blocksize)
    {
        $pad = $blocksize - (strlen($text) % $blocksize);
        return $text . str_repeat(chr($pad), $pad);
    }

    public static function pkcs5_unpad($text)
    {
        $pad = ord($text{strlen($text) - 1});
        if ($pad > strlen($text)) return false;
        if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
        return substr($text, 0, -1 * $pad);
    }
}
mingyun commented 6 years ago
class Arrobject{
    public function __get($name) {
        if(property_exists($this,$name)){
            $this->$name;
        }else{
            return '';
        }
    }

    public function __isset($name) {
        if(property_exists($this,$name)){
            $this->$name;
        }else{
            return '';
        }
    }
}
function array_to_object(array $arr)
    {
        if(empty($arr)){
            return null;
        }else{
            $object = new Arrobject();
            foreach ($arr as $k => $v){
                $object->$k = $v;
            }
            return $object;
        }
    }
function weekday($year, $week = 1){
    $year_start = mktime(0,0,0,1,1,$year);
    $year_end = mktime(0,0,0,12,31,$year);

    if (intval(date('w',$year_start)) === 1){
        $start = $year_start;
    }else{
        $start = strtotime('+1 monday',$year_start);
    }

    if ($week === 1){
        $weekday['start'] = $start;
    }else{
        $weekday['start'] = strtotime('+'.($week-0).' monday',$start);
    }

    $weekday['end'] = strtotime('+1 sunday',$weekday['start']);
    if (date('Y',$weekday['end'])!=$year){
        $weekday['end'] = $year_end;
    }
    return array_map(function($i){
        return date('Y-m-d',$i);
    },$weekday);
}
mingyun commented 6 years ago

base62 是可以的,你可以乱序一下字母表的顺序,这样就让主键较难还原了。

比如 base62 原有的字母表顺序是 0123456789abcde.....XYZ 你可以改成 0Xfeia92nje.... https://github.com/jcc/blogbuilt with Laravel and Vue.js 注意最好保证 0 在首位,因为它有定代表意义。https://segmentfault.com/q/1010000004366408 http://www.lalit.org/lab/base62-php-convert-number-to-base-62-for-short-urls/

class Base62 {

    private $string = "vPh7zZwA2LyU4bGq5tcVfIMxJi6XaSoK9CNp0OWljYTHQ8REnmu31BrdgeDkFs";

    public function base62_encode($str) {
        $out = ''; 
        for($t=floor(log10($str)/log10(62)); $t>=0; $t--) {
            $a = floor($str / pow(62, $t));
            $out = $out.substr($this->string, $a, 1); 
            $str = $str - ($a * pow(62, $t));
        }   
        return $out;
    }   

    public function base62_decode($str) {
        $out = 0;
        $len = strlen($str) - 1;
        for($t=0; $t<=$len; $t++) {
            $out = $out + strpos($this->string, substr($str, $t, 1)) * pow(62, $len - $t);
        }   
        return substr(sprintf("%f", $out), 0, -7);
    }   
}
$str = 1234567;
$object = new Base62();
echo $object->base62_encode($str) . "\n";
echo $object->base62_decode($object->base62_encode($str)) . "\n";

http://www.crazyant.net/1835.html INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;

UPDATE table SET c=c+1 WHERE a=1; php sql 注入https://github.com/ethicalhack3r/DVWA https://github.com/youzan/zanphp PHP开发面向C10K+的高并发SOA服务

mingyun commented 6 years ago
执行以下命令来安装:
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
xz -d wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar
yum install libXft

安装字体:
yum -y install fontconfig
yum -y install ttmkfdir
cd /usr/share/fonts/
 mkdir chinese
下载文件:见附件(windows 中文字体包)
unzip fonts.zip
mv fonts/* chinese/
rm -rf fonts
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
vi /etc/fonts/fonts.conf
fc-cache

安装完成执行:
cd wkhtmltox/bin
wkhtmltoimage http://www.baidu.com/ baidu.jpg 测试服务是否可用。

/**
     *  根据类型,时间计算sort
     *  1)直播用【直播实际开始时间】倒序、
     *  2)预告用【播客预设开始时间】正序、
     *  3)回放用【直播实际开始时间】倒序。
     */

    public static function getSort($webinar)
    {
        // 默认直播类型为预约
        $type = $webinar->type ? : 2;
        $time = $webinar->start_time == '0000-00-00 00:00:00' ? 1388505601 : strtotime($webinar->start_time);

        // 非预约时间根据实际时间计算
        // 无实际时间走常规时间
        if ($type != 2) {
            $time = $webinar->actual_start_time  == '0000-00-00 00:00:00' ? $time : strtotime($webinar->actual_start_time);
        }

        $sortTime = $type == 2 ? log($time) / 1000 : 1 - log($time) /1000;

        $sort = $type + $sortTime;

        // 结束不回放累加sort
        if ($webinar->type == 3 && $webinar->auto_record != '1') {
            $sort++;
        }

        return $sort;
    }
mingyun commented 6 years ago

fiddler 抓 https包 设置允许 https 然后 手机设置代理 通过 ipconfig 查看 ,然后 访问 xxx:8888 下载证书到手机,进入 设置 安全 安装刚下载的文件 MySQL导入导出数据时遇到Tab符号和换行符号怎么办http://www.crazyant.net/1901.html 1、使用select导出MySQL数据的时候,字段里的\t和\n,会自动的替换成\t和\n;

2、在使用shell、Python读取文件的时候,如果遇到了\n,不会作为行分隔符;使用split(‘\t’)函数分割的时候,如果遇到了\t,会略过;

3、使用load data向MySQL导入数据的时候,里面的\t和\n,不会作为字段分隔符和行分隔符;

id  name    remark
1   name1   我们都是屌丝程序员
2   name2   我们都是屌丝程序员\n
3   name3   我们都是\t屌丝程序员
4   name4   我们都是\t屌丝程序员\n
查看指定数据库的表的大小http://www.crazyant.net/1355.html
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
    -> from TABLES where table_schema='forexpert'
    -> and table_name='member';
查看指定数据库实例的大小mysql> select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB')
    -> as data from TABLES where table_schema='forexpert';
查询所有数据的大小

mysql> select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB')
    -> as data from TABLES;
UPDATE table_a,(SELECT id,age FROM table_b) AS tb SET table_a.age=tb.age WHERE table_a.id=tb.id;
Python封装的常用日期函数 http://www.crazyant.net/1309.html
# -*- encoding:utf-8 -*-
from hashlib import md5
import os

def generate_file_md5value(fpath):
    '''以文件路径作为参数,返回对文件md5后的值
    '''
    m = md5()
    # 需要使用二进制格式读取文件内容
    a_file = open(fpath, 'rb')    
    m.update(a_file.read())
    a_file.close()
    return m.hexdigest()

def generate_file_md5sumFile(fpath):
    fname = os.path.basename(fpath)
    fpath_md5 = "%s.md5" % fpath
    fout = open(fpath_md5, "w")
    fout.write("%s  %s\n" % (generate_file_md5value(fpath), fname.strip()))
    print "generate success, fpath:%s" % fpath_md5
    fout.flush()
    fout.close()

if __name__ == "__main__":
    fpath = "/home/users/workbench/PythonMd5/sample_file"
    # 测试一:以文件路径作为参数,获得md5后的字符串
    print generate_file_md5value(fpath)

    # 测试二:生成和linux命令:md5sum同样结果的.md5文件
    generate_file_md5sumFile(fpath)
[crazyant@localhost PythonMd5]$ more sample_file 
www.crazyant.net
www.51projob.com
[crazyant@localhost PythonMd5]$ md5sum sample_file > sample_file.md5file
[crazyant@localhost PythonMd5]$ more sample_file.md5file 
311d384505e3622ccf85d88930e2b0a0  sample_file
[crazyant@localhost PythonMd5]$ md5sum -c sample_file.md5file 
sample_file: OK
MySQL执行Select语句将结果导出到文件
mysql -h10.10.10.10 -ucrazyant -p123456 -P3306 -e "use test; select * into outfile '/tmp/rs.txt' from tb_test;"
cat runsql.sql 
use test; select * from db_test;

mysql -h10.10.10.10 -ucrazyant -p123456 -P3306 -N < runsql.sql > /tmp/rs.txt
mysql -h10.10.10.10 -ucrazyant -p123456 -P3306 -Ne "use test; select * from tb_test;" > /tmp/rs.txt
select into outfile只能在MySQL服务器上执行,客户端上无法执行;
mysql -Ne “sql” > rs.txt可以将SQL语句执行后输出为文件
mysql -N < runsql.sql > rs.txt可以执行sql文件中的内容,然后将结果输出到文件;
mysql -N的选项,表示输出时不带表头

新浪微博的mid转换成base62格式的PHP函数http://www.crazyant.net/647.html
$target_url = "http://www.crazyant.net";
$ch = curl_init();
// 抓取了本博客www.crazyant.net首页所有的超链接:
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);

if (!$html) {
    echo "<br />cURL error number:" .curl_errno($ch);
    echo "<br />cURL error:" . curl_error($ch);
    exit;
}
//创建一个DomDocument对象,用于处理一个HTML
$dom = new DOMDocument();
//从一个字符串加载HTML
@$dom->loadHTML($html);
//使该HTML规范化
$dom->normalize();

//用DOMXpath加载DOM,用于查询
$xpath = new DOMXPath($dom);
#获取所有的a标签的地址
$hrefs = $xpath->evaluate("/html/body//a//@href");

for ($i = 0; $i < $hrefs->length; $i++) {
    $href = $hrefs->item($i);
    $linktext = $href->nodeValue;
    echo $linktext;
    echo "<BR>";

}

/*
*
*函数功能:计算两个以YYYY-MM-DD为格式的日期,相差几天
*
*/
function getChaBetweenTwoDate($date1,$date2){

    $Date_List_a1=explode("-",$date1);
    $Date_List_a2=explode("-",$date2); 

    $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]); 

    $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]); 

    $Days=round(($d1-$d2)/3600/24); 

    return $Days;
}

echo getChaBetweenTwoDate('2010-08-11','2010-08-16');
mysql> select *from category;
+-------------+---------------+-----------+
| category_id | category_name | parent_id |
+-------------+---------------+-----------+
|           1 | A             |      NULL |
|           2 | B             |         1 |
|           3 | C             |         1 |
|           4 | D             |         1 |
|           5 | E             |         2 |
|           6 | F             |         2 |
|           7 | I             |         4 |
|           8 | G             |         5 |
|           9 | H             |         5 |
|          10 | J             |         7 |
|          11 | K             |        10 |
|          12 | L             |        10 |
+-------------+---------------+-----------+
查找当前节点的父节点的ID,这里使用表自身与自身连接实现
SELECT c1.parent_id, c2.category_name AS parent_name FROM category AS c1 LEFT JOIN category AS c2 ON c1.parent_id=c2.category_id WHERE c1.category_id==10;
+-----------+-------------+
| parent_id | parent_name |
+-----------+-------------+
|         7 | I           |
+-----------+-------------+
1 row in set (0.00 sec)

同时买了pid为2和3的商品的用户
select uid from T where pid=2
and uid in (select uid from T where pid=3)
select uid,count(*) as num from T where pid in(2,3) group by uid having num>1
select t1.uid from test t1 
left join (select uid from test t2 where pid=3) as t2
on t1.uid=t2.uid
where t1.pid=2

下载lnmp安装包指定10个线程,存到/tmp/: axel -n 10 -o /tmp/ http://www.linuxde.net/lnmp.tar.gz

来自: http://man.linuxde.net/axel Windows下的 Axel下载工具http://www.cnblogs.com/cpper-kaixuan/p/3669179.html
网页截图https://github.com/Runjuu/page2image
mingyun commented 6 years ago

https://github.com/firebase/php-jwt
public static function urlsafeB64Decode($input)
    {
        $remainder = strlen($input) % 4;
        if ($remainder) {
            $padlen = 4 - $remainder;
            $input .= str_repeat('=', $padlen);
        }
        return base64_decode(strtr($input, '-_', '+/'));
    }
public static function urlsafeB64Encode($input)
    {
        return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
    }private static function safeStrlen($str)
    {
        if (function_exists('mb_strlen')) {
            return mb_strlen($str, '8bit');
        }
        return strlen($str);
    }
>>> $b='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjY0MDc5MDAzIiwibmFtZSI6Ilx
1NTM2MVx1NTM2MSIsInJvb20iOiI4ODgzNDU5MTciLCJyb2xlIjoiZ3Vlc3QiLCJ1aWQiOiIxMjQ1MTQ
yNyIsInRyYWNrSWQiOiI5NDQ3NzA3OSJ9.meh6IN7iwjO-QKQw2PgGdUOTtEBFZWpOqH9iIo5Uo5A'
=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjY0MDc5MDAzIiwibmFtZSI6Ilx1NTM
2MVx1NTM2MSIsInJvb20iOiI4ODgzNDU5MTciLCJyb2xlIjoiZ3Vlc3QiLCJ1aWQiOiIxMjQ1MTQyNyI
sInRyYWNrSWQiOiI5NDQ3NzA3OSJ9.meh6IN7iwjO-QKQw2PgGdUOTtEBFZWpOqH9iIo5Uo5A"
>>> base64_decode($b)
=>
>>> \JWT::decode($b, config('app.key'),array('HS256'))
=> <stdClass #00000000134f3fc60000000072443fc8> {
       id: "64079003",
       name: "鍗″崱",
       room: "888345917",
       role: "guest",
       uid: "12451427",
       trackId: "94477079"
   }
>>> $arr=explode('.',$b)
=> [
       "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9",
       "eyJpZCI6IjY0MDc5MDAzIiwibmFtZSI6Ilx1NTM2MVx1NTM2MSIsInJvb20iOiI4ODgzNDU5
MTciLCJyb2xlIjoiZ3Vlc3QiLCJ1aWQiOiIxMjQ1MTQyNyIsInRyYWNrSWQiOiI5NDQ3NzA3OSJ9",
       "meh6IN7iwjO-QKQw2PgGdUOTtEBFZWpOqH9iIo5Uo5A"
   ]
>>> base64_decode($arr[1])
=> "{\"id\":\"64079003\",\"name\":\"\\u5361\\u5361\",\"room\":\"888345917\",\"ro
le\":\"guest\",\"uid\":\"12451427\",\"trackId\":\"94477079\"}"
>>> $s=base64_decode($arr[1])
=> "{\"id\":\"64079003\",\"name\":\"\\u5361\\u5361\",\"room\":\"888345917\",\"ro
le\":\"guest\",\"uid\":\"12451427\",\"trackId\":\"94477079\"}"
>>> json_decode($s,1)
=> [
       "id"      => "64079003",
       "name"    => "鍗″崱",
       "room"    => "888345917",
       "role"    => "guest",
       "uid"     => "12451427",
       "trackId" => "94477079"
   ]
滑动验证码破解示例https://github.com/DaiZhongyi/crack-geetest
极验证 Composer Packagehttps://github.com/JellyBool/geeCaptcha
https://github.com/HaleyLeoZhang/slide-verify/blob/master/Mine/Slide.php
https://github.com/Alvin9999/new-pac/wiki/%E8%B0%B7%E6%AD%8C%E9%95%9C%E5%83%8F
 app\Providers\AppServiceProvider.php
public function register()
    {
        $this->app->bind(
            'Illuminate\Contracts\Auth\Registrar',
            'App\Services\Registrar'
        );
    }
 config/app.php 
 'App\Providers\AppServiceProvider',
在profile文件中设置相关环境变量
# vi /etc/profile
http_proxy=192.168.10.91:3128 # 分别指定http、https、ftp协议使用的代理服务器地址
https_proxy=192.168.10.91:3128
ftp_proxy=192.168.10.91:3128
no_proxy=192.168.10.0. # 访问局域网地址(192.168.20.0/24网段)时不使用代理,可以用逗号分隔多个地址
export http_proxy https_proxy ftp_proxy no_proxy
保存退出,注销重新登陆系统即可生效。
wget -e "http_proxy=porxyhost:port" www.baidu.com
curl -x proxy host:port www.baidu.com 
如果需要用户名密码,格式
curl -x "http://user:pwd@host:port" www.baidu.com
export http_proxy=127.0.0.1:1080
或:
export https_proxy=127.0.0.1:1080
通过 echo $http_proxy查看是否设置成功
要取消该设置:
unset http_proxy
或:
unset https_proxy

设置http代理
git config --global https.proxy https://127.0.0.1:1080
取消http代理
git config --global --unset http.proxy
https://segmentfault.com/q/1010000008584470 模拟滑动验证码
https://segmentfault.com/a/1190000010594386 集成阿里云滑动验证(python)
https://github.com/Python3WebSpider 验证码破解 
微信小程序https://github.com/alex1504/wx-guita_tab
谷歌镜像https://github.com/Alvin9999/new-pac/wiki/%E8%B0%B7%E6%AD%8C%E9%95%9C%E5%83%8F
重温PHP手册http://www.powerxing.com/php-review-oop/
中文 Python 笔记https://github.com/lovecn/notes-python https://github.com/lovecn/StackOverFlowCn
https://scriptoj.com/problems/100 MySQL入门教程https://github.com/jaywcjlove/mysql-tutorial
https://github.com/TIGERB/easy-tips/blob/master/redis/pessmistic-lock.php
https://www.waitalone.cn/security-scripts-game.html
curl --form "fileupload=@filename.txt" http://hostname/resource
 curl -d "value%201" http://hostname.com
curl --data-urlencode "value 1" http://hostname.com
curl --data @filename https://github.api.com/authorizations
function  substr_utf8($str,$start,$length){  
    return implode("",array_slice(preg_split("//u",$str,-1,PREG_SPLIT_NO_EMPTY),$start,$length));  
}  substr_count($str,'你');
function ip2num($ip)
{
$ipa=explode(".",$ip);
return $ipa[0]*256*256*256+$ipa[1]*256*256+$ipa[2]*256+$ipa[3];
}
>>> import socket
>>> import struct
>>> ip = '119.75.218.77'
>>> num_ip=socket.ntohl(struct.unpack("I",socket.inet_aton(str(ip)))[0])
>>> num_ip
2001459789L
>>> ip = socket.inet_ntoa(struct.pack('I',socket.htonl(num_ip)))
>>> ip
'119.75.218.77'