123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using efunbox_xyyf_windows.bean;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace efunbox_xyyf_windows.util
- {
- public class LenvSDK
- {
- public static String LevnToken = "";
- public static String getIdByTokenUrl = "https://cloud-rest.lenovomm.com/cloud-intermodal-core/api/v1/oauth/token";
- public static LenvUserInfo mLenvUserInfo;
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- delegate Boolean LYSDKCallBack([MarshalAs(UnmanagedType.LPWStr)] StringBuilder in_par);
- /**
- * @brief LYSDKLogin 函数
- * @param in_param 参数1 json字符串,包括mchId(商户Id),appid,key;
- * @return 返回说明 :
- *-1 if already init
- *0 if success,
- *20 if already login
- *40 authorize failed
- */
- [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr LYSDKLogin(String in_param, [MarshalAs(UnmanagedType.FunctionPtr)] LYSDKCallBack callback, Boolean isAutoLogin);
- /**
- * @brief LYSDKLogout 函数
- * @return 返回说明 :
- * 0 if success,
- * 10 if SDKInit did not be called
- */
- [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
- private static extern int LYSDKLogout();
- /**
- * @brief LYSDKGetToken 函数
- * @return 返回说明 :
- * 0 if success,
- * 10 if SDKInit did not be called
- * 50 if not login
- */
- [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
- private static extern int LYSDKGetToken();
- /**
- * @brief LYSDKGetLoginStatus 函数
- * @return 返回说明 :
- * 0 if not login
- * 1 if login,
- */
- [DllImport("LYSDK.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
- private static extern int LYSDKGetLoginStatus();
- private static LYSDKCallBack mLYSDKCallBack;
- /**
- *
- * 登录方法
- *
- * **/
- public static IntPtr LenvLogin(String in_params, bool isAuthLogin)
- {
- mLYSDKCallBack = (in_par) =>
- {
-
- LevnToken = in_par.ToString();
-
- if (TextUtils.isEmpty(in_par.ToString()))
- {
- //如果为空了,返回false
- return false;
- }
- else
- {
- //不为空再进行判断
- return true;
- }
- };
- return LYSDKLogin(in_params, mLYSDKCallBack, isAuthLogin); ;
- }
- /**
- * 登出方法
- * **/
- public static int LenvLogout()
- {
- return LYSDKLogout();
- }
- /**
- *
- * 联想获取token
- * **/
- public static int LenvGetToekn()
- {
- return LYSDKGetToken();
- }
- /**
- *
- * 联想登陆状态
- * **/
- public static int LenvLoginStatus()
- {
- return LYSDKGetLoginStatus();
- }
- public static String getParamSrc(Dictionary<string, string> paramsMap)
- {
- var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic);
- StringBuilder sb = new StringBuilder();
- foreach (KeyValuePair<string, string> kv in vDic)
- {
- string pkey = kv.Key;
- string pvalue = kv.Value;
- sb.Append(pkey + "=" + pvalue + "&");
- }
- String result = sb.ToString().Substring(0, sb.ToString().Length - 1);
- return result;
- }
- }
- }
|