Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

[*] 優化省份區分功能 #152

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MAIL_FROM_NAME=Example
MAIL_TO_ADDRESS=hello@example.com
MAIL_TO_NAME=Example

_94LIST_VERSION=1.3.1
_94LIST_VERSION=1.3.2
_94LIST_SLEEP=3
_94LIST_MAX_ONCE=20
_94LIST_PASSWORD=""
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 2024

### 07-10 v1.3.2

- [*] 優化省份區分功能

### 07-10 v1.3.1

- [+] 增加查詢時的信息,方便後臺管理
Expand Down
124 changes: 59 additions & 65 deletions app/Http/Controllers/ParseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,67 +42,7 @@ public function getConfig(Request $request)
]);
}

public function getProvinceFromIP($ip)
{
if (!config("94list.limit_prov")) return "上海市";

$prov = self::_getProvinceFromIP($ip);
if ($prov === null || $prov === false) return $prov;

// 省份标准名称映射表
$provinces = [
"北京" => "北京市",
"天津" => "天津市",
"上海" => "上海市",
"重庆" => "重庆市",
"河北" => "河北省",
"山西" => "山西省",
"内蒙古" => "内蒙古自治区",
"辽宁" => "辽宁省",
"吉林" => "吉林省",
"黑龙江" => "黑龙江省",
"江苏" => "江苏省",
"浙江" => "浙江省",
"安徽" => "安徽省",
"福建" => "福建省",
"江西" => "江西省",
"山东" => "山东省",
"河南" => "河南省",
"湖北" => "湖北省",
"湖南" => "湖南省",
"广东" => "广东省",
"广西" => "广西壮族自治区",
"海南" => "海南省",
"四川" => "四川省",
"贵州" => "贵州省",
"云南" => "云南省",
"西藏" => "西藏自治区",
"陕西" => "陕西省",
"甘肃" => "甘肃省",
"青海" => "青海省",
"宁夏" => "宁夏回族自治区",
"新疆" => "新疆维吾尔自治区",
"香港" => "香港特别行政区",
"澳门" => "澳门特别行政区",
"台湾" => "台湾省"
];

// 去除多余的空白字符
$name = trim($prov);

// 匹配并返回标准省份名称
foreach ($provinces as $key => $standardName) {
if (str_contains($name, $key)) return $standardName;
}

// 屏蔽非大陸地址
if (in_array($standardName, ["香港特别行政区", "澳门特别行政区", "台湾省"])) return false;

// 若无匹配则返回上海
return "上海市";
}

public function _getProvinceFromIP($ip)
public function _getProvinceFromIP($ip): string|null|false
{
if ($ip === "0.0.0.0") return "上海市";

Expand Down Expand Up @@ -179,13 +119,67 @@ public function _getProvinceFromIP($ip)
return null;
}

// 省份标准名称映射表
const provinces = [
"北京" => "北京市",
"天津" => "天津市",
"上海" => "上海市",
"重庆" => "重庆市",
"河北" => "河北省",
"山西" => "山西省",
"内蒙古" => "内蒙古自治区",
"辽宁" => "辽宁省",
"吉林" => "吉林省",
"黑龙江" => "黑龙江省",
"江苏" => "江苏省",
"浙江" => "浙江省",
"安徽" => "安徽省",
"福建" => "福建省",
"江西" => "江西省",
"山东" => "山东省",
"河南" => "河南省",
"湖北" => "湖北省",
"湖南" => "湖南省",
"广东" => "广东省",
"广西" => "广西壮族自治区",
"海南" => "海南省",
"四川" => "四川省",
"贵州" => "贵州省",
"云南" => "云南省",
"西藏" => "西藏自治区",
"陕西" => "陕西省",
"甘肃" => "甘肃省",
"青海" => "青海省",
"宁夏" => "宁夏回族自治区",
"新疆" => "新疆维吾尔自治区",
"香港" => "香港特别行政区",
"澳门" => "澳门特别行政区",
"台湾" => "台湾省"
];

public function getProvinceFromIP($ip)
{
$prov = self::_getProvinceFromIP($ip);
if ($prov === null || $prov === false) return $prov;

// 去除多余的空白字符
$name = trim($prov);

// 匹配并返回标准省份名称
foreach (self::provinces as $key => $standardName) {
if (str_contains($name, $key)) return $standardName;
}

// 无匹配
return null;
}

public static function _getRandomCookie($prov, $vipType)
{
$where = ["switch" => 1];
if (config("94list.limit_prov")) $where["prov"] = $prov;
return Account::query()
->where([
"switch" => 1,
"prov" => $prov
])
->where($where)
->whereIn("vip_type", $vipType)
->leftJoin("records", function ($join) {
$join->on("accounts.id", "=", "records.account_id")->whereDate("records.created_at", "=", now());
Expand Down
2 changes: 1 addition & 1 deletion config/94list.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fake_wx_user_agent" => "Mozilla/5.0 (Linux; Android 7.1.1; MI 6 Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043807 Mobile Safari/537.36 MicroMessenger/6.6.1.1220(0x26060135) NetType/4G Language/zh_CN MicroMessenger/6.6.1.1220(0x26060135) NetType/4G Language/zh_CN miniProgram",
"fake_cookie" => "BAIDUID=A4FDFAE43DDBF7E6956B02F6EF715373:FG=1; BAIDUID_BFESS=A4FDFAE43DDBF7E6956B02F6EF715373:FG=1; newlogin=1",

"version" => "1.3.1",
"version" => "1.3.2",
"sleep" => (int)env("_94LIST_SLEEP", 3),
"max_once" => (int)env("_94LIST_MAX_ONCE", 20),
"password" => env("_94LIST_PASSWORD", ""),
Expand Down