├── Code
├── README.md
├── ValidateCode.php
├── codeimg.php
├── font
│ └── ebrima.ttf
└── index.php
├── IP
├── README.md
└── ip.php
├── Page
├── Page.php
├── README.md
└── demo.php
├── README.md
├── ohter
├── Database.php
├── HttpClient.php
├── Language.php
└── Text.php
└── pay
├── README.md
├── erweima.php
├── index.php
├── logo.png
├── qqpay_head.jpg
└── weixinpay_head.jpg
/Code/README.md:
--------------------------------------------------------------------------------
1 | ValidateCode.php为核心类库,codeimg.php为实例化验证码文件,font文件夹为字体文件夹,index.php为演示demo文件,调用可参照
--------------------------------------------------------------------------------
/Code/ValidateCode.php:
--------------------------------------------------------------------------------
1 | font = dirname(__FILE__).'/font/ebrima.ttf';
18 | $this->codelen = $codelen;
19 | $this->width = $width;
20 | $this->height = $height;
21 | $this->fontSize = $fontSize;
22 | $this->createCode();
23 | }
24 | //生成随机码
25 | private function createCode(){
26 | $_len = strlen($this->charset)-1;
27 | for($i=0;$i<$this->codelen;$i++){
28 | $this->code .=$this->charset[mt_rand(0,$_len)];
29 | }
30 | $_SESSION['code'] = strtolower($this->code); //将生成的code码保存在session中
31 | }
32 |
33 | //创建背景
34 | private function createBg(){
35 | $this->img = imagecreatetruecolor($this->width, $this->height);
36 | $color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));
37 | imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color);
38 | }
39 |
40 | //生成文字
41 | private function createFont(){
42 | $_x = $this->width/$this->codelen;
43 | for($i=0;$i<$this->codelen;$i++){
44 | $this->fontColor = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156));
45 | imagettftext($this->img, $this->fontSize, mt_rand(-30,30), $_x*$i+mt_rand(3,5), $this->height/1.4, $this->fontColor, $this->font, $this->code[$i]);
46 | }
47 | }
48 |
49 | //生成线条,雪花
50 | private function createLine(){
51 | for($i=0;$i<6;$i++){
52 | $color = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156));
53 | imageline($this->img, mt_rand(0,$this->width), mt_rand(0,$this->height), mt_rand(0,$this->width), mt_rand(0,$this->height), $color);
54 |
55 | }
56 | for ($i=0; $i < 100; $i++) {
57 | $color = imagecolorallocate($this->img, mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
58 | imagestring($this->img, mt_rand(1,5), mt_rand(0,$this->width), mt_rand(0,$this->height), '*', $color);
59 | }
60 | }
61 |
62 | //输出
63 | private function outPut(){
64 | header('Content-type:image/png');
65 | imagepng($this->img);
66 | imagedestroy($this->img);
67 | }
68 |
69 | //对外生成
70 | public function doimg(){
71 | $this->createBg();
72 | $this->createLine();
73 | $this->createFont();
74 | $this->outPut();
75 |
76 | }
77 | }
78 |
79 |
80 | ?>
--------------------------------------------------------------------------------
/Code/codeimg.php:
--------------------------------------------------------------------------------
1 | doimg(); //将生成的验证码图片输出
6 | ?>
--------------------------------------------------------------------------------
/Code/font/ebrima.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rianley/tool/4973bc81595f40e65b9db5627a161b4c38cf7810/Code/font/ebrima.ttf
--------------------------------------------------------------------------------
/Code/index.php:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
17 |
18 | 验证码demo
19 |
20 |
21 |
22 |
23 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/IP/README.md:
--------------------------------------------------------------------------------
1 | 查询ip地址;执行速度挺快的。调用了 新浪的api接口!
2 |
3 | 直接 给GetIpLookup方法传一个 参数 即可! 参数 为 ip地址
4 |
5 | 需要的直接 下载,也可以封装成类库使用!
6 |
7 | 作者开发不易,请点赞关注!!!!
8 |
--------------------------------------------------------------------------------
/IP/ip.php:
--------------------------------------------------------------------------------
1 | total = $total?$total:1;
13 | $this->pagesize = $pagesize;
14 | $this->pagenum = ceil($this->total/$this->pagesize);
15 | $this->page = $this->setPage();
16 | $this->limit = "LIMIT ".($this->page-1)*$this->pagesize.",".$this->pagesize;
17 | $this->url = $this->setUrl();
18 | $this->bothnum = defined('BOTHNUM')?BOTHNUM:5;
19 | }
20 |
21 |
22 | //拦截器
23 | public function __get($key){
24 | return $this->$key;
25 | }
26 |
27 |
28 | //分页信息
29 | public function showpage(){
30 | $page='';
31 | $page .= $this->first();
32 | $page .= $this->pageList();
33 | $page .= $this->last();
34 | $page .= $this->prev();
35 | $page .= $this->next();
36 |
37 | return $page;
38 | }
39 |
40 |
41 | //获取当前页面
42 | private function setPage(){
43 | $num='';
44 | if(!empty($_GET['page'])){
45 | if($_GET['page']>0){
46 | if($_GET['page']>$this->pagenum){
47 | $num=$this->pagenum;
48 | }else{
49 | $num=$_GET['page'];
50 | }
51 | }else{
52 | $num=1;
53 | }
54 | }else{
55 | $num=1;
56 | }
57 | return $num;
58 | }
59 |
60 | //首页
61 | private function first(){
62 | if($this->page>$this->bothnum+1){
63 | return "1...";
64 | }
65 |
66 | }
67 |
68 | //上一页
69 | private function prev(){
70 | if($this->page==1){
71 | return "上一页";
72 | }
73 | return "上一页";
74 | }
75 |
76 | //下一页
77 | private function next(){
78 | if($this->page==$this->pagenum){
79 | return "下一页";
80 | }
81 | return "下一页";
82 | }
83 |
84 | //尾页
85 | private function last(){
86 | if($this->pagenum-$this->page>$this->bothnum){
87 | return "...{$this->pagenum}";
88 | }
89 |
90 | }
91 |
92 | //获取地址
93 | private function setUrl(){
94 | $url = $_SERVER['REQUEST_URI'];
95 | $par = parse_url($url);
96 | if(isset($par['query'])){
97 | parse_str($par['query'],$_query);
98 | unset($_query['page']);
99 | $url = $par['path'].'?'.http_build_query($_query);
100 | }else{
101 | $url = $url.'?';
102 | }
103 | return $url;
104 | }
105 |
106 | //数字目录
107 | private function pageList(){
108 | $_pagelist='';
109 | //当前页前面内容
110 | for ($i =$this->bothnum;$i>=1; $i--) {
111 | $_page = $this->page-$i;
112 | if($_page<1)continue;
113 | $_pagelist .= "".$_page."";
114 | }
115 | //当前页
116 | $_pagelist .= ''.$this->page.'';
117 | //当前页后面内容
118 | for ($i=1; $i <=$this->bothnum ; $i++) {
119 | $_page = $this->page+$i;
120 | if($_page>$this->pagenum)break;
121 | $_pagelist .= "".$_page."";
122 | }
123 | return $_pagelist;
124 | }
125 | }
126 | ?>
--------------------------------------------------------------------------------
/Page/README.md:
--------------------------------------------------------------------------------
1 | 分页类,Page.php文件为分页类,demo.php文件为演示文件
--------------------------------------------------------------------------------
/Page/demo.php:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 | 分页demo
12 |
28 |
29 |
30 | = $page->showpage(); //调用?>
31 |
32 |
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # tool
2 | 日常工具 php 类库
3 |
--------------------------------------------------------------------------------
/ohter/Database.php:
--------------------------------------------------------------------------------
1 | host = $host;
68 | $this->user = $user;
69 | $this->password = $password;
70 | $this->port = $port;
71 | $this->dbName = $dbName;
72 | $this->charset = $charset;
73 | }
74 |
75 | public function __destruct()
76 | {
77 | $this->pdoHandle = null;
78 | }
79 |
80 | private function connect($force = false)
81 | {
82 | if (is_null($this->pdoHandle) || $force) {
83 | $dsn = "mysql:host={$this->host};port={$this->port};dbname={$this->dbName};charset={$this->charset}";
84 | $handle = new \PDO($dsn, $this->user, $this->password, array(
85 | \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
86 | \PDO::MYSQL_ATTR_COMPRESS => false
87 | ));
88 | $handle->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
89 | $this->pdoHandle = $handle;
90 | }
91 | }
92 |
93 | /**
94 | * @param string $dbName
95 | */
96 | public function selectDatabase($dbName)
97 | {
98 | $this->exec("USE {$dbName};");
99 | $this->dbName = $dbName;
100 | }
101 |
102 | public function lastSql()
103 | {
104 | return $this->lastSql;
105 | }
106 |
107 | public function queryOne($sql, $params = array())
108 | {
109 | $statement = $this->_query($sql, $params);
110 | $output = $statement->fetch(\PDO::FETCH_ASSOC);
111 | return empty($output) ? array() : $output;
112 | }
113 |
114 | public function query($sql, $params = array())
115 | {
116 | $statement = $this->_query($sql, $params);
117 | $output = $statement->fetchAll(\PDO::FETCH_ASSOC);
118 | return empty($output) ? array() : $output;
119 | }
120 |
121 | private function _query($sql, $params)
122 | {
123 | $this->connect();
124 | $statement = $this->pdoHandle->prepare($sql);
125 | foreach ($params as $k => $v) {
126 | $this->bindParam($k, $v, $statement);
127 | }
128 | $flag = $statement->execute();
129 | if ($flag === false) {
130 | $this->handleError($statement);
131 | }
132 | $this->affectedRows = $statement->rowCount();
133 | $this->lastSql = $statement->queryString;
134 | return $statement;
135 | }
136 |
137 | private function _insert(array $data, $tbl, $db, $type)
138 | {
139 | $type = strtoupper($type);
140 | $output = array();
141 | foreach ($data as $k => $v) {
142 | $output[] = "`{$k}` = :{$k}";
143 | }
144 | if (empty($db)) {
145 | $tblStr = "`{$tbl}`";
146 | } else {
147 | $tblStr = "`{$db}`.`{$tbl}";
148 | }
149 | $setStr = implode(', ', $output);
150 | $sql = "{$type} INTO {$tblStr} SET {$setStr};";
151 | return $sql;
152 | }
153 |
154 | public function delete($whereStr, $tbl, $db = null)
155 | {
156 | $this->connect();
157 | if (empty($db)) {
158 | $tblStr = "`{$tbl}`";
159 | } else {
160 | $tblStr = "`{$db}`.`{$tbl}";
161 | }
162 | $sql = "DELETE FROM {$tblStr} WHERE {$whereStr}";
163 | $statement = $this->pdoHandle->prepare($sql);
164 | $flag = $statement->execute();
165 | if ($flag === false) {
166 | $this->handleError($statement);
167 | }
168 | $this->affectedRows = $statement->rowCount();
169 | $this->lastSql = $statement->queryString;
170 | return $this->affectedRows();
171 | }
172 |
173 | public function update(array $data, $whereStr, $tbl, $db = null)
174 | {
175 | $this->connect();
176 | $output = array();
177 | foreach ($data as $k => $v) {
178 | $output[] = "`{$k}` = :{$k}";
179 | }
180 | if (empty($db)) {
181 | $tblStr = "`{$tbl}`";
182 | } else {
183 | $tblStr = "`{$db}`.`{$tbl}";
184 | }
185 | $setStr = implode(', ', $output);
186 | $sql = "UPDATE {$tblStr} SET {$setStr} WHERE {$whereStr};";
187 | $statement = $this->pdoHandle->prepare($sql);
188 | foreach ($data as $k => $v) {
189 | $this->bindParam(':' . $k, $v, $statement);
190 | }
191 | $flag = $statement->execute();
192 | if ($flag === false) {
193 | $this->handleError($statement);
194 | }
195 | $this->affectedRows = $statement->rowCount();
196 | $this->lastSql = $statement->queryString;
197 | return $this->affectedRows();
198 | }
199 |
200 | public function insert(array $data, $tbl, $db = null)
201 | {
202 | $this->connect();
203 | $sql = $this->_insert($data, $tbl, $db, 'INSERT');
204 | $statement = $this->pdoHandle->prepare($sql);
205 | foreach ($data as $k => $v) {
206 | $this->bindParam(':' . $k, $v, $statement);
207 | }
208 | $flag = $statement->execute();
209 | if ($flag === false) {
210 | $this->handleError($statement);
211 | }
212 | $this->affectedRows = $statement->rowCount();
213 | $this->lastSql = $statement->queryString;
214 | return $this->lastInsertId();
215 | }
216 |
217 | public function replace(array $data, $tbl, $db = null)
218 | {
219 | $this->connect();
220 | $sql = $this->_insert($data, $tbl, $db, 'REPLACE');
221 | $statement = $this->pdoHandle->prepare($sql);
222 | foreach ($data as $k => $v) {
223 | $this->bindParam(':' . $k, $v, $statement);
224 | }
225 | $flag = $statement->execute();
226 | if ($flag === false) {
227 | $this->handleError($statement);
228 | }
229 | $this->affectedRows = $statement->rowCount();
230 | $this->lastSql = $statement->queryString;
231 | return $this->lastInsertId();
232 | }
233 |
234 | public function ignore(array $data, $tbl, $db = null)
235 | {
236 | $this->connect();
237 | $sql = $this->_insert($data, $tbl, $db, 'INSERT IGNORE');
238 | $statement = $this->pdoHandle->prepare($sql);
239 | foreach ($data as $k => $v) {
240 | $this->bindParam(':' . $k, $v, $statement);
241 | }
242 | $flag = $statement->execute();
243 | if ($flag === false) {
244 | $this->handleError($statement);
245 | }
246 | $this->affectedRows = $statement->rowCount();
247 | $this->lastSql = $statement->queryString;
248 | return $this->lastInsertId();
249 | }
250 |
251 | public function exec($sql)
252 | {
253 | $this->connect();
254 | $flag = $this->pdoHandle->exec($sql);
255 | if ($flag === false) {
256 | $this->handleError($this->pdoHandle);
257 | }
258 | $this->affectedRows = $flag;
259 | $this->lastSql = $sql;
260 | return $this->affectedRows();
261 | }
262 |
263 | public function affectedRows()
264 | {
265 | return $this->affectedRows;
266 | }
267 |
268 | public function lastInsertId()
269 | {
270 | $this->connect();
271 | return $this->pdoHandle->lastInsertId();
272 | }
273 |
274 | public function begin()
275 | {
276 | $this->connect();
277 | if ($this->pdoHandle->inTransaction()) {
278 | throw new \PDOException('in transaction already!');
279 | } else {
280 | $this->pdoHandle->beginTransaction();
281 | }
282 | }
283 |
284 | public function commit()
285 | {
286 | $this->connect();
287 | $this->pdoHandle->commit();
288 | }
289 |
290 | public function rollback()
291 | {
292 | $this->connect();
293 | $this->pdoHandle->rollBack();
294 | }
295 |
296 | public function escape($str)
297 | {
298 | $this->connect();
299 | return $this->pdoHandle->quote($str);
300 | }
301 |
302 | /**
303 | * @param \PDO|\PDOStatement $obj
304 | */
305 | private function handleError($obj)
306 | {
307 | $tmp = $obj->errorInfo();
308 | $errCode = intval($tmp[1]);
309 | $errMsg = strval($tmp[2]);
310 | throw new \PDOException($errMsg, $errCode);
311 | }
312 |
313 | /**
314 | * @param string $key
315 | * @param mixed $value
316 | * @param \PDOStatement $statement
317 | */
318 | private function bindParam($key, $value, $statement)
319 | {
320 | if (is_numeric($value)) {
321 | $statement->bindParam($key, $value, \PDO::PARAM_INT);
322 | } elseif (is_null($value)) {
323 | $statement->bindParam($key, $value, \PDO::PARAM_NULL);
324 | } else {
325 | $statement->bindParam($key, $value, \PDO::PARAM_STR);
326 | }
327 | }
328 | }
329 |
--------------------------------------------------------------------------------
/ohter/HttpClient.php:
--------------------------------------------------------------------------------
1 | url($url);
33 | }
34 | }
35 |
36 | /**
37 | * @param $url
38 | * @return $this
39 | */
40 | public function url($url)
41 | {
42 | $this->config['url'] = trim($url);
43 | return $this;
44 | }
45 |
46 | private function processUrl($ch)
47 | {
48 | curl_setopt($ch, CURLOPT_URL, $this->config['url']);
49 | return $ch;
50 | }
51 |
52 | /**
53 | * @param $username
54 | * @param $password
55 | * @return $this
56 | */
57 | public function auth($username, $password)
58 | {
59 | $tmp = array();
60 | $tmp['username'] = $username;
61 | $tmp['password'] = $password;
62 | $this->config['auth'] = $tmp;
63 | return $this;
64 | }
65 |
66 | private function processAuth($ch)
67 | {
68 | $username = $this->config['auth']['username'];
69 | $password = $this->config['auth']['password'];
70 | curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}");
71 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
72 | }
73 |
74 | /**
75 | * @param $ua
76 | * @return $this
77 | */
78 | public function ua($ua)
79 | {
80 | $this->config['headers']['User-Agent'] = $ua;
81 | return $this;
82 | }
83 |
84 | /**
85 | * @param array $headers
86 | * @return $this
87 | */
88 | public function headers(array $headers)
89 | {
90 | $this->config['headers'] = $headers;
91 | return $this;
92 | }
93 |
94 | private function processHeaders($ch)
95 | {
96 | $headers = array();
97 | foreach ($this->config['headers'] as $k => $v) {
98 | $headers[] = "$k:{$v}";
99 | }
100 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
101 | }
102 |
103 | /**
104 | * @param $host
105 | * @param $port
106 | * @param null $username
107 | * @param null $password
108 | * @return $this
109 | */
110 | public function proxy($host, $port, $username = null, $password = null)
111 | {
112 | $tmp = array();
113 | $tmp['host'] = $host;
114 | $tmp['port'] = $port;
115 | if(!empty($username) && !empty($password)) {
116 | $tmp['username'] = $username;
117 | $tmp['password'] = $password;
118 | }
119 | $this->config['proxy'] = $tmp;
120 | return $this;
121 | }
122 |
123 | private function processProxy($ch)
124 | {
125 | $proxy = $this->config['proxy'];
126 | curl_setopt($ch, CURLOPT_PROXY, $proxy['host']);
127 | curl_setopt($ch, CURLOPT_PROXYPORT, $proxy['port']);
128 | if (!empty($proxy['username']) && !empty($proxy['password'])) {
129 | curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
130 | curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy['username'] . ':' . $proxy['password']);
131 | }
132 | }
133 |
134 | /**
135 | * @param array $cookies
136 | * @return $this
137 | */
138 | public function cookies(array $cookies)
139 | {
140 | $this->config['cookies'] = $cookies;
141 | return $this;
142 | }
143 |
144 | private function processCookies($ch)
145 | {
146 | $tmp = array();
147 | foreach ($this->config['cookies'] as $k => $v) {
148 | $tmp[] = "{$k}={$v}";
149 | }
150 | curl_setopt($ch, CURLOPT_COOKIE, implode(';', $tmp));
151 | }
152 |
153 | /**
154 | * @param $ms
155 | * @param null $connectionMs
156 | * @return $this
157 | */
158 | public function timeout($ms, $connectionMs = null)
159 | {
160 | $tmp = array();
161 | $tmp['timeout'] = $ms;
162 | $tmp['connection_timeout'] = $connectionMs;
163 | $this->config['timeout'] = $tmp;
164 | return $this;
165 | }
166 |
167 | private function processTimeout($ch)
168 | {
169 | $timeout = $this->config['timeout'];
170 | curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout['timeout']);
171 | if (!empty($timeout['connection_timeout'])) {
172 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $timeout['connection_timeout']);
173 | }
174 | }
175 |
176 | /**
177 | * @param $postData
178 | * @return $this
179 | */
180 | public function post($postData)
181 | {
182 | $tmp = null;
183 | if (is_array($postData)) {
184 | $tmp = http_build_query($postData);
185 | }else {
186 | $tmp = $postData;
187 | }
188 | $this->config['post_data'] = $tmp;
189 | return $this;
190 | }
191 |
192 | private function processPost($ch)
193 | {
194 | curl_setopt($ch, CURLOPT_POST, 1);
195 | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->config['post_data']);
196 | }
197 |
198 | /**
199 | * @param $eth
200 | * @return $this
201 | */
202 | public function eth($eth)
203 | {
204 | $this->config['eth'] = $eth;
205 | return $this;
206 | }
207 |
208 | private function processEth($ch)
209 | {
210 | curl_setopt($ch, CURLOPT_INTERFACE, $this->config['eth']);
211 | }
212 |
213 | /**
214 | * @param null $url
215 | * @param null $timeout
216 | * @return mixed
217 | * @throws \Exception
218 | */
219 | public function request($url = null, $timeout = null)
220 | {
221 | if (!empty($url)) {
222 | $this->url($url);
223 | }
224 | if (!empty($timeout)) {
225 | $this->timeout($timeout);
226 | }
227 | if (empty($this->config)) {
228 | throw new \Exception('empty config');
229 | }
230 | $ch = curl_init();
231 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
232 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);//https请求不验证证书
233 | foreach ($this->config as $k => $v) {
234 | if (empty($v)) {
235 | throw new \Exception('empty config: ' . $v);
236 | }
237 | $methodName = 'process' . ucwords($k);
238 | $this->$methodName($ch);
239 | }
240 | $content = curl_exec($ch);
241 | $this->lastErrno = curl_errno($ch);
242 | $this->lastHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
243 | curl_close($ch);
244 | $this->reset();
245 | return $content;
246 | }
247 |
248 | private function reset()
249 | {
250 | $this->config = array();
251 | }
252 | }
--------------------------------------------------------------------------------
/ohter/Language.php:
--------------------------------------------------------------------------------
1 | -20319, 'ai' => -20317, 'an' => -20304, 'ang' => -20295, 'ao' => -20292,
16 | 'ba' => -20283, 'bai' => -20265, 'ban' => -20257, 'bang' => -20242, 'bao' => -20230, 'bei' => -20051, 'ben' => -20036, 'beng' => -20032, 'bi' => -20026, 'bian' => -20002, 'biao' => -19990, 'bie' => -19986, 'bin' => -19982, 'bing' => -19976, 'bo' => -19805, 'bu' => -19784,
17 | 'ca' => -19775, 'cai' => -19774, 'can' => -19763, 'cang' => -19756, 'cao' => -19751, 'ce' => -19746, 'ceng' => -19741, 'cha' => -19739, 'chai' => -19728, 'chan' => -19725, 'chang' => -19715, 'chao' => -19540, 'che' => -19531, 'chen' => -19525, 'cheng' => -19515, 'chi' => -19500, 'chong' => -19484, 'chou' => -19479, 'chu' => -19467, 'chuai' => -19289, 'chuan' => -19288, 'chuang' => -19281, 'chui' => -19275, 'chun' => -19270, 'chuo' => -19263, 'ci' => -19261, 'cong' => -19249, 'cou' => -19243, 'cu' => -19242, 'cuan' => -19238, 'cui' => -19235, 'cun' => -19227, 'cuo' => -19224,
18 | 'da' => -19218, 'dai' => -19212, 'dan' => -19038, 'dang' => -19023, 'dao' => -19018, 'de' => -19006, 'deng' => -19003, 'di' => -18996, 'dian' => -18977, 'diao' => -18961, 'die' => -18952, 'ding' => -18783, 'diu' => -18774, 'dong' => -18773, 'dou' => -18763, 'du' => -18756, 'duan' => -18741, 'dui' => -18735, 'dun' => -18731, 'duo' => -18722,
19 | 'e' => -18710, 'en' => -18697, 'er' => -18696,
20 | 'fa' => -18526, 'fan' => -18518, 'fang' => -18501, 'fei' => -18490, 'fen' => -18478, 'feng' => -18463, 'fo' => -18448, 'fou' => -18447, 'fu' => -18446,
21 | 'ga' => -18239, 'gai' => -18237, 'gan' => -18231, 'gang' => -18220, 'gao' => -18211, 'ge' => -18201, 'gei' => -18184, 'gen' => -18183, 'geng' => -18181, 'gong' => -18012, 'gou' => -17997, 'gu' => -17988, 'gua' => -17970, 'guai' => -17964, 'guan' => -17961, 'guang' => -17950, 'gui' => -17947, 'gun' => -17931, 'guo' => -17928,
22 | 'ha' => -17922, 'hai' => -17759, 'han' => -17752, 'hang' => -17733, 'hao' => -17730, 'he' => -17721, 'hei' => -17703, 'hen' => -17701, 'heng' => -17697, 'hong' => -17692, 'hou' => -17683, 'hu' => -17676, 'hua' => -17496, 'huai' => -17487, 'huan' => -17482, 'huang' => -17468, 'hui' => -17454, 'hun' => -17433, 'huo' => -17427,
23 | 'ji' => -17417, 'jia' => -17202, 'jian' => -17185, 'jiang' => -16983, 'jiao' => -16970, 'jie' => -16942, 'jin' => -16915, 'jing' => -16733, 'jiong' => -16708, 'jiu' => -16706, 'ju' => -16689, 'juan' => -16664, 'jue' => -16657, 'jun' => -16647,
24 | 'ka' => -16474, 'kai' => -16470, 'kan' => -16465, 'kang' => -16459, 'kao' => -16452, 'ke' => -16448, 'ken' => -16433, 'keng' => -16429, 'kong' => -16427, 'kou' => -16423, 'ku' => -16419, 'kua' => -16412, 'kuai' => -16407, 'kuan' => -16403, 'kuang' => -16401, 'kui' => -16393, 'kun' => -16220, 'kuo' => -16216,
25 | 'la' => -16212, 'lai' => -16205, 'lan' => -16202, 'lang' => -16187, 'lao' => -16180, 'le' => -16171, 'lei' => -16169, 'leng' => -16158, 'li' => -16155, 'lia' => -15959, 'lian' => -15958, 'liang' => -15944, 'liao' => -15933, 'lie' => -15920, 'lin' => -15915, 'ling' => -15903, 'liu' => -15889, 'long' => -15878, 'lou' => -15707, 'lu' => -15701, 'lv' => -15681, 'luan' => -15667, 'lue' => -15661, 'lun' => -15659, 'luo' => -15652,
26 | 'ma' => -15640, 'mai' => -15631, 'man' => -15625, 'mang' => -15454, 'mao' => -15448, 'me' => -15436, 'mei' => -15435, 'men' => -15419, 'meng' => -15416, 'mi' => -15408, 'mian' => -15394, 'miao' => -15385, 'mie' => -15377, 'min' => -15375, 'ming' => -15369, 'miu' => -15363, 'mo' => -15362, 'mou' => -15183, 'mu' => -15180,
27 | 'na' => -15165, 'nai' => -15158, 'nan' => -15153, 'nang' => -15150, 'nao' => -15149, 'ne' => -15144, 'nei' => -15143, 'nen' => -15141, 'neng' => -15140, 'ni' => -15139, 'nian' => -15128, 'niang' => -15121, 'niao' => -15119, 'nie' => -15117, 'nin' => -15110, 'ning' => -15109, 'niu' => -14941, 'nong' => -14937, 'nu' => -14933, 'nv' => -14930, 'nuan' => -14929, 'nue' => -14928, 'nuo' => -14926,
28 | 'o' => -14922, 'ou' => -14921,
29 | 'pa' => -14914, 'pai' => -14908, 'pan' => -14902, 'pang' => -14894, 'pao' => -14889, 'pei' => -14882, 'pen' => -14873, 'peng' => -14871, 'pi' => -14857, 'pian' => -14678, 'piao' => -14674, 'pie' => -14670, 'pin' => -14668, 'ping' => -14663, 'po' => -14654, 'pu' => -14645,
30 | 'qi' => -14630, 'qia' => -14594, 'qian' => -14429, 'qiang' => -14407, 'qiao' => -14399, 'qie' => -14384, 'qin' => -14379, 'qing' => -14368, 'qiong' => -14355, 'qiu' => -14353, 'qu' => -14345, 'quan' => -14170, 'que' => -14159, 'qun' => -14151,
31 | 'ran' => -14149, 'rang' => -14145, 'rao' => -14140, 're' => -14137, 'ren' => -14135, 'reng' => -14125, 'ri' => -14123, 'rong' => -14122, 'rou' => -14112, 'ru' => -14109, 'ruan' => -14099, 'rui' => -14097, 'run' => -14094, 'ruo' => -14092,
32 | 'sa' => -14090, 'sai' => -14087, 'san' => -14083, 'sang' => -13917, 'sao' => -13914, 'se' => -13910, 'sen' => -13907, 'seng' => -13906, 'sha' => -13905, 'shai' => -13896, 'shan' => -13894, 'shang' => -13878, 'shao' => -13870, 'she' => -13859, 'shen' => -13847, 'sheng' => -13831, 'shi' => -13658, 'shou' => -13611, 'shu' => -13601, 'shua' => -13406, 'shuai' => -13404, 'shuan' => -13400, 'shuang' => -13398, 'shui' => -13395, 'shun' => -13391, 'shuo' => -13387, 'si' => -13383, 'song' => -13367, 'sou' => -13359, 'su' => -13356, 'suan' => -13343, 'sui' => -13340, 'sun' => -13329, 'suo' => -13326,
33 | 'ta' => -13318, 'tai' => -13147, 'tan' => -13138, 'tang' => -13120, 'tao' => -13107, 'te' => -13096, 'teng' => -13095, 'ti' => -13091, 'tian' => -13076, 'tiao' => -13068, 'tie' => -13063, 'ting' => -13060, 'tong' => -12888, 'tou' => -12875, 'tu' => -12871, 'tuan' => -12860, 'tui' => -12858, 'tun' => -12852, 'tuo' => -12849,
34 | 'wa' => -12838, 'wai' => -12831, 'wan' => -12829, 'wang' => -12812, 'wei' => -12802, 'wen' => -12607, 'weng' => -12597, 'wo' => -12594, 'wu' => -12585,
35 | 'xi' => -12556, 'xia' => -12359, 'xian' => -12346, 'xiang' => -12320, 'xiao' => -12300, 'xie' => -12120, 'xin' => -12099, 'xing' => -12089, 'xiong' => -12074, 'xiu' => -12067, 'xu' => -12058, 'xuan' => -12039, 'xue' => -11867, 'xun' => -11861,
36 | 'ya' => -11847, 'yan' => -11831, 'yang' => -11798, 'yao' => -11781, 'ye' => -11604, 'yi' => -11589, 'yin' => -11536, 'ying' => -11358, 'yo' => -11340, 'yong' => -11339, 'you' => -11324, 'yu' => -11303, 'yuan' => -11097, 'yue' => -11077, 'yun' => -11067,
37 | 'za' => -11055, 'zai' => -11052, 'zan' => -11045, 'zang' => -11041, 'zao' => -11038, 'ze' => -11024, 'zei' => -11020, 'zen' => -11019, 'zeng' => -11018, 'zha' => -11014, 'zhai' => -10838, 'zhan' => -10832, 'zhang' => -10815, 'zhao' => -10800, 'zhe' => -10790, 'zhen' => -10780, 'zheng' => -10764, 'zhi' => -10587, 'zhong' => -10544, 'zhou' => -10533, 'zhu' => -10519, 'zhua' => -10331, 'zhuai' => -10329, 'zhuan' => -10328, 'zhuang' => -10322, 'zhui' => -10315, 'zhun' => -10309, 'zhuo' => -10307, 'zi' => -10296, 'zong' => -10281, 'zou' => -10274, 'zu' => -10270, 'zuan' => -10262, 'zui' => -10260, 'zun' => -10256, 'zuo' => -10254
38 | );
39 |
40 | public static function traditional2simplified($tc) {
41 | $iContent = mb_strlen($tc, 'UTF-8');
42 | $simplifiedCN = "";
43 | for ($i = 0; $i < $iContent; $i++) {
44 | $str = mb_substr($tc, $i, 1, 'UTF-8');
45 | $match = mb_strpos(self::$traditionalDiff, $str, null, 'UTF-8');
46 | $simplifiedCN.=($match !== false ) ? mb_substr(self::$simplifiedDiff, $match, 1, 'UTF-8') : $str;
47 | }
48 | return $simplifiedCN;
49 | }
50 |
51 | public static function simplified2traditional($sc) {
52 | $iContent = mb_strlen($sc, 'UTF-8');
53 | $traditionalCN = "";
54 | for ($i = 0; $i < $iContent; $i++) {
55 | $str = mb_substr($sc, $i, 1, 'UTF-8');
56 | $match = mb_strpos(self::$simplifiedDiff, $str, null, 'UTF-8');
57 | $traditionalCN.=($match !== false ) ? mb_substr(self::$traditionalDiff, $match, 1, 'UTF-8') : $str;
58 | }
59 | return $traditionalCN;
60 | }
61 |
62 | /**
63 | * 将中文编码成拼音
64 | * @param string $str
65 | * @param bool $firstLetter
66 | * @return string
67 | */
68 | public static function zh2py($str, $firstLetter = true)
69 | {
70 | $str = self::traditional2simplified($str);
71 | // $sGBK = iconv('UTF-8', 'GBK//TRANSLIT', $str);
72 | $sGBK = mb_convert_encoding($str, 'GBK', 'UTF-8');
73 | $aBuf = array();
74 | for ($i = 0, $iLoop = strlen($sGBK); $i < $iLoop; $i++) {
75 | $iChr = ord($sGBK{$i});
76 | if ($iChr > 160)
77 | $iChr = ($iChr << 8) + ord($sGBK{++$i}) - 65536;
78 | if ($firstLetter)
79 | $aBuf[] = substr(self::_zh2py($iChr), 0, 1);
80 | else
81 | $aBuf[] = self::_zh2py($iChr);
82 | }
83 | if ($firstLetter)
84 | return implode('', $aBuf);
85 | else
86 | return implode(' ', $aBuf);
87 | }
88 |
89 | private static function _zh2py($iWORD)
90 | {
91 | if ($iWORD > 0 && $iWORD < 160) {
92 | return chr($iWORD);
93 | } elseif ($iWORD < -20319 || $iWORD > -10247) {
94 | return '';
95 | } else {
96 | $result = '';
97 | foreach (self::$pinYinMap as $py => $code) {
98 | if ($code > $iWORD) break;
99 | $result = $py;
100 | }
101 | return $result;
102 | }
103 | }
104 |
105 | public static function isChinese($str, $all = false)
106 | {
107 | $range = '\x{4e00}-\x{9fa5}';
108 | if ($all) {
109 | $flag = preg_match('/^[' . $range . '|\s]+$/uis', $str);
110 | } else {
111 | $flag = preg_match('/[' . $range . ']/uis', $str);
112 | }
113 | return $flag;
114 | }
115 |
116 | public static function isKorean($str, $all = false)
117 | {
118 | $rangeA = '\x{3130}-\x{318f}';
119 | $rangeB = '\x{ac00}-\x{d7a3}';
120 | if ($all) {
121 | $flag = preg_match('/^[' . $rangeA . '|\s]+$/uis', $str);
122 | if (!$flag) {
123 | $flag = preg_match('/^[' . $rangeB . '|\s]+$/uis', $str);
124 | }
125 | } else {
126 | $flag = preg_match('/[' . $rangeA . ']/uis', $str);
127 | if (!$flag) {
128 | $flag = preg_match('/[' . $rangeB . ']/uis', $str);
129 | }
130 | }
131 | return $flag;
132 | }
133 |
134 | public static function isJapanese($str, $all = false)
135 | {
136 | $range = '\x{0800}-\x{4e00}';
137 | if ($all) {
138 | $flag = preg_match('/^[' . $range . '|\s]+$/uis', $str);
139 | } else {
140 | $flag = preg_match('/[' . $range . ']/uis', $str);
141 | }
142 | return $flag;
143 | }
144 | }
--------------------------------------------------------------------------------
/ohter/Text.php:
--------------------------------------------------------------------------------
1 | 里面内容
26 | $str = preg_replace("/\<.*\>/is", "", $str, $limit);
27 | return $str;
28 | }
29 |
30 | /**
31 | * 获取括号中的内容
32 | * @param string $str
33 | * @param bool $recursive
34 | * @return array|string
35 | */
36 | public static function grabBrackets($str, $recursive = false)
37 | {
38 | $paternA = "/\((.*)\)/is";
39 | $paternB = "/((.*))/is";
40 | $paternC = "/\[(.*)\]/is";
41 | $paternD = "/\<(.*)\>/is";
42 | $paternList = array($paternA, $paternB, $paternC, $paternD);
43 | $tmp = array();
44 | foreach ($paternList as $patern) {
45 | preg_match_all($patern, $str, $matches);
46 | if (isset($matches[1]) && count($matches[1]) > 0) {
47 | if (!$recursive) {
48 | return $matches[1][0];
49 | }else {
50 | $tmp = array_merge($tmp, $matches[1]);
51 | }
52 | }
53 | }
54 | return array_unique($tmp);
55 | }
56 |
57 | /**
58 | * 比较字符串,返回相似度
59 | * 0.0 ~ 1.0(越低越相似)
60 | * @param $strA
61 | * @param $strB
62 | * @param $costReplace
63 | * @return float
64 | */
65 | public static function compare($strA, $strB, $costReplace = 1)
66 | {
67 | $strA = self::stripSymbol($strA);
68 | $strB = self::stripSymbol($strB);
69 | $lenA = mb_strlen($strA, 'UTF-8');
70 | $lenB = mb_strlen($strB, 'UTF-8');
71 | $len = max($lenA, $lenB);
72 | $distance = self::levenshtein($strA, $strB, $costReplace);
73 | return ($distance * 1.0 / $len);
74 | }
75 |
76 | /**
77 | * 字符串转数组
78 | * @param $string
79 | * @param string $encoding
80 | * @return array
81 | */
82 | private static function string2Array($string, $encoding = 'UTF-8') {
83 | $arrayResult = array();
84 | while ($iLen = mb_strlen($string, $encoding)) {
85 | array_push($arrayResult, mb_substr($string, 0, 1, $encoding));
86 | $string = mb_substr($string, 1, $iLen, $encoding);
87 | }
88 | return $arrayResult;
89 | }
90 |
91 | private static function levenshtein($str1, $str2, $costReplace = 1, $encoding = 'UTF-8') {
92 | $count_same_letter = 0;
93 | $d = array();
94 | $mb_len1 = mb_strlen($str1, $encoding);
95 | $mb_len2 = mb_strlen($str2, $encoding);
96 | $mb_str1 = self::string2Array($str1, $encoding);
97 | $mb_str2 = self::string2Array($str2, $encoding);
98 | for ($i1 = 0; $i1 < $mb_len1 + 1; $i1++) {
99 | $d[$i1] = array();
100 | $d[$i1][0] = $i1;
101 | }
102 | for ($i2 = 0; $i2 < $mb_len2 + 1; $i2++) {
103 | $d[0][$i2] = $i2;
104 | }
105 | for ($i1 = 1; $i1 <= $mb_len1; $i1++) {
106 | for ($i2 = 1; $i2 <= $mb_len2; $i2++) {
107 | if ($mb_str1[$i1 - 1] === $mb_str2[$i2 - 1]) {
108 | $cost = 0;
109 | $count_same_letter++;
110 | } else {
111 | $cost = $costReplace; //替换
112 | }
113 | $d[$i1][$i2] = min($d[$i1 - 1][$i2] + 1, //插入
114 | $d[$i1][$i2 - 1] + 1, //删除
115 | $d[$i1 - 1][$i2 - 1] + $cost);
116 | }
117 | }
118 | return $d[$mb_len1][$mb_len2];
119 | }
120 |
121 | /**
122 | * 移除各种符号和空格
123 | * @param string $str
124 | * @return string
125 | */
126 | private static function stripSymbol($str)
127 | {
128 | $str = trim($str);
129 | $oriStr = $str;
130 | //大小写转换,空白字符转换
131 | $str = strtolower($str);
132 | $str = str_replace(' ', '', $str);
133 | $str = str_replace(' ', '', $str);
134 | $str = str_replace("'\t'", '', $str);
135 | $str = str_replace("'\r\n'", '', $str);
136 | $str = str_replace("'\n'", '', $str);
137 | //删除所有符号
138 | $symbolList = array('`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '_', '+', '[', ']', '{',
139 | '}', '\\', '|', ';', ':', '\'', '"', ',', '<', '.', '>', '/', '?', '·', '~', '!', '@', '#', '¥', '……',
140 | '(', ')', '—', '+', '【', '】', '、', ';', '‘', ':', '“', ',', '《', '。', '》', '、', '?', '·', '「',
141 | '」', "”", "’", '~', '•', '▪', '#', '…', '.');
142 | foreach ($symbolList as $symbol) {
143 | $str = str_replace($symbol, '', $str);
144 | }
145 | if (empty($str)) {
146 | $str = $oriStr;//纯符号字符串,保留原始
147 | }
148 | //巴比伦数字转换
149 | $replaceList = array('Ⅰ' => 'I', 'Ⅱ' => 'II', 'Ⅲ' => 'III', 'Ⅳ' => 'IV', 'Ⅴ' => 'V', 'Ⅵ' => 'VI', 'Ⅶ' => 'VII',
150 | 'Ⅷ' => 'VIII', 'Ⅸ' => 'IX', 'Ⅹ' => 'X', 'Ⅺ' => 'XI', 'Ⅻ' => 'XII');
151 | foreach ($replaceList as $old => $new) {
152 | $str = str_replace($old, $new, $str);
153 | }
154 | return $str;
155 | }
156 |
157 | /**
158 | * 增加bom头
159 | * @param string $filename
160 | * @param string $charset
161 | * @return bool
162 | */
163 | public static function addBOM($filename, $charset = 'utf-8')
164 | {
165 | $charset = strtolower($charset);
166 | if ($charset != 'utf-8') {
167 | return false;
168 | }
169 | if(!file_exists($filename)) {
170 | return false;
171 | }
172 | $tmpFilename = $filename . '.tmp.' . md5(time());
173 | $rFp = fopen($filename, 'rb');
174 | if (!$rFp) {
175 | return false;
176 | }
177 | $wFp = fopen($tmpFilename, 'wb');
178 | fputs($wFp, "\xEF\xBB\xBF");//输出utf-8 BOM信息
179 | while ($chunk = fgets($rFp, 1024)) {
180 | fputs($wFp, $chunk);
181 | }
182 | fclose($rFp);
183 | fclose($wFp);
184 | unlink($filename);
185 | rename($tmpFilename, $filename);
186 | return true;
187 | }
188 |
189 | public static function readCsvFile($filename, callable $callback)
190 | {
191 | $fp = fopen($filename, 'rb');
192 | while ($row = fgetcsv($fp)) {
193 | $callback($row, $fp);
194 | }
195 | fclose($fp);
196 | }
197 |
198 | public static function readFile($filename, callable $callback)
199 | {
200 | $fp = fopen($filename, 'rb');
201 | while ($row = fgets($fp)) {
202 | $callback($row, $fp);
203 | }
204 | fclose($fp);
205 | }
206 | }
--------------------------------------------------------------------------------
/pay/README.md:
--------------------------------------------------------------------------------
1 | PHP制作 微信、支付宝、QQ支付多合一收款二维码
2 |
3 |
4 | 也是最近 蛮流行的一个 支付方法! 一开始 在这里遇到个误区,不管是使用微信访问还是使用QQ访问,全部是跳转到QQ相关页面。后来仔细一看UA代码(第一步),原来QQ、微信里的UA全部都包括QQ这个字符,最后就在判断微信与QQ UA里QQ字符串后面加了个“/”,微信也一样在后面加“/”。
5 | 制作PHP页面,并上传到PHP空间。
6 |
7 | PS:QQ、微信 无法直接调起微信转账页面,所 以需要长按识二维码别进行转账。
8 | 支付宝,可以直接扫描二维码进行转账操作,不知道这样是便于用户,还是一个小BUG。
9 | 所以,就需要单独给 QQ、微信制作一个二维码识别页面。
10 | 然后制作一个index.php页面,也就是我们要向用户展示的二维码内容页。
11 |
12 |
13 | 具体 看 源码吧!
14 |
15 | 制作不易,还望点赞关注!!!!
16 | 制作不易,还望点赞关注!!!!
17 | 制作不易,还望点赞关注!!!!
18 |
--------------------------------------------------------------------------------
/pay/erweima.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 支付
6 |
7 |
8 |
9 |
10 |
35 |
36 |
37 |
38 |

"/>
46 |
47 |
48 |
49 |

50 |
长按二维码识别,向商家付款
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/pay/index.php:
--------------------------------------------------------------------------------
1 |
19 |
--------------------------------------------------------------------------------
/pay/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rianley/tool/4973bc81595f40e65b9db5627a161b4c38cf7810/pay/logo.png
--------------------------------------------------------------------------------
/pay/qqpay_head.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rianley/tool/4973bc81595f40e65b9db5627a161b4c38cf7810/pay/qqpay_head.jpg
--------------------------------------------------------------------------------
/pay/weixinpay_head.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rianley/tool/4973bc81595f40e65b9db5627a161b4c38cf7810/pay/weixinpay_head.jpg
--------------------------------------------------------------------------------