Esempio n. 1
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);
        }
        /// <summary>
        /// 刷新公众号token
        /// </summary>
        private void RefeshToken(string appID)
        {
            if (Access_TokenInfoDic.ContainsKey(appID))
            {
                DateTime     now         = DateTime.Now;
                MWeixinParam weixinParam = null;
                // 如果已经超时
                if (Access_TokenInfoDic[appID].OutTime <= now)
                {
                    weixinParam = new MWeixinParam(Access_TokenInfoDic[appID].AppID, Access_TokenInfoDic[appID].AppSecret);
                    AccessTokenRequest request = new AccessTokenRequest(weixinParam);
                    // 重新获取token
                    var response = Client.Execute(request);
                    if (response.IsError)
                    {
                        throw new Exception(response.ErrorMessage);
                    }
                    // 修改授权
                    Access_TokenInfoDic[appID].OutTime      = now.AddSeconds(response.Expires_In);
                    Access_TokenInfoDic[appID].Access_Token = response.Access_Token;

                    // 更新
                    BUpdateAccess_Token updateToken = new BUpdateAccess_Token(Access_TokenInfoDic[appID].KeyID, SecurityUtility.EncryptDES(Access_TokenInfoDic[appID].Access_Token), string.Empty, Access_TokenInfoDic[appID].OutTime);
                    updateToken.Execute();


                    // 更新ticket
                    this.RefeshTicket(response.Access_Token);
                }
            }
        }