| package com.secondworld.universalsdk; | 
|   | 
| import android.app.Application; | 
|   | 
| import android.app.Activity; | 
| import com.quicksdk.QuickSDK; | 
| import com.quicksdk.entity.UserInfo; | 
| import com.quicksdk.notifier.InitNotifier; | 
| import com.quicksdk.notifier.LoginNotifier; | 
| import com.quicksdk.notifier.LogoutNotifier; | 
| import com.quicksdk.notifier.SwitchAccountNotifier; | 
| import com.quicksdk.notifier.PayNotifier; | 
| import com.quicksdk.notifier.ExitNotifier; | 
| import com.quicksdk.User; | 
|   | 
| import org.json.JSONException; | 
| import org.json.JSONObject; | 
|   | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * Created by Administrator on 2020/8/25 0025. | 
|  */ | 
|   | 
| public class QuickPlatformUtil | 
| { | 
|   | 
|     private static QuickPlatformUtil m_Instance; | 
|     private static final String TAG = "QKPlatformUtil"; | 
|   | 
|     public static QuickPlatformUtil getInstance() | 
|     { | 
|         if (m_Instance == null) | 
|         { | 
|             m_Instance = new QuickPlatformUtil(); | 
|         } | 
|         return m_Instance; | 
|     } | 
|   | 
|     private Map<String, Object> m_Message = new HashMap<>(); | 
|     public boolean payProcessing = false; | 
|   | 
|     private UserInfo USER; | 
|   | 
|     public Boolean isInited = false; | 
|   | 
|     public void onCreate(){ | 
|   | 
|         QuickSDK.getInstance().setInitNotifier(new InitNotifier() { | 
|             @Override | 
|             public void onSuccess() | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformInitOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 isInited = true; | 
|             } | 
|   | 
|             @Override | 
|             public void onFailed(String s, String s1) | 
|             { | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformInitFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|   | 
|         QuickSDK.getInstance().setLoginNotifier(new LoginNotifier() { | 
|             @Override | 
|             public void onSuccess(UserInfo userInfo) { | 
|                 //登录成功,获取到用户信息userInfo | 
|                 //通过userInfo中的UID、token做服务器登录认证 | 
|                 m_Message.clear(); | 
|                 USER = userInfo; | 
|   | 
|                 //根据回调获取用户信息 | 
|                 String token = USER.getToken(); | 
|                 //通知到unity中的账号已经加上渠道ID,保证appid和spid唯一对应 | 
|                 String userId = USER.getUID() + "@" + com.quicksdk.Extend.getInstance().getChannelType(); | 
|                 String userName = USER.getUserName(); | 
|                 try | 
|                 { | 
|                     JSONObject _info = new JSONObject(); | 
|                     _info.put("account", userId); | 
|                     _info.put("token", token); | 
|                     _info.put("userName", USER.getUID()); | 
|                     m_Message.put("code", CodeA2U.FreePlatformLoginOk); | 
|                     m_Message.put("info", _info); | 
|                     UniversalUtil.sendMessageToUnity(m_Message); | 
|                 } catch (JSONException e) | 
|                 { | 
|                     e.printStackTrace(); | 
|                 } | 
|             } | 
|             @Override | 
|             public void onCancel() { | 
|                 //登录取消 | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLoginFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|             @Override | 
|             public void onFailed(final String message, String trace) { | 
|                 //登录失败 | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.FreePlatformLoginFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|         }); | 
|   | 
|         QuickSDK.getInstance().setLogoutNotifier(new LogoutNotifier() { | 
|             @Override | 
|             public void onSuccess() { | 
|                 //注销成功 | 
|                 m_Message.clear(); | 
|                 //需要把游戏切换回登陆前的场景,并重新弹出登录框等操作 | 
|                 m_Message.put("code", CodeA2U.FreePlatformLogoutOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|             } | 
|             @Override | 
|             public void onFailed(String message, String trace) { | 
|                 //注销失败,不做处理 | 
|             } | 
|         }); | 
|   | 
|         QuickSDK.getInstance().setSwitchAccountNotifier(new SwitchAccountNotifier() { | 
|             @Override | 
|             public void onSuccess(UserInfo userInfo) { | 
|                 //切换账号成功的回调,返回新账号的userInfo | 
|                 m_Message.clear(); | 
|                 USER = userInfo; | 
|   | 
|                 //根据回调获取用户信息 | 
|                 String token = USER.getToken(); | 
|                 //通知到unity中的账号已经加上渠道ID,保证appid和spid唯一对应 | 
|                 String userId = USER.getUID() + "@" + com.quicksdk.Extend.getInstance().getChannelType(); | 
|                 String userName = USER.getUserName(); | 
|                 try | 
|                 { | 
|                     JSONObject _info = new JSONObject(); | 
|                     _info.put("userName", USER.getUID()); | 
|                     _info.put("token", token); | 
|                     _info.put("account", userId); | 
|                     m_Message.put("code", CodeA2U.FreePlatformSwitchAccountOk); | 
|                     m_Message.put("info", _info); | 
|                     UniversalUtil.sendMessageToUnity(m_Message); | 
|                 } catch (JSONException e) | 
|                 { | 
|                     e.printStackTrace(); | 
|                 } | 
|             } | 
|   | 
|             @Override | 
|             public void onCancel() { | 
|                 //切换账号取消 | 
|             } | 
|   | 
|             @Override | 
|             public void onFailed(String message, String trace) { | 
|                 //切换账号失败 | 
|             } | 
|         }); | 
|   | 
|         QuickSDK.getInstance().setPayNotifier(new PayNotifier() { | 
|             @Override | 
|             public void onSuccess(String sdkOrderID, String cpOrderID, String extrasParams) { | 
|                 //支付成功 | 
|                 // sdkOrderID:quick订单号 cpOrderID:游戏订单号 | 
|                 LogUtil.i(TAG, "Pay Success Info sdkOrderID: " + sdkOrderID + "cpOrderID: " + cpOrderID); | 
|                 m_Message.clear(); | 
|                 //根据回调获取支付订单信息 | 
|                 m_Message.put("code", CodeA2U.FreePlatformPayOk); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|             } | 
|             @Override | 
|             public void onCancel(String cpOrderID) { | 
|                 //支付取消 | 
|                 m_Message.clear(); | 
|                 //根据回调获取支付订单信息 | 
|                 LogUtil.i(TAG, "Pay Fail Info cpOrderID: " + cpOrderID); | 
|                 m_Message.put("code", CodeA2U.FreePlatformPayCancel); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|   | 
|             } | 
|             @Override | 
|             public void onFailed(String cpOrderID, String message, String trace) { | 
|                 //支付失败 | 
|                 m_Message.clear(); | 
|                 //根据回调获取支付订单信息 | 
|                 LogUtil.i(TAG, "Pay Fail Info cpOrderID: " + cpOrderID); | 
|                 m_Message.put("code", CodeA2U.FreePlatformPayFail); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|             } | 
|         }); | 
|   | 
|   | 
|         QuickSDK.getInstance().setExitNotifier(new ExitNotifier() { | 
|             @Override | 
|             public void onSuccess() { | 
|                 //退出成功,游戏在此做自身的退出逻辑处理 | 
|                 m_Message.clear(); | 
|                 m_Message.put("code", CodeA2U.ExitGame); | 
|                 UniversalUtil.sendMessageToUnity(m_Message); | 
|                 payProcessing = false; | 
|             } | 
|   | 
|             @Override | 
|             public void onFailed(String message, String trace) { | 
|                 //退出失败,不做处理 | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void login(final Activity activity) | 
|     { | 
|         User.getInstance().login(activity); | 
|     } | 
|   | 
|     public void logout(final Activity activity) | 
|     { | 
|         User.getInstance().logout(activity); | 
|     } | 
| } |