<?php
// 生成烟台、威海地区的手机号,支持四大运营商
// 定义运营商前缀
$prefixes = [
// 移动
'cmcc' => [
'134', '135', '136', '137', '138', '139', '147', '150', '151', '152',
'157', '158', '159', '172', '178', '182', '183', '184', '187', '188', '198'
],
// 联通
'cucc' => [
'130', '131', '132', '145', '155', '156', '166', '171', '175', '176', '185', '186'
],
// 电信
'ctcc' => [
'133', '149', '153', '173', '174', '177', '180', '181', '189', '191', '199'
],
// 广电
'crtc' => [
'192'
]
];
// 烟台、威海的地区码
$areaCodes = [
'yantai' => [357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369],
'weihai' => [356, 369] // 部分重叠
];
// 随机生成一个手机号
function generatePhoneNumber($prefixes, $areaCodes) {
// 随机选择运营商
$operators = array_keys($prefixes);
$operator = $operators[array_rand($operators)];
// 随机选择该运营商的前缀
$prefix = $prefixes[$operator][array_rand($prefixes[$operator])];
// 随机选择地区(烟台或威海)
$cities = array_keys($areaCodes);
$city = $cities[array_rand($cities)];
// 随机选择该地区的号码段
$areaCode = $areaCodes[$city][array_rand($areaCodes[$city])];
// 随机生成后四位
$suffix = rand(1000, 9999);
return [
'phone' => $prefix . $areaCode . $suffix,
'operator' => $operator,
'city' => $city
];
}
// 生成指定数量的手机号
$count = 20;
$phones = [];
for ($i = 0; $i < $count; $i++) {
$phones[] = generatePhoneNumber($prefixes, $areaCodes);
}
// 输出结果
header('Content-Type: application/json');
echo json_encode($phones, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
?>