| package com.secondworld.univeralsdk; | 
|   | 
| import android.app.Activity; | 
|   | 
| import com.linglei.sdk.openapi.LLSDK; | 
| import com.linglei.sdklib.open.ILLSDKCallback; | 
| import com.linglei.sdklib.open.ILLSDKInitCallback; | 
| import com.linglei.sdklib.open.reqinfo.OrderReq; | 
| import com.linglei.sdklib.open.reqinfo.RoleInfoReq; | 
| import com.linglei.sdklib.open.respinfo.UserResp; | 
|   | 
| import org.json.JSONException; | 
| import org.json.JSONObject; | 
|   | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * Created by Administrator on 2018/9/3 0003. | 
|  */ | 
|   | 
| public class JSPlatformUtil | 
| { | 
|     private static final String TAG = "JSPlatformUtil"; | 
|   | 
|     private boolean m_Init = false; | 
|   | 
|     private static JSPlatformUtil s_Instance; | 
|   | 
|     public static JSPlatformUtil getInstance() | 
|     { | 
|         if (s_Instance == null) | 
|         { | 
|             s_Instance = new JSPlatformUtil(); | 
|         } | 
|         return s_Instance; | 
|     } | 
|   | 
|     public boolean payProcessing = false; | 
|   | 
|     private Map<String, Object> m_Message = new HashMap<>(); | 
|   | 
|     public void init(final Activity activity) | 
|     { | 
|         if (m_Init) | 
|         { | 
|             return; | 
|         } | 
|   | 
|         LLSDK.getInstance().initSDK(activity, new ILLSDKInitCallback() | 
|         { | 
|             @Override | 
|             public void onInitResponse(int i, String s) | 
|             { | 
|                 m_Message.clear(); | 
|                 if (i == 1) | 
|                 { | 
|                     m_Init = true; | 
|                     m_Message.put("code", CodeA2U.FreePlatformInitOk); | 
|                     UniversalUtil.sendMessageToUnity(m_Message); | 
|                 } | 
|                 else | 
|                 { | 
|                     m_Message.clear(); | 
|                     m_Message.put("code", CodeA2U.FreePlatformInitFail); | 
|                     UniversalUtil.sendMessageToUnity(m_Message); | 
|                 } | 
|             } | 
|         }); | 
|   | 
|         LLSDK.getInstance().setLLSDKCallback(sdkCallback); | 
|     } | 
|   | 
|     public void login(Activity activity) | 
|     { | 
|         LLSDK.getInstance().login(activity); | 
|     } | 
|   | 
|     public void logout(final Activity activity) | 
|     { | 
|         LLSDK.getInstance().switchAccount(); | 
|     } | 
|   | 
|     public void pay(final Activity activity, | 
|                     String orderID, | 
|                     int amount, | 
|                     String title, | 
|                     String extraData) | 
|     { | 
|         OrderReq orderReq = new OrderReq(orderID, amount, title, extraData); | 
|         LLSDK.getInstance().pay(activity, orderReq); | 
|     } | 
|   | 
|     public void enterWorld(final Activity activity, | 
|                            String roleID, | 
|                            String serverID, | 
|                            String roleName, | 
|                            String roleLevel, | 
|                            String roleVipLevel, | 
|                            String gold) | 
|     { | 
|         // 登录成功后请设置角色信息 | 
|         // 参数依次为 游戏币当前余额、角色的等级、用户vip等级、角色唯一标识、角色名、所在区服 | 
|         RoleInfoReq roleInfoReq = new RoleInfoReq(Integer.parseInt(gold), Integer.parseInt(roleLevel), Integer.parseInt(roleVipLevel), roleID, roleName, serverID); | 
|         LLSDK.getInstance().setRoleData(roleInfoReq); | 
|     } | 
|   | 
|     private ILLSDKCallback sdkCallback = new ILLSDKCallback() | 
|     { | 
|         @Override | 
|         public void onLoginSuccess(UserResp userResp) | 
|         { | 
|             LogUtil.e(TAG, "登录成功"); | 
|              | 
|             // 成功回调UserResp类 | 
|             // UserResp字段: | 
|             // uid    用户唯一标识 | 
|             // token  cp服务器校验值 | 
|             // uid和token信息也可以在登录成功后调用LLSDK.getInstance().getAuth()来获取(务必做非空判断) | 
|   | 
|             try | 
|             { | 
|                 m_Message.clear(); | 
|                 JSONObject _info = new JSONObject(); | 
|                 _info.put("account", userResp.getUid()); | 
|                 _info.put("token", userResp.getToken()); | 
|                 _info.put("account_id", userResp.getUid()); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLoginOk); | 
|                 m_Message.put("info", _info); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } catch (JSONException e) | 
|             { | 
|                 e.printStackTrace(); | 
|             } | 
|         } | 
|   | 
|         @Override | 
|         public void onLoginFailure(int errorCode, String errorMsg) | 
|         { | 
|             LogUtil.e(TAG, "登录失败" + errorCode + " " + errorMsg); | 
|             m_Message.clear(); | 
|             m_Message.put("code", CodeA2U.FreePlatformLoginFail); | 
|             UniversalUtil.sendMessageToUnity(m_Message); | 
|         } | 
|   | 
|         @Override | 
|         public void onLogout() | 
|         { | 
|             // 表示用户已登出, 切换账号接口会走这个回调,游戏收到此消息通常情况下,需要主动调用登录接口 | 
|             m_Message.clear(); | 
|             m_Message.put("code", CodeA2U.FreePlatformLogoutOk); | 
|             UniversalUtil.sendMessageToUnity(m_Message); | 
|         } | 
|   | 
|         @Override | 
|         public void onPayResponse() | 
|         { | 
|             // 此方法回调只能说明支付操作完毕,具体是否支付成功以接入方服务端为准 | 
|             m_Message.clear(); | 
|             m_Message.put("code", CodeA2U.FreePlatformPayOk); | 
|             UniversalUtil.sendMessageToUnity(m_Message); | 
|             payProcessing = false; | 
|         } | 
|   | 
|         @Override | 
|         public void onPayFailure(int errorCode, String errorMsg) | 
|         { | 
|             m_Message.clear(); | 
|             m_Message.put("code", CodeA2U.FreePlatformPayFail); | 
|             UniversalUtil.sendMessageToUnity(m_Message); | 
|             payProcessing = false; | 
|         } | 
|     }; | 
|   | 
|     public void SendRegisterEvent() | 
|     { | 
|     } | 
| } |