Exemplo n.º 1
0
        /// <summary>
        /// 获取口令(公众号)
        /// </summary>
        /// <param name="trans">事物</param>
        /// <param name="conn">连接</param>
        /// <param name="grant_Type">grant_Type</param>
        /// <returns></returns>
        public List <MAccess_Token> GetAccess_Token(IDbTransaction trans, IDbConnection conn, string grant_Type)
        {
            string          sqlText           = @"select KeyID,AppID,WeixinID,AppSecret,Access_Token,Grant_Type,AddTime,OutTime,ModifyTime,IsDelete  from Access_Token WHERE  Grant_Type=@Grant_Type and IsDelete = 0 ";
            MySqlParameters destionParameters = new MySqlParameters();

            destionParameters.Add(new MySqlParameter()
            {
                ParameterName = "@Grant_Type", MySqlDbType = MySqlDbType.VarChar, Value = grant_Type
            });

            List <MAccess_Token> access_TokenList = new List <MAccess_Token>();

            using (MySqlDataReader reader = Common.DBUtility.MySqlHelper.ExecuteReader(trans, conn, sqlText, destionParameters.ToArray()))
            {
                MAccess_Token access_Token = null;
                while (reader.Read())
                {
                    access_Token              = new MAccess_Token();
                    access_Token.KeyID        = reader["KeyID"] == DBNull.Value ? string.Empty : reader["KeyID"].ToString();
                    access_Token.AppID        = reader["AppID"] == DBNull.Value ? string.Empty : reader["AppID"].ToString();
                    access_Token.WeixinID     = reader["WeixinID"] == DBNull.Value ? string.Empty : reader["WeixinID"].ToString();
                    access_Token.AppSecret    = reader["AppSecret"] == DBNull.Value ? string.Empty : reader["AppSecret"].ToString();
                    access_Token.Access_Token = reader["Access_Token"] == DBNull.Value ? string.Empty : SecurityUtility.DecryptString(reader["Access_Token"].ToString());
                    access_Token.Grant_Type   = reader["Grant_Type"] == DBNull.Value ? string.Empty : reader["Grant_Type"].ToString();
                    access_Token.AddTime      = reader["AddTime"] == DBNull.Value ? new DateTime(1990, 1, 1) : Convert.ToDateTime(reader["AddTime"]);
                    access_Token.OutTime      = reader["OutTime"] == DBNull.Value ? new DateTime(1990, 1, 1) : Convert.ToDateTime(reader["OutTime"]);
                    access_TokenList.Add(access_Token);
                }
            }

            return(access_TokenList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 尝试连接VPN(指定VPN名称,用户名,密码)
        /// </summary>
        /// <param name="connVpnName">vpn名称</param>
        /// <param name="connUserName">连接的用户名称</param>
        /// <param name="connPassWord">连接的密码</param>
        /// <returns>连接成功true,连接失败false</returns>
        public bool TryConnectVPN(string connVpnName, string connUserName, string connPassWord)
        {
            bool     result    = false;
            DateTime startTime = DateTime.Now;
            string   linkInfo  = string.Empty;

            try
            {
                string args = string.Format("{0} {1} {2}", connVpnName, connUserName, SecurityUtility.DecryptString(connPassWord));

                ProcessStartInfo myProcess = new ProcessStartInfo(this.vpnProcess, args);

                myProcess.CreateNoWindow = true;

                myProcess.UseShellExecute        = false;
                myProcess.RedirectStandardOutput = true;
                var excuteResult = Process.Start(myProcess);
                linkInfo = excuteResult.StandardOutput.ReadToEnd();
                linkInfo = linkInfo.Replace("\n", string.Empty);
                if (linkInfo.Contains("已连接"))
                {
                    result = true;
                }
                else
                {
                    MessagePipe.ExcuteWriteMessageEvent("登陆失败,账号:" + connUserName + "密码:" + SecurityUtility.EncryptDES(connPassWord) + "VPN服务器:" + this.vpnIP, Color.Green, true);
                }

                MessagePipe.ExcuteWriteMessageEvent(connVpnName + "登陆验证结果:" + linkInfo, Color.Green, false);
            }
            catch (Exception ex)
            {
                string msg = "登陆异常,账号:" + connUserName + "密码:" + SecurityUtility.EncryptDES(connPassWord) + "VPN服务器:" + this.vpnIP;
                LogManager.Log.WriteException(new AppException(msg, ex, ExceptionLevel.Info));
            }
            finally
            {
                ////记录交互日志
                string request = "VPN通道名称:" + connVpnName + ";VPN账号:" + connUserName;
                RecordLog.RecordInteractionLog(connUserName, "通过用账号和密码登陆", request, linkInfo, DateTime.Now.Subtract(startTime), this.vpnIP);
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取口令(用户的)
        /// </summary>
        /// <param name="trans">事物</param>
        /// <param name="conn">连接</param>
        /// <param name="appid">appid</param>
        /// <param name="appSecret">appSecret</param>
        /// <param name="openID">OpendID</param>
        /// <param name="scope">Scope</param>
        /// <returns>用户令牌</returns>
        public MAccess_Token GetAccess_Token(IDbTransaction trans, IDbConnection conn, string appid, string appSecret, string openID, string scope)
        {
            string          sqlText           = @"select KeyID,AppID,AppSecret,WeixinID,Access_Token, RefreshToken,Grant_Type,OpenID,Scope,UnionID,AddTime,OutTime,ModifyTime,IsDelete from Access_Token 
WHERE AppID = @AppID and  AppSecret= @AppSecret and OpenID=@OpenID and Scope=@Scope and IsDelete = 0 limit 1";
            MySqlParameters destionParameters = new MySqlParameters();

            destionParameters.Add(new MySqlParameter()
            {
                ParameterName = "@AppID", MySqlDbType = MySqlDbType.VarChar, Value = appid
            });
            destionParameters.Add(new MySqlParameter()
            {
                ParameterName = "@AppSecret", MySqlDbType = MySqlDbType.VarChar, Value = appSecret
            });
            destionParameters.Add(new MySqlParameter()
            {
                ParameterName = "@OpenID", MySqlDbType = MySqlDbType.VarChar, Value = openID
            });
            destionParameters.Add(new MySqlParameter()
            {
                ParameterName = "@Scope", MySqlDbType = MySqlDbType.VarChar, Value = scope
            });

            MAccess_Token access_Token = null;

            using (MySqlDataReader reader = Common.DBUtility.MySqlHelper.ExecuteReader(trans, conn, sqlText, destionParameters.ToArray()))
            {
                while (reader.Read())
                {
                    access_Token              = new MAccess_Token();
                    access_Token.KeyID        = reader["KeyID"] == DBNull.Value ? string.Empty : reader["KeyID"].ToString();
                    access_Token.AppID        = reader["AppID"] == DBNull.Value ? string.Empty : reader["AppID"].ToString();
                    access_Token.AppSecret    = reader["AppSecret"] == DBNull.Value ? string.Empty : reader["AppSecret"].ToString();
                    access_Token.WeixinID     = reader["WeixinID"] == DBNull.Value ? string.Empty : reader["WeixinID"].ToString();
                    access_Token.Access_Token = reader["Access_Token"] == DBNull.Value ? string.Empty : SecurityUtility.DecryptString(reader["Access_Token"].ToString());
                    access_Token.RefreshToken = reader["RefreshToken"] == DBNull.Value ? string.Empty : SecurityUtility.DecryptString(reader["RefreshToken"].ToString());
                    access_Token.Grant_Type   = reader["Grant_Type"] == DBNull.Value ? string.Empty : reader["Grant_Type"].ToString();
                    access_Token.OpenID       = reader["OpenID"] == DBNull.Value ? string.Empty : reader["OpenID"].ToString();
                    access_Token.Scope        = reader["Scope"] == DBNull.Value ? string.Empty : reader["Scope"].ToString();
                    access_Token.UnionID      = reader["UnionID"] == DBNull.Value ? string.Empty : reader["UnionID"].ToString();
                    access_Token.AddTime      = reader["AddTime"] == DBNull.Value ? new DateTime(1990, 1, 1) : Convert.ToDateTime(reader["AddTime"]);
                    access_Token.OutTime      = reader["OutTime"] == DBNull.Value ? new DateTime(1990, 1, 1) : Convert.ToDateTime(reader["OutTime"]);
                }
            }

            return(access_Token);
        }