Beispiel #1
0
/**
 *  encrypt_phone($phone, $snum, $id)
 *  手机号格式保留加密
 * @param  $phone     string                  11位手机号
 * @param  $snum      string                  用户编号字符串,用于混淆密钥
 * @param  $id        int                     用户id,在1~100000之间的整数,用于混淆原文
 * @return string(11) 加密后的手机号
 */
function encrypt_phone($phone, $snum, $id)
{
    if (!$phone) {
        return $phone;
    }
    if ($snum && $id) {
        $mid = substr($phone, -10, 6);
        $end = substr($phone, -4);
        return substr($phone, 0, -10) . encrypt_mid($mid, $snum, $id) . encrypt_end($end);
    } else {
        E('参数不足!');
    }
}
Beispiel #2
0
/**
 * 根据手机号查找用户
 * @method get_user_by_phone($phone)
 * @param  $phone 电话号码
 * @return array  返回一个或者全部查找结果
 */
function get_user_by_phone($phone)
{
    import('Common.Encrypt', COMMON_PATH, '.php');
    $tail = encrypt_end(substr($phone, -4));
    $where['phone'] = array('LIKE', '%%' . $tail);
    $info = M('User')->where($where)->field('id,student_number,phone')->select();
    if (!$info) {
        return false;
    }
    foreach ($info as $user) {
        if ($phone == decrypt_phone($user['phone'], $user['student_number'], $user['id'])) {
            return $user;
        }
    }
    return false;
}