123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- use think\Db;
- function IntToChr($index, $start = 65) {
- $str = '';
- if (floor($index / 26) > 0) {
- $str .= IntToChr(floor($index / 26)-1);
- }
- return $str . chr($index % 26 + $start);
- }
- /********************php验证身份证号码是否正确函数*********************/
- function is_idcard($id)
- {
- $id = strtoupper($id);
- $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
- $arr_split = array();
- if(!preg_match($regx, $id))
- {
- return FALSE;
- }
- if(15==strlen($id)) //检查15位
- {
- $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
- @preg_match($regx, $id, $arr_split);
- //检查生日日期是否正确
- $dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
- if(!strtotime($dtm_birth))
- {
- return FALSE;
- } else {
- return TRUE;
- }
- }
- else //检查18位
- {
- $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
- @preg_match($regx, $id, $arr_split);
- $dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
- if(!strtotime($dtm_birth)) //检查生日日期是否正确
- {
- return FALSE;
- }
- else
- {
- //检验18位身份证的校验码是否正确。
- //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
- $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
- $sign = 0;
- for ( $i = 0; $i < 17; $i++ )
- {
- $b = (int) $id[$i];
- $w = $arr_int[$i];
- $sign += $b * $w;
- }
- $n = $sign % 11;
- $val_num = $arr_ch[$n];
- if ($val_num != substr($id,17, 1))
- {
- return FALSE;
- } //phpfensi.com
- else
- {
- return TRUE;
- }
- }
- }
- }
- /**
- * 下载文件到服务器
- * addtime 2020年8月28日 18:38:43
- */
- function getFile($url, $save_dir = '', $filename = '', $type = 0)
- {
- if (trim($url) == '') {
- return false;
- }
- if (trim($save_dir) == '') {
- $save_dir = './';
- }
- if (0 !== strrpos($save_dir, '/')) {
- $save_dir.= '/';
- }
- //创建保存目录
- if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
- return false;
- }
- //获取远程文件所采用的方法
- if ($type) {
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $content = curl_exec($ch);
- curl_close($ch);
- } else {
- ob_start();
- readfile($url);
- $content = ob_get_contents();
- ob_end_clean();
- }
- $size = strlen($content);
- //文件大小
- $fp2 = @fopen($save_dir . $filename, 'a');
- fwrite($fp2, $content);
- fclose($fp2);
- unset($content, $url);
- return $filename;
- }
- /**
- * 获取单个系统配置信息
- */
- function getConfigValue($name){
- return Db::name('system_config')->where('name',$name)->value('value');
- }
- /**
- * 调试函数
- */
- function debug($str,$name='debug'){
- $str = var_export($str,true).PHP_EOL;
- $str.= date('Y-m-d H:i:s').' ';
- $str.= $_SERVER['REMOTE_ADDR'].' ';
- $str.= $_SERVER['REQUEST_METHOD'].': ';
- // $str.=$_SERVER['HTTP_HOST'];
- $str.= $_SERVER['REQUEST_URI'].''.PHP_EOL.PHP_EOL;
- $str='<?php exit();?>'.PHP_EOL.$str;
- error_log($str,3,$name.".log");
- }
- /**
- * 获取前12个月
- */
- function monthpast(){
- $str = array();
- for ($i=0;$i<12;$i++){
- $str[$i] = date('Y-m',strtotime('+'.$i.'month',strtotime(date('2022-09'))));
- }
- return $str;
- }
- //计算概率
- function get_rand($proArr) {
- $result = '';
- //概率数组的总概率精度
- $proSum = array_sum($proArr);
- // var_dump($proSum);
- //概率数组循环
- foreach ($proArr as $key => $proCur) {
- if($proSum<1){
- continue;
- }
- $randNum = mt_rand(1, $proSum); //返回随机整数
- if ($randNum <= $proCur) {
- $result = $key;
- break;
- } else {
- $proSum -= $proCur;
- }
- }
- unset ($proArr);
- return $result;
- }
|