void LoginCheck()
    {
        if (isDebug == true)
        {
            bLogined = true;
            return;
        }

        string url = createLoginURL();

        Debug.Log("LoginCheck url:" + url);
        if (url == null)
        {
            return;
        }
        string result = executeHttpGet(url);

        Debug.Log("LoginCheck result:" + result);
        if (result == null || !(result == "SUCCESS"))
        {
            bLogined = false;
        }
        else
        {
            bLogined = true;
            using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
                using (AndroidJavaObject curActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) {
                    setRoleData(curActivity.GetRawObject(), "1", "hunter", "30", "1", "1");


                    SFJSONObject gameinfo = new SFJSONObject();
                    gameinfo.put("roleId", "1");                                               //当前登录的玩家角色ID,必须为数字
                    gameinfo.put("roleName", "猎人");                                            //当前登录的玩家角色名,不能为空,不能为null
                    gameinfo.put("roleLevel", "100");                                          //当前登录的玩家角色等级,必须为数字,且不能为0,若无,传入1
                    gameinfo.put("zoneId", "1");                                               //当前登录的游戏区服ID,必须为数字,且不能为0,若无,传入1
                    gameinfo.put("zoneName", "阿狸一区");                                          //当前登录的游戏区服名称,不能为空,不能为null
                    gameinfo.put("balance", "0");                                              //用户游戏币余额,必须为数字,若无,传入0
                    gameinfo.put("vip", "1");                                                  //当前用户VIP等级,必须为数字,若无,传入1
                    gameinfo.put("partyName", "无帮派");                                          //当前角色所属帮派,不能为空,不能为null,若无,传入“无帮派”
                    gameinfo.put("roleCTime", "21322222");                                     //单位为秒,创建角色的时间
                    gameinfo.put("roleLevelMTime", "54456556");                                //单位为秒,角色等级变化时间,如果没有就传-1
                    setData(curActivity.GetRawObject(), "createrole", gameinfo.toString());    //创建新角色时调用,必接接口
                    setData(curActivity.GetRawObject(), "levelup", gameinfo.toString());       //玩家升级角色时调用,必接接口
                    setData(curActivity.GetRawObject(), "enterServer", gameinfo.toString());   //选择服务器进入时调用,必接接口
                    setData(curActivity.GetRawObject(), "loginGameRole", gameinfo.toString()); ////这个接口只有接uc的时候才会用到和setRoleData一样的功能,但是两个放在一起不会出现冲突,必接接口
                }
            }
        }
    }
