# 清理修复方案 > 2026-06-29 ## 设计原则 - 与 `miot/examples` 共用同一份 `config.json`,不重复造轮子 - 用户先跑 `miot/examples/cloud_oauth` 获取 token,token 自动写入 `miot/examples/config.json` - xiaomi 示例直接读这份已有的配置文件 --- ## 修改清单 ### A. 删除 `xiaomi/examples/config/config.go` 整个文件删掉。复用 `miot/examples/config` 包。 ### B. 9 个示例文件 — 统一替换 **旧代码**(每个文件都要删): ```go import "xiaomihome/xiaomi/examples/config" cfg, err := config.LoadFromEnv() entryData := map[string]interface{}{ "country_code": cfg.CountryCode, "cloud_server": cfg.CloudServer, "client_id": cfg.ClientID, "client_secret": cfg.ClientSecret, "access_token": cfg.AccessToken, } miotClient := miot.NewMIoTClient("phone", entryData, "", miot.DefaultCloudServer, miot.CtrlModeAuto) miotClient.Init() defer miotClient.Deinit() httpClient, _ := miot.NewMIoTHttpClient(cfg.CloudServer, cfg.ClientID, cfg.AccessToken) client := xiaomi.NewClient(miotClient, httpClient) ``` **替换为**: ```go import miotconfig "xiaomihome/miot/examples/config" cfg, err := miotconfig.LoadConfig("miot/examples/config.json") if err != nil { log.Fatal("请先运行 miot/examples/cloud_oauth 获取 token:", err) } client, err := xiaomi.NewClient(ctx, xiaomi.Config{ ClientID: miot.OAUTH2_CLIENT_ID, ClientSecret: "", AccessToken: cfg.AuthInfo.AccessToken, }) if err != nil { log.Fatal(err) } defer client.Close() ``` ### C. `miot/miot_client.go` — 去无用字段 `NewMIoTClient` 中 entryData 如有 `"country_code"`,删掉该行。