package com.secondworld.univeralsdk; 
 | 
  
 | 
import android.app.Activity; 
 | 
  
 | 
import com.aoyou.sdk.SDKManager; 
 | 
import com.aoyou.sdk.domain.LoginErrorMsg; 
 | 
import com.aoyou.sdk.domain.LogincallBack; 
 | 
import com.aoyou.sdk.domain.OnLoginListener; 
 | 
import com.aoyou.sdk.domain.OnPaymentListener; 
 | 
import com.aoyou.sdk.domain.PaymentCallbackInfo; 
 | 
import com.aoyou.sdk.domain.PaymentErrorMsg; 
 | 
import com.reyun.tracking.sdk.Tracking; 
 | 
import com.ss.android.common.lib.EventUtils; 
 | 
  
 | 
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 YLPlatformUtil 
 | 
{ 
 | 
    private static final String TAG = "com.secondworld.univeralsdk.YLPlatformUtil"; 
 | 
  
 | 
    private boolean m_Init = false; 
 | 
  
 | 
    private static YLPlatformUtil s_Instance; 
 | 
  
 | 
    public static YLPlatformUtil getInstance() 
 | 
    { 
 | 
        if (s_Instance == null) 
 | 
        { 
 | 
            s_Instance = new YLPlatformUtil(); 
 | 
        } 
 | 
        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; 
 | 
        } 
 | 
  
 | 
        SDKManager.getInstance(activity); 
 | 
    } 
 | 
    private String m_AccountID; 
 | 
  
 | 
    public void login(Activity activity) 
 | 
    { 
 | 
        SDKManager.getInstance(activity).showLogin(activity, true, new OnLoginListener() 
 | 
        { 
 | 
            @Override 
 | 
            public void loginSuccess(LogincallBack logincallBack) 
 | 
            { 
 | 
                try 
 | 
                { 
 | 
                    m_Message.clear(); 
 | 
  
 | 
                    m_AccountID = logincallBack.username; 
 | 
  
 | 
                    JSONObject _info = new JSONObject(); 
 | 
                    _info.put("account", m_AccountID); 
 | 
                    _info.put("token", logincallBack.sign); 
 | 
                    _info.put("account_id", logincallBack.username); 
 | 
                    _info.put("token_expire",logincallBack.logintime); 
 | 
                    m_Message.put("code", CodeA2U.FreePlatformLoginOk); 
 | 
                    m_Message.put("info", _info); 
 | 
                    UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                } catch (JSONException e) 
 | 
                { 
 | 
                    e.printStackTrace(); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void loginError(LoginErrorMsg loginErrorMsg) 
 | 
            { 
 | 
                m_Message.clear(); 
 | 
                m_Message.put("code", CodeA2U.FreePlatformLoginFail); 
 | 
                UniversalUtil.sendMessageToUnity(m_Message); 
 | 
            } 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    // public void logout(final Activity activity) { } 
 | 
  
 | 
    public void pay(final Activity activity, 
 | 
                    String productName, 
 | 
                    String money, 
 | 
                    String roleID, 
 | 
                    String extraData, 
 | 
                    String serverID) 
 | 
    { 
 | 
        SDKManager.getInstance(activity).showPay(activity, 
 | 
                                                 roleID, 
 | 
                                                 money, 
 | 
                                                 serverID, 
 | 
                                                 productName, 
 | 
                                                 productName, 
 | 
                                                 extraData, 
 | 
                                                 new OnPaymentListener() 
 | 
                                                 { 
 | 
                                                     @Override 
 | 
                                                     public void paymentSuccess( 
 | 
                                                             PaymentCallbackInfo paymentCallbackInfo) 
 | 
                                                     { 
 | 
                                                         m_Message.clear(); 
 | 
                                                         m_Message.put("code", 
 | 
                                                                       CodeA2U.FreePlatformPayOk); 
 | 
                                                         UniversalUtil.sendMessageToUnity( 
 | 
                                                                 m_Message); 
 | 
                                                         payProcessing = false; 
 | 
                                                     } 
 | 
  
 | 
                                                     @Override 
 | 
                                                     public void paymentError( 
 | 
                                                             PaymentErrorMsg paymentErrorMsg) 
 | 
                                                     { 
 | 
                                                         LogUtil.i(TAG, 
 | 
                                                                   paymentErrorMsg.code + " => " + paymentErrorMsg.msg); 
 | 
                                                         m_Message.clear(); 
 | 
                                                         m_Message.put("code", 
 | 
                                                                       CodeA2U.FreePlatformPayFail); 
 | 
                                                         UniversalUtil.sendMessageToUnity( 
 | 
                                                                 m_Message); 
 | 
                                                         payProcessing = false; 
 | 
                                                     } 
 | 
                                                 }); 
 | 
    } 
 | 
  
 | 
    public void enterWorld(final Activity activity, 
 | 
                           String roleID, 
 | 
                           String roleName, 
 | 
                           String roleLv, 
 | 
                           String serverID, 
 | 
                           String serverName, 
 | 
                           JSONObject ext) 
 | 
    { 
 | 
        SDKManager.getInstance(activity).setRoleDate(activity, roleID, 
 | 
                                                     roleName, roleLv, 
 | 
                                                     serverID, serverName, 
 | 
                                                     ext); 
 | 
    } 
 | 
  
 | 
    public void SendRegisterEvent() 
 | 
    { 
 | 
        Tracking.setRegisterWithAccountID(m_AccountID); 
 | 
        EventUtils.setRegister("mobile",true); 
 | 
    } 
 | 
  
 | 
    public void SendLoginEvent() 
 | 
    { 
 | 
        Tracking.setLoginSuccessBusiness(m_AccountID); 
 | 
    } 
 | 
} 
 |