< ?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright ( c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 < liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
if ( ! function_exists( 'ok' )) {
function ok( $data = [ ] , $code = 200, $msg = 'success' )
{
$res = [
'code' = > $code ,
'msg' = > $msg ,
'data' = > $data
] ;
//header( 'Content-type: application/json' ) ;
exit( json_encode( $res , JSON_UNESCAPED_UNICODE)) ;
}
}
if ( ! function_exists( 'fail' )) {
function fail( $msg , $code = 500, $data = [ ] )
{
$res = [
'code' = > $code ,
'msg' = > $msg ,
'data' = > $data
] ;
//header( 'Content-type: application/json' ) ;
exit( json_encode( $res , JSON_UNESCAPED_UNICODE)) ;
}
}
if ( ! function_exists( 'encrypt_password' )) {
//密码加密处理
function encrypt_password( $password )
{
$salt = 'sssfds' ;
return md5( md5( $salt . md5( $password )) ) ;
}
}
if ( ! function_exists( 'dd' )) {
function dd( $value )
{
echo "<pre>" ;
var_dump( $value ) ;
die( ) ;
}
}
//短网址算法
if ( ! function_exists( 'dwz' )) {
function dwz( $url )
{
$code = sprintf( '%u' , crc32( $url )) ;
$surl = '' ;
while ( $code ) {
$mod = $code % 62;
if ( $mod > 9 && $mod <= 35) {
$mod = chr( $mod + 55) ;
} elseif ( $mod > 35) {
$mod = chr( $mod + 61) ;
}
$surl .= $mod ;
$code = floor( $code / 62) ;
}
return $surl ;
}
}
//邮件发送
if ( ! function_exists( 'sendmail' )) {
function SendMail( $address , $title , $body )
{
$mail = new PHPMailer( true) ;
try {
$mail -> SMTPDebug = SMTP::DEBUG_OFF; //Enable verbose debug output
$mail -> isSMTP( ) ; //Send using SMTP
$mail -> Host = 'smtp.qq.com' ; //Set the SMTP server to send through
$mail -> SMTPAuth = true ; //Enable SMTP authentication
$mail -> Username = 'gztrljh@qq.com' ; //SMTP username
$mail -> Password = 'xoiltpegqcbibgef' ; //SMTP password
$mail -> SMTPSecure = 'ssl' ; //Enable TLS encryption; ` PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail -> Port = 465; //TCP port to connect to, use 465 for ` PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail -> setFrom( 'gztrljh@qq.com' , 'gztrljh' ) ;
$mail -> addAddress( $address , 'lisi' ) ; //Add a recipient
//Content
$mail -> isHTML( true) ; //Set email format to HTML
$mail -> Subject = $title ;
$mail -> Body = $body ;
$mail -> send( ) ;
return "发送成功" ;
} catch ( Exception $e ) {
$res = [
'code' = > 500,
'msg' = > $mail -> ErrorInfo,
'data' = > $data
] ;
return json_encode( $res , JSON_UNESCAPED_UNICODE) ;
}
}
}