Php-编码解码punycode

前言 域名的编码解码 什么是PunyCode 英文域名在IIS或Apache中的虚拟主机设置,可以直接使用英文域名,如webmasterhome.cn。 中文域名在IIS或Apache中应如何设置主机头呢 在进行设置之前要先把中文域名转化成为PunyCode编码,然后在主机头设置里面填上中文域名所对应的PunyCode编码(xn–fiqsC146Ah4ex80Cro7A.com)便可。 新的国际化域名的标准在网域名称编码上,为了保留向下兼容性及不影响现有的应用程序协议,因此将多国语言域名转成ASCII编码 目标 前置条件 正式内容 <?php class Punycode { const TMIN=1; const TMAX=26; const BASE = 36; const INITIAL_N = 128; const INITIAL_BIAS = 72; const DAMP = 700; const SKEW = 38; const DELIMITER = '-'; const MAXINT = 2147483647; //encode编码时候的错误返回值 const ERROR_BAD_INPUT = -1; const ERROR_BIG_OUTPUT = -2; const ERROR_OVERFLOW = -3; /** * 配置 * 1: 使用iconv * 2: iconv Unicode-1-1 * 3: 使用mb_convert_encoding(较通用,需mb_string支持) */ const CHARSET_MODE = 3; /** * punycode编码 * @param string $input * 输入的字符传不能有空格....

八月 12, 2022 · 4 分钟 · Ken

Php-Swagger代码了解

前言 良好的文档规范,对于前后端的沟通是很有必要的,减少没必要的误解和争执,前端也可以根据文档的格式先制定出页面的流程和提前mock数据开发 目标 前置条件 zircote/swagger-php document 正式内容 1. 基础了解定义文档的语法 文档描述 @OA\Info(title=“Fapi”, version=“0.1”,description=“antdv5的接口前缀为/api/v2 当前版本为/api/返回列表的格式有区别外其他一致”), 文档中的api路径 @OA\Server(url=“http://www.github.com/",description="github",), 预先定义好返回数据的格式 @OA\Schema( schema=“Pagination”, @OA\Property(property=“current”, type=“integer”), @OA\Property(property=“total”, type=“integer”), @OA\Property(property=“pageSize”, type=“integer”), ) 分组每种接口的类别,如/user, /order /record 等, @OA\Tag(name=“api-tag”, description=“Tag”) 编写接口的声明 @OA\Post( path="/api/index", summary="api name", operationId="UniqueOperationId", tags={"api-tag"}, @OA\Parameter(in="query", name="fIDDomainFolder", required=false,schema={"type":"string"},description=""), @OA\Parameter(in="query", name="intActive", required=false,schema={"type":"integer"},description=""), @OA\Parameter(in="query", name="timetype", required=false,schema={"type":"string","enum":{"created_at","expired_at","update_at"}},description="时间类型"), @OA\Response( response="200", description="An example resource", @OA\JsonContent( @OA\Property(property="Pagination",type="object", ref="#/components/schemas/Pagination"), ) ), ) 2. 将定义好的注释声明生成openapi.json $openapi = \OpenApi\Generator::scan([ path . 'api', path . 'model', ]); $openapi->toJson() 3....

八月 12, 2022 · 1 分钟 · Ken

Php支付接口

前言 项目上需要接触到不同种类的支付平台,有一些其他第三方平台的支付也是为了企业没资质或为了得到更好的费率原因,因此也总结一下个人在开发中的使用记录 目标 通过合并支付的接口,让用户在选择支付上能更简单快捷 前置条件 相关支付平台都有自己的支付申请条件,因此根据需求自行了解注册 环境 PHP 正式内容 支付的需求最主要在于3个接口的实现 interface PaymentClientInterface { /** * 支付请求 * @param $order_out_no * @param $total_fee * @param array $param * @return mixed */ public function pay($out_trade_no,$total_fee,$param=[]); /** * 查询支付结果 * @return mixed */ public function query($out_trade_no,$param=[]); /** * 支付回调,由于各支付平台的参数都不同,因此返回原始信息自己处理 * @param $all * @return mixed */ public function handle($all); } wechat 微信支付 public function query($out_trade_no, $param = []) { $action = "/v3/pay/transactions/out-trade-no/{$out_trade_no}"; $resp = $this->request($action, [], 'GET'); return $resp; } private function sign($url, $params, $method) { $params['mchid'] = $this->apiConfig->ExtraConfig['mch_id']; $serial_no = $this->apiConfig->ExtraConfig['serial_no']; $mch_private_key = file_get_contents("/conf/wechat_private_key....

八月 12, 2022 · 8 分钟 · Ken

Python-多线程

import sys import threading import queue import traceback import statistics class NoResultsPending(Exception): """All works requests have been processed""" pass class NoWorkersAvailable(Exception): """No worket threads available to process remaining requests.""" pass def _handle_thread_exception(request, exc_info): """默认的异常处理函数,只是简单的打印""" traceback.print_exception(*exc_info) #classes class WorkerThread(threading.Thread): """后台线程,真正的工作线程,从请求队列(requestQueue)中获取work, 并将执行后的结果添加到结果队列(resultQueue)""" def __init__(self,requestQueue,resultQueue,poll_timeout=5,**kwds): threading.Thread.__init__(self,**kwds) '''设置为守护进行''' self.setDaemon(True) self._requestQueue = requestQueue self._resultQueue = resultQueue self._poll_timeout = poll_timeout '''设置一个flag信号,用来表示该线程是否还被dismiss,默认为false''' self._dismissed = threading.Event() self.start() # self.join() def run(self): '''每个线程尽可能多的执行work,所以采用loop, 只要线程可用,并且requestQueue有work未完成,则一直loop''' while True: if self._dismissed.is_set(): break try: ''' Queue....

八月 12, 2022 · 3 分钟 · Ken

Https双向认证

前言 由于公司需求一些措施加强员工登录企业后台网站的验证,所以了解了一下有关https的双向认证,并部署到生产环境上,因此记录下来部署的流程分享一下遇到的问题 目标 每个员工有各自的验证密钥,只能在自己的电脑上登录验证,防止员工之间的替名篡改或者恶意操作 前置条件 拥有一张根证书,用于签发员工用的,如没有可参考教程创建 PHP 正式内容 参考链接: 阿里云指导openssl签发流程 https://help.aliyun.com/document_detail/160093.html?spm=5176.10695662.1996646101.searchclickresult.480f29d22TQ6uz php官方文档 https://www.php.net/manual/en/function.openssl-csr-sign.php $cacert = “file://path/to/ca.crt”; 文档中此处值得ca.crt是下面所指的root.pem,不是根证书的root.crt,不一样的~~ 使用工具 openssl 创建根证书私钥: openssl genrsa -out root.key 1024 创建根证书请求文件: openssl req -new -out root.csr -key root.key 后续参数的例子提供: Country Name (2 letter code) [AU]:cn State or Province Name (full name) [Some-State]:gd Locality Name (eg, city) []:zh Organization Name (eg, company) [Internet Widgits Pty Ltd]:company Organizational Unit Name (eg, section) []:it Common Name (e.g. server FQDN or YOUR name) []:root 创建根证书: openssl x509 -req -in root....

八月 12, 2022 · 2 分钟 · Ken

Prerender-单页面前端渲染

预渲染,用于前端单页面的项目,做到被seo收录的 #创建用户 useradd -d /home/prerender -m prerender #安装nginx cd /usr/local wget http://nginx.org/download/nginx-1.16.1.tar.gz tar -xzf nginx-1.16.1.tar.gz cd nginx-1.16.1 ./configure –with-http_ssl_module make make install #测试prerender cd /home/prerender #https://github.com/prerender/prerender npm install prerender npm install prerender-memory-cache –save vi server.js const prerender = require(‘prerender’); const server = prerender(); server.use(require(‘prerender-memory-cache’)) server.start(); node server #访问 http://ip:3000/render?url=http://www.baidu.com #配置nginx #参考https://gist.github.com/thoop/8165802 /usr/local/nginx/sbin/nginx -c /home/prerender/nginx.conf /usr/local/nginx/sbin/nginx -s stop nginx.conf events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; # Change YOUR_TOKEN to your prerender token # Change example....

八月 12, 2022 · 2 分钟 · Ken

Nginx-实现网站简繁体转换

这个利用nginx(openresty)+lua+opencc,写10行代码左右就可以实现的类似繁简通的功能 可充分利用nginx的快反应和可靠性 所需插件 https://github.com/BYVoid/OpenCC https://github.com/Finalcheat/lua-resty-opencc/blob/master/lib/resty/opencc.lua opencc在centos7可以用yum安装,但版本很旧 yum install doxygen opencc opencc-tools opencc-devel centos7上编译新版本可能要升级gcc,比较麻烦,我在centos8上编译过新版本 参考: yum install cmake gcc-c++ bison flex http://www.doxygen.nl/download.html https://bintray.com/byvoid/opencc/OpenCC ln -s /user/bin/python3.6 /user/bin/python ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2 安装openresty后opencc.lua放到/usr/local/openresty/lualib/resty/ opencc.lua if (ngx.var.sent_http_content_type ~= nil and string.sub(ngx.var.sent_http_content_type, 1, 4) == "text") then local data=ngx.ctx.data or "" local cdata=ngx.arg[1] data=data..cdata ngx.ctx.data=data if ngx.arg[2] then local opencc = require("resty.opencc") -- local o = opencc:new("zhs2zht.ini") -- opencc 0.4.x local o = opencc:new("s2hk.json") ngx....

八月 12, 2022 · 1 分钟 · Ken

Nginx-了解Lua用法

用lua实现访问限制,木桶效应 nginx.conf server{ location / { access_by_lua_file /usr/local/openresty/nginx/conf/lua/domain_check.lua; index index.html index.htm; } } 限制每个IP一段时间内能访问多少次 domain_check.lua local client = require "resty.websocket.client" local limit_req = require "resty.limit.req" local limit_rate = 150 local limit_burst = 50 local limit_req = require "resty.limit.req" local lim, err = limit_req.new("my_limit_req_store", limit_rate, limit_burst) -- 这里设置rate=2/s,漏桶桶容量设置为0,(也就是来多少水就留多少水) -- 因为resty.limit.req代码中控制粒度为毫秒级别,所以可以做到毫秒级别的平滑处理 if not lim then -- ngx.log(ngx.ERR, "failed to instantiate a resty.limit.req object: ", err) return ngx.exit(500) end local key = ngx.var.binary_remote_addr local delay, err = lim:incoming(key, true) if not delay then if err == "rejected" then return ngx....

八月 12, 2022 · 1 分钟 · Ken

Nginx使用过程中的记录

How to format log (eg: Y-m-d.log) http { map $host $fmt_localdate { default '';} map $host $fmt_localtime { default '';} log_by_lua_block { ngx.var.fmt_localdate = os.date("%Y-%m-%d"); ngx.var.fmt_localtime = os.date("%Y-%m-%d %H:%M:%S"); } log_format main '[$host][$remote_addr][$fmt_localtime][$http_referer][$http_user_agent]'; server { access_log /var/log/nginx/access-$fmt_localdate.log main; } }

八月 12, 2022 · 1 分钟 · Ken

Netdata-监控apache

安装好apache 确保监控模块开启 /etc/httpd/conf.modules.d/00-base.conf 查看这个文件,确保监控模块开启 LoadModule status_module modules/mod_status.so 没有被注释 一旦启用了mod_status ,接下来需要为Apache服务器状态页面创建一个server-status.conf配置文件 # vim /etc/httpd/conf.d/server-status.conf <Location "/server-status"> SetHandler server-status #Require host localhost #uncomment to only allow requests from localhost </Location> 通过使用命令行Web浏览器 (如lynx)验证Apache服务器状态和统计信息页是否正常工作,如图所示。 yum install lynx lynx http://localhost/server-status 5.创建netdata读取apache属性的配置文件 vi /etc/netdata/python.d/apache.conf # # if the URL is password protected, the following are supported: # # user:'username' # pass:'password' # ------------------------------------------------------------------- # AUTO-DETECTION JOBS # only one of them will run (they have the same name) localhost: name : 'local' url : 'http://localhost/server-status?...

八月 12, 2022 · 1 分钟 · Ken