/// <summary> /// 读取本地账号文件 /// </summary> private void LoadAccountConfig() { #if !WINDOWS_GUEST string accountInipath = GameDefine.AppPersistentDataPath + GameDefine.AccountInfoFile; //检测文件是否存在 /* if (!File.Exists(accountInipath)) * { * Debug.Log("LoadAccountConfig no file "); * GetPlayerData().SetPlayerID(0); * return; * } * StreamReader sr = File.OpenText(path); * uint playerid; * uint.TryParse(sr.ReadLine(), out playerid); * GetPlayerData().SetPlayerID(playerid); * Debug.Log("LoadAccountConfig PlayerID:" + playerid); * sr.Close(); * sr.Dispose();*/ INIParser IniFile = new INIParser(); IniFile.Open(accountInipath); VisitorAccountId = IniFile.ReadUIntValue("Account", "VisitorId", 0); BindMobileAccountId = IniFile.ReadUIntValue("Account", "BindPlayerId", 0); IniFile.Close(); CWechatUserAuth.GetInstance().ReadWeChatAuthInfo(); //如果游客账号与绑定状态的账号ID一致说明上次登陆进行了绑定操作 //if (VisitorAccountId == BindMobileAccountId && VisitorAccountId !=0) // VisitorAccountId = 0; //Debug.Log("AccountConfig VisitorId:" + VisitorAccountId + ",BindPlayerId:" + BindMobileAccountId); #endif }
/// <summary> /// 请求微信登录 /// </summary> private void WeChatAuthLogin() { UMessage vchatmsg = new UMessage((uint)GameCity.EMSG_ENUM.CrazyCityMsg_PLAYERLOGIN); MessageLogin ml_ = new MessageLogin(); Luancher.IsVChatLogin = true; ml_.nUseID = VisitorAccountId; ml_.smachinecode = SystemInfo.deviceUniqueIdentifier; ml_.sVersion = GameMain.Instance.GetAppVersion(); if (Application.platform == RuntimePlatform.IPhonePlayer) { ml_.nPlatform = 1; } else if (Application.platform == RuntimePlatform.Android) { ml_.nPlatform = 2; } else { ml_.nPlatform = 0; } vchatmsg.Add(ml_.nUseID); vchatmsg.Add(ml_.smachinecode); vchatmsg.Add(ml_.sVersion); vchatmsg.Add(ml_.nPlatform); vchatmsg.Add((byte)2); //登陆方式标记 1 运营渠道 2 微信 vchatmsg.Add(CWechatUserAuth.GetInstance().GetUserUnionId()); vchatmsg.Add(CWechatUserAuth.GetInstance().GetUserHeadImgUrl()); vchatmsg.Add(CWechatUserAuth.GetInstance().GetUserNickname()); vchatmsg.Add(CWechatUserAuth.GetInstance().GetUserSex()); NetWorkClient.GetInstance().SendMsg(vchatmsg); }
public static CWechatUserAuth GetInstance() { if (AuthInstance == null) { AuthInstance = new CWechatUserAuth(); } return(AuthInstance); }
bool BackPlayerWxQRAuthCode(uint _msgType, UMessage _ms) { //微信扫描二维码登录授权后code string QRAuthCode = _ms.ReadString(); CWechatUserAuth.GetInstance().GetAuthUserInfo(QRAuthCode); return(true); }
//微信登陆授权回调 public void WXAuthCallback(string retcode) { Debug.Log(" Wechat login auth on Resp:" + retcode); //0(为0时返回用户换取access_token的code,仅在ErrCode为0时有效) //-4(用户拒绝授权) //-2(用户取消) int retstate; int.TryParse(retcode, out retstate); if (retstate == -4) { //用户拒绝授权 } else if (retstate == -2) { //用户取消 } else { //用户同意 CWechatUserAuth.GetInstance().GetAuthUserInfo(retcode); } }
/// <summary> /// 登陆流程有账号直接登陆,没账号显示登陆界面 /// </summary> public void IntoLoginProcess() { #if UNITY_EDITOR if (VisitorAccountId == 0 && BindMobileAccountId == 0) { LoadChooseLoginType(); } else { RequestLogin(); } #elif UNITY_STANDALONE_WIN #if WINDOWS_GUEST uint accountId = 0; string [] CommandLine = System.Environment.CommandLine.Split('-'); if (CommandLine.Length >= 2) { string nameValue = "ID ="; int separatorIndex = CommandLine[1].IndexOf("ID =") + nameValue.Length + 1; string AccountIdName = CommandLine[1].Substring(separatorIndex, CommandLine[1].Length - separatorIndex); if (separatorIndex != -1 && uint.TryParse(AccountIdName, out accountId)) { CLoginUI.Instance.SetVisitorAccountId(accountId); CLoginUI.Instance.RequestLogin(); } else { LoadChooseLoginType(); } } else { LoadChooseLoginType(); } #else //如果已经微信授权用户数据直接登陆 if (!string.IsNullOrEmpty(CWechatUserAuth.GetInstance().GetUserUnionId())) { RequestLogin(LoginType.LoginType_Wechat); } else { LoadChooseLoginType(); } #endif #else ////如果已经微信授权用户数据直接登陆 //if(!string.IsNullOrEmpty(CWechatUserAuth.GetInstance().GetUserUnionId())) //{ // RequestLogin(LoginType.LoginType_Wechat); //} //else //{ // LoadChooseLoginType(); // //RequestLogin(); //} if (VisitorAccountId == 0 && BindMobileAccountId == 0) { LoadChooseLoginType(); } else { RequestLogin(); } #endif }