thinkphp5.0 common常用助手函数

<?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);
        }
    }

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值