Beispiel #2
0
    public override void UpdatePlayerInfo(SDKData.RoleData roleData, SDKData.UpdatePlayerInfoType updateType)
    {
        using (AndroidJavaObject curActivity = CallAndroidFuncGetResult <AndroidJavaObject>("GetGameMainActivity"))
        {
            string updateType_Key = updateType == SDKData.UpdatePlayerInfoType.createRole ? "createrole" : "levelup";

            if (updateType == SDKData.UpdatePlayerInfoType.enterGame)
            {
                updateType_Key = "enterServer";

                setRoleData(curActivity.GetRawObject(), roleData.roleId, roleData.roleName, roleData.roleLevel, roleData.realmId, roleData.realmName);
            }


            SFJSONObject gameinfo = new SFJSONObject();
            gameinfo.put("roleId", roleData.roleId);        //当前登录的玩家角色ID,必须为数字
            gameinfo.put("roleName", roleData.roleName);    //当前登录的玩家角色名,不能为空,不能为null
            gameinfo.put("roleLevel", roleData.roleLevel);  //当前登录的玩家角色等级,必须为数字,且不能为0,若无,传入1
            gameinfo.put("zoneId", roleData.realmId);       //当前登录的游戏区服ID,必须为数字,且不能为0,若无,传入1
            gameinfo.put("zoneName", roleData.realmName);   //当前登录的游戏区服名称,不能为空,不能为null
            gameinfo.put("balance", "0");                   //用户游戏币余额,必须为数字,若无,传入0
            gameinfo.put("vip", "1");                       //当前用户VIP等级,必须为数字,若无,传入1
            gameinfo.put("partyName", "无帮派");               //当前角色所属帮派,不能为空,不能为null,若无,传入“无帮派”
            gameinfo.put("roleCTime", roleData.createTime); //单位为秒,创建角色的时间
            gameinfo.put("roleLevelMTime", "-1");           //单位为秒,角色等级变化时间,如果没有就传-1

            string gameInfoString = gameinfo.toString();

            setData(curActivity.GetRawObject(), updateType_Key, gameInfoString);//各种时机调用,必接接口

            if (updateType_Key == "enterServer")
            {
                //在调用一遍,游戏里enterserver和logingamerole一样
                setData(curActivity.GetRawObject(), "loginGameRole", gameInfoString);////这个接口只有接uc的时候才会用到和setRoleData一样的功能,但是两个放在一起不会出现冲突,必接接口
            }
        }
    }
    void Awake()
    {
        goodName = PlayerPrefs.GetString("goodName", "");
        money    = PlayerPrefs.GetInt("money", 0);
        string itemCode = PlayerPrefs.GetString("goodid", "");
        string remain   = PlayerPrefs.GetString("remain", "");

        Debug.Log("itemCode=" + itemCode + " remain=" + remain);
        bLogined = PlayerPrefs.GetInt("login", 0) == 0 ? false : true;
        keyName  = PlayerPrefs.GetString("keyName", "");
        if (goodName.Equals("") || money == 0)
        {
            desc    = "";
            paytype = "";
        }
        else
        {
            desc    = PlayerPrefs.GetString("desc", "");
            paytype = PlayerPrefs.GetString("paytype", "");
        }
        if (keyName.Equals(""))
        {
            setDataType = "";
        }
        else
        {
            setDataType = PlayerPrefs.GetString("setDataType", "");
        }


        PlayerPrefs.DeleteAll();

        if (Application.platform == RuntimePlatform.Android)
        {
            using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
                using (AndroidJavaObject curActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) {
                    setLoginListener(curActivity.GetRawObject(), "Main Camera", "LoginResult");
                    Debug.Log("Awake setDataType:" + setDataType);
                    if (bLogined == true)
                    {
                        Debug.Log("Alogin result = login success");
                        str = "login result = login success";
                        if (paytype.Equals(PAYTYPE_PAY))
                        {
                            str = "PAYTYPE_PAY";
                            pay(curActivity.GetRawObject(), "Main Camera", money, goodName, 1, desc, CP_PAY_SYNC_URL, "PayResult");
                        }
                        else if (paytype.Equals(PAYTYPE_CHARGE))
                        {
                            str = "PAYTYPE_CHARGE";
                            charge(curActivity.GetRawObject(), "Main Camera", goodName, money, 1, desc, CP_PAY_SYNC_URL, "PayResult");
                        }
                        else if (paytype.Equals(PAYTYPE_PAY_EXTEND))
                        {
                            str = "PAYTYPE_PAY_EXTEND";
                            payExtend(curActivity.GetRawObject(), "Main Camera", money, goodName, itemCode, remain,
                                      1, desc, CP_PAY_SYNC_URL, "PayResult");
                        }
                        else if (setDataType.Equals(PAYTYPE_ROLE))
                        {
                            str = "PAYTYPE_ROLE";
                            SFJSONObject gameinfo = new SFJSONObject();
                            gameinfo.put("roleId", "1");                                       //当前登录的玩家角色ID,必须为数字
                            gameinfo.put("roleName", "猎人");                                    //当前登录的玩家角色名,不能为空,不能为null
                            gameinfo.put("roleLevel", "100");                                  //当前登录的玩家角色等级,必须为数字,且不能为0,若无,传入1
                            gameinfo.put("zoneId", "1");                                       //当前登录的游戏区服ID,必须为数字,且不能为0,若无,传入1
                            gameinfo.put("zoneName", "阿狸一区");                                  //当前登录的游戏区服名称,不能为空,不能为null
                            gameinfo.put("balance", "0");                                      //用户游戏币余额,必须为数字,若无,传入0
                            gameinfo.put("vip", "1");                                          //当前用户VIP等级,必须为数字,若无,传入1
                            gameinfo.put("partyName", "无帮派");                                  //当前角色所属帮派,不能为空,不能为null,若无,传入“无帮派”
                            gameinfo.put("roleCTime", "21322222");                             //单位为秒,创建角色的时间
                            gameinfo.put("roleLevelMTime", "54456556");                        //单位为秒,角色等级变化时间,如果没有就传-1
                            setData(curActivity.GetRawObject(), keyName, gameinfo.toString()); //创建新角色时调用,必接接口
                        }
                    }
                    Debug.Log("user had payed str:" + str);
                }
            }
        }
        isPause = false;

        isFocus = false;
    }