Skip to content

Commit 4c25330

Browse files
committed
功能上线
1 parent 20c6f98 commit 4c25330

File tree

6 files changed

+498
-0
lines changed

6 files changed

+498
-0
lines changed

.github/workflows/assign-issue.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Assign Issue to Myself
2+
3+
on:
4+
issues:
5+
types: [opened] # 只对新开的 issue 触发
6+
7+
jobs:
8+
assign:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Assign issue to me
12+
uses: peter-evans/assign-issue@v2
13+
with:
14+
issue-number: ${{ github.event.issue.number }}
15+
assignees: 'zxc7563598'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "hejunjie/address-parser",
3+
"description": "收货地址智能解析工具,支持从非结构化文本中提取姓名、手机号、身份证号、省市区、详细地址等字段,适用于电商、物流、CRM 等系统。",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Hejunjie\\AddressParser\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "何俊杰",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=8.1",
19+
"hejunjie/china-division": "^1.0"
20+
}
21+
}

src/AddressParser.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Hejunjie\AddressParser;
4+
5+
use Hejunjie\AddressParser\Support\RegionMatcher;
6+
use Hejunjie\AddressParser\Support\UserInfoExtractor;
7+
8+
class AddressParser
9+
{
10+
11+
/**
12+
* 解析地址
13+
* @param mixed $string 地址信息
14+
* @param bool $user 信息中是否包含用户信息
15+
*
16+
* @return array {name: string, mobile: string, idn: string, postcode: string, province: string, city: string, region: string, street: string}
17+
*/
18+
public static function parse(string $string, bool $user = true)
19+
{
20+
// 默认数据
21+
$data = [
22+
'name' => '',
23+
'mobile' => '',
24+
'idn' => '',
25+
'postcode' => '',
26+
'province' => '',
27+
'city' => '',
28+
'region' => '',
29+
'street' => ''
30+
];
31+
// 提取用户信息(如果需要)
32+
if ($user) {
33+
$extractUserInfo = UserInfoExtractor::extractUserInfo($string);
34+
$data = array_merge($data, [
35+
'name' => $extractUserInfo['name'],
36+
'mobile' => $extractUserInfo['mobile'],
37+
'idn' => $extractUserInfo['idn'],
38+
'postcode' => $extractUserInfo['postcode']
39+
]);
40+
$addr = $extractUserInfo['addr'];
41+
} else {
42+
$addr = $string;
43+
}
44+
// 解析地址
45+
$address = RegionMatcher::parseAddress($addr);
46+
// 更新地址信息
47+
$data['province'] = $address['province'];
48+
$data['city'] = $address['city'];
49+
$data['region'] = $address['region'];
50+
$data['street'] = trim(str_replace(
51+
[$data['region'], $data['city'], $data['province']],
52+
['', '', ''],
53+
$address['street'] ?? ''
54+
));
55+
// 返回数据
56+
return $data;
57+
}
58+
}

0 commit comments

Comments
 (0)