几个经常用到的常规class
来源:互联网 发布:匡恩网络武汉 编辑:程序博客网 时间:2024/06/17 15:46
/**
* 常规类
*/
class Fun
{ //邮件发送函数
static function send_mail($to, $name, $subject = '', $body = '', $attachment = null){
require EXTEND_PATH."phpmailer/class.phpmailer.php";
require EXTEND_PATH."phpmailer/class.smtp.php";
//Config::load('配置文件地址');如果不设置,默认读取当前模块的config.php
$mail = new \PHPMailer(); //PHPMailer对象
$mail->CharSet = 'UTF-8';
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
// $mail->SMTPSecure = 'ssl'; // 使用安全协议(qq需要。163不用)
$mail->IsHTML(TRUE); // 是否HTML格式邮件
$mail->Host = config('THINK_MAIL.SMTP_HOST'); // SMTP 服务器
$mail->Port = config('THINK_MAIL.SMTP_PORT'); //端口
$mail->Username = config('THINK_MAIL.SMTP_USER'); // SMTP服务器登陆账号
$mail->Password = config('THINK_MAIL.SMTP_PASS'); // SMTP服务使用授权码
$mail->SetFrom(config('THINK_MAIL.FROM_EMAIL'),config('THINK_MAIL.FROM_NAME'));
//发件人邮箱,名字*SMTP服务器登陆账号必须一致
$mail->AddReplyTo(config('THINK_MAIL.REPLY_EMAIL'), config('THINK_MAIL.REPLY_NAME'));
//收件人所看到发件热你的邮箱,名子(差不多跟昵称一回事)
$mail->Subject = $subject; //邮件标题
$mail->MsgHTML($body);//邮件内容
$mail->AddAddress($to, $name); //收件人邮箱,名字
return $mail->Send() ? true : $mail->ErrorInfo;
}
//模拟post调用接口方法 (测试用)
/**
*响应信息(post)
*@url 请求地址
*@query 请求参数string类型
*/
static function sock_post($url,$query){
$info=parse_url($url);
$fp =fsockopen($info["host"],80,$errno,$errstr,3);
$head="POST ".$info['path']." HTTP/1.0\r\n";
$head.="Host: ".$info['host']."\r\n";
$head.="Referer: http://".$info['host'].$info['path']."\r\n";
$head.="Content-type: application/x-www-form-urlencoded\r\n";
$head.="Content-Length: ".strlen(trim($query))."\r\n";
$head.="\r\n";
$head.=trim($query);
$write=fputs($fp,$head);
while(!feof($fp)){
$line[] =fgets($fp);
}
$aaa = explode(',', end($line));
$aaa = end($aaa);
return $aaa;
}
static function _post($url,$query){
$info=parse_url($url);
$fp =fsockopen($info["host"],80,$errno,$errstr,3);
$head="POST ".$info['path']." HTTP/1.0\r\n";
$head.="Host: ".$info['host']."\r\n";
$head.="Referer: http://".$info['host'].$info['path']."\r\n";
$head.="Content-type: application/x-www-form-urlencoded\r\n";
$head.="Content-Length: ".strlen(trim($query))."\r\n";
$head.="\r\n";
$head.=trim($query);
$write=fputs($fp,$head);
while(!feof($fp)){
echo $line =fgets($fp);
}
}
//密码加密
static function encrypt($pass){
$pass = md5(md5($pass).'yang');
$pass = sha1(strrev($pass));
return $pass;
}
/**
*minwei 最小维度
*minjing 最小经度
*maxwei 最大维度
*maxjing 最大经度
*/
static function getAround($lat,$lon,$raidus){
$PI = 3.14159265; // 圆周率
$latitude = $lat;
$longitude = $lon;
$degree = (24901*1609)/360.0;
$raidusMile = $raidus;
$dpmLat = 1/$degree;
$radiusLat = $dpmLat*$raidusMile;
$minLat = $latitude - $radiusLat;
$maxLat = $latitude + $radiusLat;
$mpdLng = $degree*cos($latitude * ($PI/180));
$dpmLng = 1 / $mpdLng;
$radiusLng = $dpmLng*$raidusMile;
$minLng = $longitude - $radiusLng;
$maxLng = $longitude + $radiusLng;
$result['minwei']=$minLat;
$result['minjing']=$minLng;
$result['maxwei']=$maxLat;
$result['maxjing']=$maxLng;
return $result;
}
/**
* @desc 根据两点间的经纬度计算距离
* @param float $lat 纬度值
* @param float $lng 经度值
*/
static function getDistance($lat1, $lng1, $lat2, $lng2)
{
$earthRadius = 6367000; //地球半径
/*这些学位转换为弧度 用这个公式 */
$lat1 = ($lat1 * pi() ) / 180;
$lng1 = ($lng1 * pi() ) / 180;
$lat2 = ($lat2 * pi() ) / 180;
$lng2 = ($lng2 * pi() ) / 180;
$calcLongitude = $lng2 - $lng1;
$calcLatitude = $lat2 - $lat1;
$stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
$stepTwo = 2 * asin(min(1, sqrt($stepOne)));
$calculatedDistance = $earthRadius * $stepTwo;
return round($calculatedDistance);
}
//首字母排序方法
public function _getFirstCharter($str){
if(empty($str)){return '';}
$fchar=ord($str{0});
if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{0});
$s1=iconv('UTF-8','gb2312',$str);
$s2=iconv('gb2312','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319&&$asc<=-20284) return 'A';
if($asc>=-20283&&$asc<=-19776) return 'B';
if($asc>=-19775&&$asc<=-19219) return 'C';
if($asc>=-19218&&$asc<=-18711) return 'D';
if($asc>=-18710&&$asc<=-18527) return 'E';
if($asc>=-18526&&$asc<=-18240) return 'F';
if($asc>=-18239&&$asc<=-17923) return 'G';
if($asc>=-17922&&$asc<=-17418) return 'H';
if($asc>=-17417&&$asc<=-16475) return 'J';
if($asc>=-16474&&$asc<=-16213) return 'K';
if($asc>=-16212&&$asc<=-15641) return 'L';
if($asc>=-15640&&$asc<=-15166) return 'M';
if($asc>=-15165&&$asc<=-14923) return 'N';
if($asc>=-14922&&$asc<=-14915) return 'O';
if($asc>=-14914&&$asc<=-14631) return 'P';
if($asc>=-14630&&$asc<=-14150) return 'Q';
if($asc>=-14149&&$asc<=-14091) return 'R';
if($asc>=-14090&&$asc<=-13319) return 'S';
if($asc>=-13318&&$asc<=-12839) return 'T';
if($asc>=-12838&&$asc<=-12557) return 'W';
if($asc>=-12556&&$asc<=-11848) return 'X';
if($asc>=-11847&&$asc<=-11056) return 'Y';
if($asc>=-11055&&$asc<=-10247) return 'Z';
return null;
}
static function httppost($url,$query){ //用于短信验证
$postUrl = $url;
$curlPost = $query;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
}
* 常规类
*/
class Fun
{ //邮件发送函数
static function send_mail($to, $name, $subject = '', $body = '', $attachment = null){
require EXTEND_PATH."phpmailer/class.phpmailer.php";
require EXTEND_PATH."phpmailer/class.smtp.php";
//Config::load('配置文件地址');如果不设置,默认读取当前模块的config.php
$mail = new \PHPMailer(); //PHPMailer对象
$mail->CharSet = 'UTF-8';
$mail->IsSMTP(); // 设定使用SMTP服务
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
// $mail->SMTPSecure = 'ssl'; // 使用安全协议(qq需要。163不用)
$mail->IsHTML(TRUE); // 是否HTML格式邮件
$mail->Host = config('THINK_MAIL.SMTP_HOST'); // SMTP 服务器
$mail->Port = config('THINK_MAIL.SMTP_PORT'); //端口
$mail->Username = config('THINK_MAIL.SMTP_USER'); // SMTP服务器登陆账号
$mail->Password = config('THINK_MAIL.SMTP_PASS'); // SMTP服务使用授权码
$mail->SetFrom(config('THINK_MAIL.FROM_EMAIL'),config('THINK_MAIL.FROM_NAME'));
//发件人邮箱,名字*SMTP服务器登陆账号必须一致
$mail->AddReplyTo(config('THINK_MAIL.REPLY_EMAIL'), config('THINK_MAIL.REPLY_NAME'));
//收件人所看到发件热你的邮箱,名子(差不多跟昵称一回事)
$mail->Subject = $subject; //邮件标题
$mail->MsgHTML($body);//邮件内容
$mail->AddAddress($to, $name); //收件人邮箱,名字
return $mail->Send() ? true : $mail->ErrorInfo;
}
//模拟post调用接口方法 (测试用)
/**
*响应信息(post)
*@url 请求地址
*@query 请求参数string类型
*/
static function sock_post($url,$query){
$info=parse_url($url);
$fp =fsockopen($info["host"],80,$errno,$errstr,3);
$head="POST ".$info['path']." HTTP/1.0\r\n";
$head.="Host: ".$info['host']."\r\n";
$head.="Referer: http://".$info['host'].$info['path']."\r\n";
$head.="Content-type: application/x-www-form-urlencoded\r\n";
$head.="Content-Length: ".strlen(trim($query))."\r\n";
$head.="\r\n";
$head.=trim($query);
$write=fputs($fp,$head);
while(!feof($fp)){
$line[] =fgets($fp);
}
$aaa = explode(',', end($line));
$aaa = end($aaa);
return $aaa;
}
static function _post($url,$query){
$info=parse_url($url);
$fp =fsockopen($info["host"],80,$errno,$errstr,3);
$head="POST ".$info['path']." HTTP/1.0\r\n";
$head.="Host: ".$info['host']."\r\n";
$head.="Referer: http://".$info['host'].$info['path']."\r\n";
$head.="Content-type: application/x-www-form-urlencoded\r\n";
$head.="Content-Length: ".strlen(trim($query))."\r\n";
$head.="\r\n";
$head.=trim($query);
$write=fputs($fp,$head);
while(!feof($fp)){
echo $line =fgets($fp);
}
}
//密码加密
static function encrypt($pass){
$pass = md5(md5($pass).'yang');
$pass = sha1(strrev($pass));
return $pass;
}
/**
*minwei 最小维度
*minjing 最小经度
*maxwei 最大维度
*maxjing 最大经度
*/
static function getAround($lat,$lon,$raidus){
$PI = 3.14159265; // 圆周率
$latitude = $lat;
$longitude = $lon;
$degree = (24901*1609)/360.0;
$raidusMile = $raidus;
$dpmLat = 1/$degree;
$radiusLat = $dpmLat*$raidusMile;
$minLat = $latitude - $radiusLat;
$maxLat = $latitude + $radiusLat;
$mpdLng = $degree*cos($latitude * ($PI/180));
$dpmLng = 1 / $mpdLng;
$radiusLng = $dpmLng*$raidusMile;
$minLng = $longitude - $radiusLng;
$maxLng = $longitude + $radiusLng;
$result['minwei']=$minLat;
$result['minjing']=$minLng;
$result['maxwei']=$maxLat;
$result['maxjing']=$maxLng;
return $result;
}
/**
* @desc 根据两点间的经纬度计算距离
* @param float $lat 纬度值
* @param float $lng 经度值
*/
static function getDistance($lat1, $lng1, $lat2, $lng2)
{
$earthRadius = 6367000; //地球半径
/*这些学位转换为弧度 用这个公式 */
$lat1 = ($lat1 * pi() ) / 180;
$lng1 = ($lng1 * pi() ) / 180;
$lat2 = ($lat2 * pi() ) / 180;
$lng2 = ($lng2 * pi() ) / 180;
$calcLongitude = $lng2 - $lng1;
$calcLatitude = $lat2 - $lat1;
$stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
$stepTwo = 2 * asin(min(1, sqrt($stepOne)));
$calculatedDistance = $earthRadius * $stepTwo;
return round($calculatedDistance);
}
//首字母排序方法
public function _getFirstCharter($str){
if(empty($str)){return '';}
$fchar=ord($str{0});
if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{0});
$s1=iconv('UTF-8','gb2312',$str);
$s2=iconv('gb2312','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{0})*256+ord($s{1})-65536;
if($asc>=-20319&&$asc<=-20284) return 'A';
if($asc>=-20283&&$asc<=-19776) return 'B';
if($asc>=-19775&&$asc<=-19219) return 'C';
if($asc>=-19218&&$asc<=-18711) return 'D';
if($asc>=-18710&&$asc<=-18527) return 'E';
if($asc>=-18526&&$asc<=-18240) return 'F';
if($asc>=-18239&&$asc<=-17923) return 'G';
if($asc>=-17922&&$asc<=-17418) return 'H';
if($asc>=-17417&&$asc<=-16475) return 'J';
if($asc>=-16474&&$asc<=-16213) return 'K';
if($asc>=-16212&&$asc<=-15641) return 'L';
if($asc>=-15640&&$asc<=-15166) return 'M';
if($asc>=-15165&&$asc<=-14923) return 'N';
if($asc>=-14922&&$asc<=-14915) return 'O';
if($asc>=-14914&&$asc<=-14631) return 'P';
if($asc>=-14630&&$asc<=-14150) return 'Q';
if($asc>=-14149&&$asc<=-14091) return 'R';
if($asc>=-14090&&$asc<=-13319) return 'S';
if($asc>=-13318&&$asc<=-12839) return 'T';
if($asc>=-12838&&$asc<=-12557) return 'W';
if($asc>=-12556&&$asc<=-11848) return 'X';
if($asc>=-11847&&$asc<=-11056) return 'Y';
if($asc>=-11055&&$asc<=-10247) return 'Z';
return null;
}
static function httppost($url,$query){ //用于短信验证
$postUrl = $url;
$curlPost = $query;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
}
0 0
- 几个经常用到的常规class
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- 几个经常用到的字符串的截取
- linux经常要用到的几个命令
- Linux下面经常用到的几个命令
- jquery经常用到的几个方法1
- Linux下面经常用到的几个命令
- C#几个经常用到的字符串截取
- Duilib滑动条的使用
- 设计模式之简单工厂模式
- Shell 脚本小试牛刀(4) -- 创建 git 仓库
- ioctl 和unlock_ioctl函数讨论
- java的构造块静态块
- 几个经常用到的常规class
- duilib 捕捉Windos原生消息和自定义消息
- 为什么在App Store下载必须免费软件必须验证付款信息
- android 从服务器下载图片,并保存到本地
- Java中常用到的算法题
- JFinal 多数据源切换,实现数据迁移
- 算24点游戏规则及技巧攻略
- Duilb控件的特殊说明
- zookeeper安装时遇见的问题