build-for-baota.sh
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# 抖音物流项目 - 宝塔部署打包脚本
# 打包前后端为一体,输出到 douyin-deploy 目录
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
DEPLOY_DIR="$ROOT/douyin-deploy"
echo "=== 抖音项目打包(宝塔部署)==="
# 1. 构建前端
echo "[1/4] 构建前端..."
cd "$ROOT/frontend"
npm run build
# 2. 复制前端到后端 wwwroot
echo "[2/4] 复制前端到 wwwroot..."
mkdir -p "$ROOT/DouyinLogistics.API/wwwroot"
cp -r "$ROOT/frontend/dist/"* "$ROOT/DouyinLogistics.API/wwwroot/"
# 3. 发布后端
echo "[3/4] 发布后端..."
cd "$ROOT/DouyinLogistics.API"
dotnet publish -c Release -o "$DEPLOY_DIR"
# 4. 复制部署说明
echo "[4/4] 生成部署说明..."
cat > "$DEPLOY_DIR/宝塔部署说明.md" << 'DEPLOY_EOF'
# 抖音物流系统 - 宝塔部署说明
## 一、环境要求
- 宝塔面板
- .NET 8.0 运行时
- MySQL 5.7+ 或 8.0
## 二、部署步骤
### 1. 安装 .NET 8 运行时
宝塔 → 软件商店 → 搜索「.NET」→ 安装 .NET 8 运行时
或命令行:
```bash
# CentOS/RHEL
sudo dnf install dotnet-runtime-8.0
# Ubuntu
sudo apt install dotnet-runtime-8.0
```
### 2. 创建 MySQL 数据库
- 数据库名:DouyinLogistics
- 字符集:utf8mb4
### 3. 修改配置文件
编辑 `appsettings.json`:
- **ConnectionStrings.DefaultConnection**:改为你的 MySQL 连接串
- **Douyin**:抖音应用配置(AppKey、AppSecret、CallbackUrl 等)
- **ErpApi.BaseUrl**:ERP(NCC)API 地址,如 `http://你的服务器:2015`
### 4. 上传并运行
1. 将整个 `douyin-deploy` 目录上传到服务器(如 /www/wwwroot/douyin)
2. 宝塔 → 网站 → 添加站点(或使用已有站点)
3. 宝塔 → 软件商店 → 安装「PM2」或使用「Supervisor」
4. 添加进程守护:
- 启动命令:`dotnet DouyinLogistics.API.dll`
- 运行目录:/www/wwwroot/douyin(你的实际路径)
### 5. Nginx 反向代理(推荐)
```nginx
location / {
proxy_pass http://127.0.0.1:5070;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
```
或直接运行在 80 端口:修改 `DouyinLogistics.API` 启动参数 `--urls "http://0.0.0.0:80"`
## 三、首次运行
1. 启动后访问:http://你的域名/
2. 首次需完成抖音 OAuth 授权获取 Token
3. 点击「同步订单」拉取抖音订单
## 四、环境变量(可选)
可通过环境变量覆盖配置,便于 Docker/宝塔:
- DB_CONNECTION:数据库连接串
- DY_APP_KEY、DY_APP_SECRET:抖音应用
- DY_CALLBACK_URL:授权回调地址
- ErpApi 等见 appsettings.json
DEPLOY_EOF
echo ""
echo "✅ 打包完成!"
echo " 输出目录: $DEPLOY_DIR"
echo " 请将 $DEPLOY_DIR 整个目录上传到宝塔服务器"
echo ""