<?php

namespace Home\Model;
use Think\Model;

class UserModel extends Model {

    public function send($email,$messge,$code){
        $_SESSION['email_code'] = $code;
        $_SESSION['email'] = $email;
        $mail = new \Org\Email();
        $mail->setServer("smtp.163.com", "18439856338@163.com", "likuo74110");//设置SMTP服务器
        $mail->setFrom("18439856338@163.com");//设置发件人
        $mail->setReceiver($email);//设置收件人，多个收件人调用多次
        $mail->setCc("18439856338@163.com");//设置抄送，多个抄送，调用多次
        $mail->setMailInfo("找回密码", $messge.':'.$code);//设置邮件主题、内容
        $mail->sendMail();//发送邮件
    }

    public function random($length = 6 , $numeric = 0) {
        PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
        if($numeric ==1) {
            $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
        } else {
            $hash = '';
            $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
            $max = strlen($chars) - 1;
            for($i = 0; $i < $length; $i++) {
                $hash .= $chars[mt_rand(0, $max)];
            }
        }
        return $hash;
    }



}