// json序列化
json_encode($value, 320);
//sha256加密
hash('sha256', $value, true);
//TP自定义扩展类库
extend/first/second/Foo.php
namespace first\second;
class Foo
{
}
use first\second\Foo;
$foo = new Foo();
//TP5生成二维码
//官方文档:http://www.phpqrcode.com/
vendor('phpqrcode.phpqrcode');
$name = 'test';
$data = '测试生成1';
$level = 'L';
$size = 10;
$margin = 1;
$outfile = ROOT_PATH . 'public' . DS . 'uploads' . DS . $name .'.png';
$saveandprint = false;
$QRcode = new \QRcode();
$QRcode->png($data, $outfile, $level, $size, $margin, $saveandprint);
//TP5图片二维码逆解析
//参考链接:https://blog.csdn.net/qq15577969/article/details/114217992
use Zxing\QrReader;
$qrcode = new QrReader("本地图片路径");
$qr_text = $qrcode->text();
//GET/POST请求接口
function curl($url, $params, $method ='POST',$header = []){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if(!empty($header)){
curl_setopt ( $curl, CURLOPT_HTTPHEADER, $header );
}
$timeout = 30;
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
switch ($method){
case "GET" :
curl_setopt($curl, CURLOPT_HTTPGET, true);
break;
case "POST":
if(is_array($params)){
$params = json_encode($params,320);
}
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS,$params);
break;
}
$data = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return $data;
}