Css3动画
python3基础之数据类型
数据类型
计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值。但是,计算机能处理的远不止数值,还可以处理文本、图形、音频、视频、网页等各种各样的数据,不同的数据,需要定义不同的数据类型。在Python中,能够直接处理的数据类型有以下几种:整数、浮点数、字符串、布尔值、空值、变量
centos7下安装python3,与python2共存
centos系统本身默认安装有python2.x,可通过 python –V 或 python –version 查看系统自带的python版本。有一些系统命令时需要用到python2,所以python2不能卸载。
一个PHP的jwt类
<?php
namespace utils;
/**
*
*/
class Jwt
{
public $KEY = 'hao';
/**
* [返回 hash 加密后的字符串]
* @param [type] $header [description]
* @param [type] $payload [description]
* @return [type] [description]
*/
private function hash_do($str, $type){
$algo = 'sha256';
if (strtoupper($type) == 'MD5'){
$algo = 'md5';
} else if(strtolower($type) == 'HAVAL'){
$algo = 'haval160,4';
}
return hash($algo, $str);
}
/**
* [create_token description]
* @param [type] $header [description]
* @param [type] $payload [description]
* @return [type] [description]
*/
public function create_token($header, $payload){
if (!empty($header) && is_array($header) &&
(strtoupper($header['alg'])=='HS256' || strtoupper($header['alg'])=='MD5' || strtoupper($header['alg'])=='HAVAL') &&
!empty($payload))
{
$h = base64_encode(json_encode($header));
$p = base64_encode(json_encode($payload));
$s = $this->hash_do($h . $p . md5($this->KEY), $header['alg']);
$sign = $h. '.' . $p . '.' . $s;
return $sign;
}
return null;
}
public function check_token($jwt){
if (empty($jwt)){
return false;
}
$tokens = explode('.', $jwt);
if (count($tokens)!==3){
return false;
}
list($header64, $payload64, $sign) = $tokens;
$header = json_decode(base64_decode($header64), TRUE);
if (!isset($header['alg'])){
return false;
}
$s = $this->hash_do($header64 . $payload64 . md5($this->KEY), $header['alg']);
if ($s !== $sign){
return false;
}
$payload = json_decode(base64_decode($payload64), TRUE);
$time = time();
if (isset($payload['iat']) && $payload['iat'] > $time){
return false;
}
if (isset($payload['exp']) && $payload['exp'] < $time){
return false;
}
return true;
}
}
<?php
namespace utils;
/**
*
*/
class Jwt
{
public $KEY = 'hao';
/**
* [返回 hash 加密后的字符串]
* @param [type] $header [description]
* @param [type] $payload [description]
* @return [type] [description]
*/
private function hash_do($str, $type){
$algo = 'sha256';
if (strtoupper($type) == 'MD5'){
$algo = 'md5';
} else if(strtolower($type) == 'HAVAL'){
$algo = 'haval160,4';
}
return hash($algo, $str);
}
/**
* [create_token description]
* @param [type] $header [description]
* @param [type] $payload [description]
* @return [type] [description]
*/
public function create_token($header, $payload){
if (!empty($header) && is_array($header) &&
(strtoupper($header['alg'])=='HS256' || strtoupper($header['alg'])=='MD5' || strtoupper($header['alg'])=='HAVAL') &&
!empty($payload))
{
$h = base64_encode(json_encode($header));
$p = base64_encode(json_encode($payload));
$s = $this->hash_do($h . $p . md5($this->KEY), $header['alg']);
$sign = $h. '.' . $p . '.' . $s;
return $sign;
}
return null;
}
public function check_token($jwt){
if (empty($jwt)){
return false;
}
$tokens = explode('.', $jwt);
if (count($tokens)!==3){
return false;
}
list($header64, $payload64, $sign) = $tokens;
$header = json_decode(base64_decode($header64), TRUE);
if (!isset($header['alg'])){
return false;
}
$s = $this->hash_do($header64 . $payload64 . md5($this->KEY), $header['alg']);
if ($s !== $sign){
return false;
}
$payload = json_decode(base64_decode($payload64), TRUE);
$time = time();
if (isset($payload['iat']) && $payload['iat'] > $time){
return false;
}
if (isset($payload['exp']) && $payload['exp'] < $time){
return false;
}
return true;
}
}
<?php namespace utils; /** * */ class Jwt { public $KEY = 'hao'; /** * [返回 hash 加密后的字符串] * @param [type] $header [description] * @param [type] $payload [description] * @return [type] [description] */ private function hash_do($str, $type){ $algo = 'sha256'; if (strtoupper($type) == 'MD5'){ $algo = 'md5'; } else if(strtolower($type) == 'HAVAL'){ $algo = 'haval160,4'; } return hash($algo, $str); } /** * [create_token description] * @param [type] $header [description] * @param [type] $payload [description] * @return [type] [description] */ public function create_token($header, $payload){ if (!empty($header) && is_array($header) && (strtoupper($header['alg'])=='HS256' || strtoupper($header['alg'])=='MD5' || strtoupper($header['alg'])=='HAVAL') && !empty($payload)) { $h = base64_encode(json_encode($header)); $p = base64_encode(json_encode($payload)); $s = $this->hash_do($h . $p . md5($this->KEY), $header['alg']); $sign = $h. '.' . $p . '.' . $s; return $sign; } return null; } public function check_token($jwt){ if (empty($jwt)){ return false; } $tokens = explode('.', $jwt); if (count($tokens)!==3){ return false; } list($header64, $payload64, $sign) = $tokens; $header = json_decode(base64_decode($header64), TRUE); if (!isset($header['alg'])){ return false; } $s = $this->hash_do($header64 . $payload64 . md5($this->KEY), $header['alg']); if ($s !== $sign){ return false; } $payload = json_decode(base64_decode($payload64), TRUE); $time = time(); if (isset($payload['iat']) && $payload['iat'] > $time){ return false; } if (isset($payload['exp']) && $payload['exp'] < $time){ return false; } return true; } }
使用方式:
public function auth_token(){
$over = config('TOKEN_OVER_TIME'); // 生存时间
$time = time();
$time_over = $time + $over;
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
$payload = [
'iss' => 'admin_name',
'iat' => $time,
'exp' => $time_over,
'uid' => 12
];
$j = new Jwt();
$sign = $j->create_token($header, $payload);
return $sign;
}
public function check(){
$jwt = 'jwtxxxxxxxx';
$j = new Jwt();
$b = $j->check_token($jwt);
dump($b);
}
public function auth_token(){
$over = config('TOKEN_OVER_TIME'); // 生存时间
$time = time();
$time_over = $time + $over;
$header = [
'typ' => 'JWT',
'alg' => 'HS256'
];
$payload = [
'iss' => 'admin_name',
'iat' => $time,
'exp' => $time_over,
'uid' => 12
];
$j = new Jwt();
$sign = $j->create_token($header, $payload);
return $sign;
}
public function check(){
$jwt = 'jwtxxxxxxxx';
$j = new Jwt();
$b = $j->check_token($jwt);
dump($b);
}
public function auth_token(){ $over = config('TOKEN_OVER_TIME'); // 生存时间 $time = time(); $time_over = $time + $over; $header = [ 'typ' => 'JWT', 'alg' => 'HS256' ]; $payload = [ 'iss' => 'admin_name', 'iat' => $time, 'exp' => $time_over, 'uid' => 12 ]; $j = new Jwt(); $sign = $j->create_token($header, $payload); return $sign; } public function check(){ $jwt = 'jwtxxxxxxxx'; $j = new Jwt(); $b = $j->check_token($jwt); dump($b); }
linux下php安装扩展–以swoole为例
①需要把php扩展对应的源码包拉到linux中
②解压并进入解压后的目录
③在解压的目录中,找到php的安装目录中找到phpize指令并执行。
说明:phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
执行完后会在解压的目录生成一个configure的文件,用于后续的操作
④在解压目录执行./configure脚本, 并且指定php安装目录的php-config脚本文件路径
⑤编译和安装make && make install ,执行完毕后会在php相应的目录生成一个.so的动态库文件
⑥在php配置文件php.ini中指定.so的动态库文件的路径
⑦重启,写个phpinfo的函数进行测试有没有对应的扩展出现
php递归遍历多级分类
/**
* [indexAction_white 返回[树状结构]格式化后的树]
* @return [type] [description]
*/
public function areaData_white()
{
$objs = db($this->table_name)->field('id,parent_id,area_name')->select();
$arr = $this->__format_priv($objs);
return json($arr);
}
/**
* [__format_priv 与[树状结构]格式化数据, [递归]]
* @param [type] $objs [description]
* @param [type] $parent_id [description]
* @return [type] [description]
*/
private function __format_priv($objs, $parent_id = null)
{
$arr = [];
if ($objs && is_array($objs)) {
foreach ($objs as $v) {
if ($v['parent_id'] == $parent_id) {
$arr[] = [
'id' => $v['id'],
'text' => $v['area_name'],
'children' => $this->__format_priv($objs, $v['id'])
];
}
}
}
return $arr;
}
/**
* [indexAction_white 返回[树状结构]格式化后的树]
* @return [type] [description]
*/
public function areaData_white()
{
$objs = db($this->table_name)->field('id,parent_id,area_name')->select();
$arr = $this->__format_priv($objs);
return json($arr);
}
/**
* [__format_priv 与[树状结构]格式化数据, [递归]]
* @param [type] $objs [description]
* @param [type] $parent_id [description]
* @return [type] [description]
*/
private function __format_priv($objs, $parent_id = null)
{
$arr = [];
if ($objs && is_array($objs)) {
foreach ($objs as $v) {
if ($v['parent_id'] == $parent_id) {
$arr[] = [
'id' => $v['id'],
'text' => $v['area_name'],
'children' => $this->__format_priv($objs, $v['id'])
];
}
}
}
return $arr;
}
/** * [indexAction_white 返回[树状结构]格式化后的树] * @return [type] [description] */ public function areaData_white() { $objs = db($this->table_name)->field('id,parent_id,area_name')->select(); $arr = $this->__format_priv($objs); return json($arr); } /** * [__format_priv 与[树状结构]格式化数据, [递归]] * @param [type] $objs [description] * @param [type] $parent_id [description] * @return [type] [description] */ private function __format_priv($objs, $parent_id = null) { $arr = []; if ($objs && is_array($objs)) { foreach ($objs as $v) { if ($v['parent_id'] == $parent_id) { $arr[] = [ 'id' => $v['id'], 'text' => $v['area_name'], 'children' => $this->__format_priv($objs, $v['id']) ]; } } } return $arr; }
/**
* 家谱树(面包屑导航)
* @param $id
* @return array
*/
public function getPlist($id)
{
$arr = collection($this->select())->toArray();
return $this->_familytree($arr, $id);
}
/**
* 家谱树
* @param $arr
* @param $id
* @return array
*/
private function _familytree($arr, $id)
{
$list = array();
foreach ($arr as $v) {
if ($v['id'] == $id) {
$list[] = $v['area_name'];
$list = array_merge($this->_familytree($arr, $v['parent_id']),$list );
}
}
return $list;
}
/**
* 家谱树(面包屑导航)
* @param $id
* @return array
*/
public function getPlist($id)
{
$arr = collection($this->select())->toArray();
return $this->_familytree($arr, $id);
}
/**
* 家谱树
* @param $arr
* @param $id
* @return array
*/
private function _familytree($arr, $id)
{
$list = array();
foreach ($arr as $v) {
if ($v['id'] == $id) {
$list[] = $v['area_name'];
$list = array_merge($this->_familytree($arr, $v['parent_id']),$list );
}
}
return $list;
}
/** * 家谱树(面包屑导航) * @param $id * @return array */ public function getPlist($id) { $arr = collection($this->select())->toArray(); return $this->_familytree($arr, $id); } /** * 家谱树 * @param $arr * @param $id * @return array */ private function _familytree($arr, $id) { $list = array(); foreach ($arr as $v) { if ($v['id'] == $id) { $list[] = $v['area_name']; $list = array_merge($this->_familytree($arr, $v['parent_id']),$list ); } } return $list; }