TripleView / MiHome.Net

MiHome's C# native SDK,which can control Mijia smart devices through the network and local methods.
MIT License
123 stars 17 forks source link

访问设备列表出错,这个是我姿势有问题吗? #3

Closed mrhuo closed 2 months ago

mrhuo commented 7 months ago
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MiHome.Net.Middleware;
using MiHome.Net.Service;

var hostBuilder = Host.CreateDefaultBuilder();
//添加小米米家的驱动服务,需要小米账号和密码
hostBuilder.ConfigureServices(it => it.AddMiHomeDriver(x =>
{
    x.UserName = "xxx";
    x.Password = "xxx";
}));
var host = hostBuilder.Build();
var miHomeDriver = host.Services.GetService<IMiHomeDriver>();
//列出家庭里所有的智能家居设备
var deviceList = await miHomeDriver?.Cloud?.GetDeviceListAsync();   // <---- 这里出错
Console.WriteLine(deviceList);

控制台信息:


info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[100]
      Start processing HTTP request GET https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[100]
      Sending HTTP request GET https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[101]
      Received HTTP response headers after 325.6286ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[101]
      End processing HTTP request after 354.8538ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[100]
      Start processing HTTP request POST https://account.xiaomi.com/pass/serviceLoginAuth2?_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[100]
      Sending HTTP request POST https://account.xiaomi.com/pass/serviceLoginAuth2?_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[101]
      Received HTTP response headers after 132.9929ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[101]
      End processing HTTP request after 138.56ms - 200
Unhandled exception. System.UriFormatException: Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at SummerBoot.Feign.DefaultFeignUnitOfWork.GetCookies(String url)
   at SummerBoot.Feign.FeignAspectSupport.ProcessCookie(RequestTemplate requestTemplate)
   at SummerBoot.Feign.FeignAspectSupport.BaseExecuteAsync[T](MethodInfo method, Object[] args, IServiceProvider serviceProvider)
   at SummerBoot.Feign.HttpService.ExecuteAsync[T](List`1 originArgs, MethodInfo method, IServiceProvider serviceProvider)
   at MiHome.Net.Service.MIotCloud.GetInternalLoginInfoAsync()
   at MiHome.Net.Service.MIotCloud.GetLoginInfoAsync()
   at MiHome.Net.Service.MIotCloud.BeginControlDeviceCookieAsync()
   at MiHome.Net.Service.MIotCloud.GetDeviceListAsync()
   at Program.<Main>$(String[] args) in G:\code\WpfApp1\MiHomeTest\Program.cs:line 16
   at Program.<Main>(String[] args)
``
TripleView commented 7 months ago

你好,添加一下我的wx,hezp666

humoyun1798 commented 6 months ago

我也遇到了,好像是登录失败 image

TripleView commented 6 months ago

我也遇到了,好像是登录失败 image

你好,你也添加一下我的微信,hezp666

TripleView commented 2 months ago

这个问题主要是登陆失败引起的,比如账号密码错误,或者账号需要到米家进行手机验证。