docs(course): set production backend to shopneu.hmos.site and clean draft notes
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled

This commit is contained in:
xiaobai committed 2026-03-04 20:32:35 +08:00
1 parent dc2e32c437
commit 24945ee3fe
2 files changed
+20 -11

No files matched your search

@@ -33,7 +33,7 @@ kmp-mini-shopping/
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
``` ```
如果课堂接 HTTP(局域网后端),`application` 里加: 如果仅在本地联调 HTTP(局域网后端),`application` 里加:
```xml ```xml
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
@@ -75,6 +75,16 @@ Android 侧引擎(`shared/androidMain`)需要:
- Ktor Serialization 官方说明(ContentNegotiation/JSON 的用途): - Ktor Serialization 官方说明(ContentNegotiation/JSON 的用途):
`https://ktor.io/docs/server-serialization.html` `https://ktor.io/docs/server-serialization.html`
### 2.1 课程统一后端地址(已部署)
- 线上地址:`https://shopneu.hmos.site`
- 商品接口:`https://shopneu.hmos.site/api/products`(推荐)
Android 端 `baseUrl` 建议写:
```kotlin
ProductApi(baseUrl = "https://shopneu.hmos.site/api", useMock = false)
```
### 3. `content-negotiation` 是干什么的?(给学生讲) ### 3. `content-negotiation` 是干什么的?(给学生讲)
`ktor-client-content-negotiation` + `ktor-serialization-kotlinx-json` 这两个依赖, `ktor-client-content-negotiation` + `ktor-serialization-kotlinx-json` 这两个依赖,
就是让 Ktor 能把接口返回的 JSON 自动反序列化成 Kotlin 数据类(例如 `List<Product>`)。 就是让 Ktor 能把接口返回的 JSON 自动反序列化成 Kotlin 数据类(例如 `List<Product>`)。
@@ -101,8 +111,6 @@ install(ContentNegotiation) {
- 后端额外返回 `tag/extra` - 后端额外返回 `tag/extra`
- 开启 `ignoreUnknownKeys = true` 后,`id/title` 仍可正常解析。 - 开启 `ignoreUnknownKeys = true` 后,`id/title` 仍可正常解析。
> 你在官方文档里看到的 `prettyPrint`、`isLenient` 只是配置示例,
> `ignoreUnknownKeys` 同样是 JsonBuilder 的常用配置项。
--- ---
@@ -139,18 +139,19 @@ import androidx.compose.foundation.lazy.staggeredgrid.items as staggeredItems
## 六、联调与稳定性(第5段:15分钟) ## 六、联调与稳定性(第5段:15分钟)
### Step 10:切后端地址 ### Step 10:切后端地址(课程统一)
- 模拟器:`http://10.0.2.2:8080` 或 `/api` - 线上服务:`https://shopneu.hmos.site`
- 真机:`http://192.168.x.x:8080` 或 `/api` - 推荐接口前缀:`https://shopneu.hmos.site/api`
### Step 11:Android HTTP 放行(开发环境) Android 端示例:
`AndroidManifest.xml`:
```xml ```kotlin
android:usesCleartextTraffic="true" ProductApi(baseUrl = "https://shopneu.hmos.site/api", useMock = false)
``` ```
### Step 12:图片兜底 > 使用 HTTPS 时,不需要 `usesCleartextTraffic`。
### Step 11:图片兜底
- 网络图加载中:显示本地默认图 - 网络图加载中:显示本地默认图
- 加载失败:显示本地默认图 - 加载失败:显示本地默认图