Ejemplo n.º 1
0
        /****************/

        private static async ETTask SignIn(this BenchmarkClientComponent self, string deviceUniqueIdentifier)
        {
            string secret = CryptographyHelper.AESEncrypt(deviceUniqueIdentifier);

            var signInResult = await UserUtility.SignIn(() =>
            {
                //連接Realm
                self.ConnectRealm();
                return(self.session);
            }, address =>
            {
                //斷開Realm
                self.session.Dispose();
                //連接Gate
                self.ConnectGate(address);
                return(self.session);
            }, new C2R_Authentication()
            {
                Info = new AuthenticationInfo
                {
                    Language            = 10,
                    Secret              = secret,
                    FirebaseDeviceToken = string.Empty,
                    Type = AuthenticationType.Guest,
                }
            });

            self.userName = signInResult.playerBaseInfo.Name;
            //self.UserLog(signInResult.playerBaseInfo.Name);
        }
        public string ReplyMessageMiddle(string replyMsg)
        {
            string replyMsgEncrypted = CryptographyHelper.AESEncrypt(replyMsg, _baseSettings.EncodingAESKey, _baseSettings.AppId);
            string timestamp         = UtilityHelper.GetTimeStamp().ToString();
            string nonce             = UtilityHelper.GenerateNonce();
            string signature         = SignatureGenerater.GenerateSignature(_baseSettings.Token, timestamp, nonce, replyMsgEncrypted);

            StringBuilder sb = new StringBuilder();

            sb.Append($"<xml>");
            sb.Append($"<Encrypt><![CDATA[{replyMsgEncrypted}]]></Encrypt>");
            sb.Append($"<MsgSignature><![CDATA[{signature}]]></MsgSignature>");
            sb.Append($"<TimeStamp><![CDATA[{timestamp}]]></TimeStamp>");
            sb.Append($"<Nonce><![CDATA[{nonce}]]></Nonce>");
            sb.Append($"</xml>");

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public BindResult Bind(Dictionary <string, string> openIds, string batch, string userName, string password, string captcha)
        {
            var result = new BindResult
            {
                NeedCaptcha = false
            };

            var callback         = ProviderGateway.CallbackContentProvider.GetByBatchId(batch);
            var appAccountPublic = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPublic);

            if (!openIds.ContainsKey(appAccountPublic.AppId))
            {
                result.Result  = 2;
                result.Message = "用户公有OpenId无效";
                return(result);
            }
            AppAccountInfo appAccountPrivate = null;

            if (callback.TenantId != 0)
            {
                appAccountPrivate = ProviderGateway.AppAccountProvider.Get(callback.AppAccountPrivate);
                if (!openIds.ContainsKey(appAccountPrivate.AppId))
                {
                    result.Result  = 2;
                    result.Message = "用户私有OpenId无效";
                    return(result);
                }
            }
            var openIdPublic = openIds[appAccountPublic.AppId];

            var currentAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByOpenId(appAccountPublic.AppId, openIdPublic);

            if (currentAppUserAccount != null && currentAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 8;
                result.Message = "您已经绑定过了,无需重复绑定";
                return(result);
            }

            //验证发送时间
            if (RedisHelper.IsExist(RedisConstName.SendCheck + userName))
            {
                result.Result  = 6;
                result.Message = "绑定过于频繁";
                return(result);
            }

            // 校验邮箱是否存在
            var userId = Proxy.BeisenUserProxy.GetSecurityByUserName(userName);

            if (userId <= 0)
            {
                result.Result  = 5;
                result.Message = "未找到对应账户";
                return(result);
            }
            var tenantId = Proxy.BeisenUserProxy.GetTenantId(userId);

            var oldAppUserAccount = ProviderGateway.AppUserAccountProvider.GetByUserId(tenantId, userId, appAccountPublic.AppId);

            if (oldAppUserAccount != null && oldAppUserAccount.State == AppUserAccountState.Activated)
            {
                result.Result  = 7;
                result.Message = "帐号已绑定";
                return(result);
            }

            var newAppUserAccountMaster = new AppUserAccountInfo
            {
                AppId           = appAccountPublic.AppId,
                OpenId          = openIdPublic,
                TenantId        = tenantId,
                UserId          = userId,
                BeisenAccount   = userName,
                Type            = _type,
                State           = AppUserAccountState.Inactive,
                MasterAccountId = 0
            };
            var masterAccountId = ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppUserAccountMaster);

            //增加私有关联关系
            if ((appAccountPublic.Type == 11 || appAccountPublic.Type == 12) && callback.TenantId != 0 && masterAccountId != 0)
            {
                var newAppAccountUser = new AppUserAccountInfo
                {
                    AppId           = appAccountPrivate.AppId,
                    OpenId          = openIds[appAccountPrivate.AppId],
                    TenantId        = tenantId,
                    UserId          = userId,
                    BeisenAccount   = userName,
                    Type            = _type,
                    State           = AppUserAccountState.Inactive,
                    MasterAccountId = masterAccountId
                };
                ProviderGateway.AppUserAccountProvider.AddOrUpdate(tenantId, newAppAccountUser);
            }
            // 记录发邮件记录
            var bindBatch = new BindBatchInfo
            {
                TenantId         = tenantId,
                AppUserAccountId = masterAccountId,
                BeisenAccount    = userName,
                Type             = _type,
                State            = BindBatchState.UnUse
            };
            var bindBatchId = ProviderGateway.BindBatchProvider.Add(tenantId, bindBatch);

            // 发送激活邮件
            string activateCode = CryptographyHelper.AESEncrypt(tenantId + "_" + bindBatchId);
            string emailBody    = GetEmailBody(userName, AppConnectHostConfig.Cache[0] + HostConst.UserActivate + "?code=" + activateCode);
            var    emailBatch   = EmailProxy.SendEmail(0, "iTalent登录邮件验证", "", userName, emailBody);

            RedisHelper.SetRedis(RedisConstName.SendCheck + userName, DateTime.Now.Ticks.ToString(), 180);
            ProviderGateway.BindBatchProvider.UpdateBatchId(tenantId, bindBatchId, emailBatch);

            return(result);
        }
Ejemplo n.º 4
0
 public static string Encrypt(string raw)
 {
     return(CryptographyHelper.AESEncrypt(key, IV, raw));
 }