| package com.secondworld.univeralsdk; | 
|   | 
| import android.app.Activity; | 
|   | 
| import com.mrcn.common.CommonMrSdk; | 
| import com.mrcn.sdk.callback.MrCallback; | 
| import com.mrcn.sdk.entity.MrError; | 
| import com.mrcn.sdk.entity.MrInitEntity; | 
| import com.mrcn.sdk.entity.MrPayEntity; | 
| import com.mrcn.sdk.entity.MrRoleEntity; | 
| import com.mrcn.sdk.entity.response.ResponseLoginData; | 
|   | 
| 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 MrPlatformUtil | 
| { | 
|     private static final String TAG = "MrPlatformUtil"; | 
|   | 
|     private boolean m_Init = false; | 
|   | 
|     private static MrPlatformUtil s_Instance; | 
|   | 
|     public static MrPlatformUtil getInstance() | 
|     { | 
|         if (s_Instance == null) | 
|         { | 
|             s_Instance = new MrPlatformUtil(); | 
|         } | 
|         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; | 
|         } | 
|   | 
|         MrInitEntity _initEntity = new MrInitEntity(); | 
|         _initEntity.setDebug(true); | 
|   | 
|         CommonMrSdk.getInstance().init(activity, _initEntity, new MrCallback<Void>() | 
|         { | 
|             @Override | 
|             public void onSuccess(Void aVoid) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Init = true; | 
|                 m_Message.put("code", CodeA2U.FreePlatformInitOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|   | 
|             @Override | 
|             public void onFail(MrError mrError) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformInitFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|   | 
|         CommonMrSdk.getInstance().registerLogout(activity, new MrCallback<Void>() | 
|         { | 
|             @Override | 
|             public void onSuccess(Void aVoid) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLogoutOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|   | 
|             @Override | 
|             public void onFail(MrError mrError) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLogoutFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void login(Activity activity) | 
|     { | 
|   | 
|         CommonMrSdk.getInstance().loginWithUI(activity, new MrCallback<ResponseLoginData>() | 
|         { | 
|             @Override | 
|             public void onSuccess(ResponseLoginData responseLoginData) | 
|             { | 
| //                public string account; | 
| //                public string token; | 
| //                public string tokenExpire; | 
| //                public int phone; | 
| //                public int accountID; | 
|   | 
|                 LogUtil.i(TAG, String.format( | 
|                         "token: %s, uid: %s, vSign: %s, userName: %s, isNew: %s, userType: %s, phone: %s, isRt: %s", | 
|                         responseLoginData.getLoginToken(), | 
|                         responseLoginData.getUid(), | 
|                         responseLoginData.getVsign(), | 
|                         responseLoginData.getUsername(), | 
|                         responseLoginData.isNew(), | 
|                         responseLoginData.getUserType(), | 
|                         responseLoginData.getPhone(), | 
|                         responseLoginData.isRT())); | 
|   | 
|                 try | 
|                 { | 
|                     m_Message.clear(); | 
|                     JSONObject _info = new JSONObject(); | 
|                     _info.put("account", responseLoginData.getUid()); | 
|                     _info.put("token", responseLoginData.getVsign()); | 
|                     _info.put("account_id", responseLoginData.getUid()); | 
|                     m_Message.put("code", CodeA2U.FreePlatformLoginOk); | 
|                     m_Message.put("info", _info); | 
|                     UniversalUtil.sendMessageToUnity(m_Message); | 
|                 } catch (JSONException e) | 
|                 { | 
|                     e.printStackTrace(); | 
|                 } | 
|             } | 
|   | 
|             @Override | 
|             public void onFail(MrError mrError) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLoginFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void logout(final Activity activity) | 
|     { | 
|         CommonMrSdk.getInstance().logOut(activity, new MrCallback<Void>() | 
|         { | 
|             @Override | 
|             public void onSuccess(Void aVoid) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLogoutOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|   | 
|             @Override | 
|             public void onFail(MrError mrError) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLogoutFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void pay(final Activity activity, | 
|                     String productID, | 
|                     String roleID, | 
|                     String roleName, | 
|                     String level, | 
|                     String extraData, | 
|                     String serverID, | 
|                     String orderID, | 
|                     String notifyUrl) | 
|     { | 
|         final MrPayEntity _entity = new MrPayEntity(); | 
|         _entity.setProductid(productID); | 
|         _entity.setRoleid(roleID); | 
|         _entity.setRolename(roleName); | 
|         _entity.setRolelevel(level); | 
|         _entity.setExtradata(extraData); | 
|         _entity.setServerid(serverID); | 
|         _entity.setGamecno(orderID); | 
|         _entity.setChannel("1"); | 
|         _entity.setNotifyurl(notifyUrl); | 
|   | 
|         CommonMrSdk.getInstance().pay(activity, _entity, new MrCallback<Void>() | 
|         { | 
|             @Override | 
|             public void onSuccess(Void aVoid) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformPayOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|             } | 
|   | 
|             @Override | 
|             public void onFail(MrError mrError) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformPayFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void createRole(final Activity activity, | 
|                            String roleID, | 
|                            String serverID, | 
|                            String roleName, | 
|                            String roleLevel, | 
|                            String roleVipLevel) | 
|     { | 
|         MrRoleEntity _entity = new MrRoleEntity(); | 
|         _entity.setRoleid(roleID); | 
|         _entity.setServerId(serverID); | 
|         _entity.setRoleName(roleName); | 
|         _entity.setRoleLevel(roleLevel); | 
|         _entity.setVipLevel(roleVipLevel); | 
|   | 
|         CommonMrSdk.getInstance().sendRoleCreateData(activity, _entity); | 
|     } | 
|   | 
|     public void enterWorld(final Activity activity, | 
|                            String roleID, | 
|                            String serverID, | 
|                            String roleName, | 
|                            String roleLevel, | 
|                            String roleVipLevel) | 
|     { | 
|         MrRoleEntity _entity = new MrRoleEntity(); | 
|         _entity.setRoleid(roleID); | 
|         _entity.setServerId(serverID); | 
|         _entity.setRoleName(roleName); | 
|         _entity.setRoleLevel(roleLevel); | 
|         _entity.setVipLevel(roleVipLevel); | 
|   | 
|         CommonMrSdk.getInstance().sendRoleLoginData(activity, _entity); | 
|     } | 
|   | 
|     public void SendRegisterEvent() | 
|     { | 
|     } | 
| } |