LenvSDK.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using efunbox_xyyf_windows.bean;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace efunbox_xyyf_windows.util
  9. {
  10. public class LenvSDK
  11. {
  12. public static String LevnToken = "";
  13. public static String getIdByTokenUrl = "https://cloud-rest.lenovomm.com/cloud-intermodal-core/api/v1/oauth/token";
  14. public static LenvUserInfo mLenvUserInfo;
  15. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  16. delegate Boolean LYSDKCallBack([MarshalAs(UnmanagedType.LPWStr)] StringBuilder in_par);
  17. /**
  18. * @brief LYSDKLogin 函数
  19. * @param in_param 参数1 json字符串,包括mchId(商户Id),appid,key;
  20. * @return 返回说明 :
  21. *-1 if already init
  22. *0 if success,
  23. *20 if already login
  24. *40 authorize failed
  25. */
  26. [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
  27. private static extern IntPtr LYSDKLogin(String in_param, [MarshalAs(UnmanagedType.FunctionPtr)] LYSDKCallBack callback, Boolean isAutoLogin);
  28. /**
  29. * @brief LYSDKLogout 函数
  30. * @return 返回说明 :
  31. * 0 if success,
  32. * 10 if SDKInit did not be called
  33. */
  34. [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
  35. private static extern int LYSDKLogout();
  36. /**
  37. * @brief LYSDKGetToken 函数
  38. * @return 返回说明 :
  39. * 0 if success,
  40. * 10 if SDKInit did not be called
  41. * 50 if not login
  42. */
  43. [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
  44. private static extern int LYSDKGetToken();
  45. /**
  46. * @brief LYSDKGetLoginStatus 函数
  47. * @return 返回说明 :
  48. * 0 if not login
  49. * 1 if login,
  50. */
  51. [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
  52. private static extern int LYSDKGetLoginStatus();
  53. private static LYSDKCallBack mLYSDKCallBack;
  54. /**
  55. *
  56. * 登录方法
  57. *
  58. * **/
  59. public static IntPtr LenvLogin(String in_params, bool isAuthLogin)
  60. {
  61. mLYSDKCallBack = (in_par) =>
  62. {
  63. LevnToken = in_par.ToString();
  64. if (TextUtils.isEmpty(in_par.ToString()))
  65. {
  66. //如果为空了,返回false
  67. return false;
  68. }
  69. else
  70. {
  71. //不为空再进行判断
  72. return true;
  73. }
  74. };
  75. return LYSDKLogin(in_params, mLYSDKCallBack, isAuthLogin); ;
  76. }
  77. /**
  78. * 登出方法
  79. * **/
  80. public static int LenvLogout()
  81. {
  82. return LYSDKLogout();
  83. }
  84. /**
  85. *
  86. * 联想获取token
  87. * **/
  88. public static int LenvGetToekn()
  89. {
  90. return LYSDKGetToken();
  91. }
  92. /**
  93. *
  94. * 联想登陆状态
  95. * **/
  96. public static int LenvLoginStatus()
  97. {
  98. return LYSDKGetLoginStatus();
  99. }
  100. public static String getParamSrc(Dictionary<string, string> paramsMap)
  101. {
  102. var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic);
  103. StringBuilder sb = new StringBuilder();
  104. foreach (KeyValuePair<string, string> kv in vDic)
  105. {
  106. string pkey = kv.Key;
  107. string pvalue = kv.Value;
  108. sb.Append(pkey + "=" + pvalue + "&");
  109. }
  110. String result = sb.ToString().Substring(0, sb.ToString().Length - 1);
  111. return result;
  112. }
  113. }
  114. }