UserApi.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using cuidian.Common;
  7. using cuidian.OpenApi.Exceptions;
  8. using cuidian.OpenApi.Http;
  9. using cuidian.OpenApi.Utils;
  10. using Logs;
  11. namespace cuidian.OpenApi.Api
  12. {
  13. public class UserApi: BasicApi
  14. {
  15. public const string RESOURCE_ID = "user";
  16. public UserApi()
  17. : base(RESOURCE_ID) { }
  18. public BusinessObject Login()
  19. {
  20. string userId = AppSeting.Instance.GetValue("user");
  21. string passWord = AppSeting.Instance.GetValue("password");
  22. return Login(userId,passWord);
  23. }
  24. public BusinessObject Login(string userId, string password)
  25. {
  26. try
  27. {
  28. string data = String.Format("{{\"user\":{{\"user_id\":\"{0}\",\"password\":\"{1}\"}}}}"
  29. , userId
  30. , password);
  31. this.Method = "login";
  32. BusinessObject bo = BusinessObject.Do(this.Method, this.ResourceId, new Response(Client.Post(this.Url, this.GetSystemParameters(), data)));
  33. return bo;
  34. }
  35. catch (Exception e)
  36. {
  37. LogHelper.Error(e.Message);
  38. throw new ApiException(ERR_MSG_SDK_RUNTIME_ERROR, e);
  39. }
  40. }
  41. }
  42. }