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 paramsMap) { var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair 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; } } }