ErmcpService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Muchinfo.MTPClient.Infrastructure.LinkProxy;
  6. using Muchinfo.MTPClient.Infrastructure.Utilities;
  7. using Muchinfo.MTPClient.IService;
  8. using System.Runtime.InteropServices;
  9. namespace Muchinfo.MTPClient.Service
  10. {
  11. /// <summary>
  12. /// 风管云平台专用服务
  13. /// </summary>
  14. public class ErmcpService: IErmcpService
  15. {
  16. [DllImport("WinDataCollect.dll", EntryPoint = "?CTP_GetSystemInfo@@YAHPADAAH@Z", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
  17. private static extern int CTP_GetSystemInfo(IntPtr pSystemInfo, ref int nLen);
  18. /// <summary>
  19. /// 获取登录ID
  20. /// </summary>
  21. /// <param name="username">可传入“登录账号”、“登录代码”和“手机号码”</param>
  22. /// <param name="successAction">成功能回调</param>
  23. /// <param name="errorAction">失败回调</param>
  24. public void GetLoginId(string username, Action<string> successAction, Action<Data.ErrorEntity> errorAction)
  25. {
  26. var url = string.Format("{0}{1}?username={2}", LinkManager.Instance.Parameters.GoCommonSearchUrl,
  27. "/User/GetLoginID",
  28. username);
  29. var jsonString = HttpUtility.HttpGet(url);
  30. if (jsonString != null)
  31. {
  32. Dictionary<String, Object> dicJson =
  33. Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<String, Object>>(jsonString);
  34. if (dicJson["code"].ToString() == "200")
  35. {
  36. successAction(dicJson["data"].ToString());
  37. return;
  38. }
  39. }
  40. successAction(username);
  41. }
  42. /// <summary>
  43. /// CTP获取系统信息
  44. /// </summary>
  45. /// <returns></returns>
  46. public byte[] GetSystemInfo()
  47. {
  48. var nLen = 0;
  49. byte[] szOutData = null;
  50. //创建内存
  51. var pSystemInfo = Marshal.AllocHGlobal(270);
  52. var iResult = CTP_GetSystemInfo(pSystemInfo, ref nLen);
  53. if (iResult == 0)
  54. {
  55. //拷贝到数组上面
  56. szOutData = new byte[nLen];
  57. Marshal.Copy(pSystemInfo, szOutData, 0, nLen);
  58. }
  59. //释放内存
  60. Marshal.FreeHGlobal(pSystemInfo);
  61. return szOutData;
  62. }
  63. }
  64. }