C# - Lee 公共类库_George_Fal的博客-程序员秘密

技术标签: c#  xhtml  

我的公共类库

using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using CY.CommonLibrary.Common;

namespace Lee
{
    public class Common
    {
        public static string ServerIPAndPort = System.Configuration.ConfigurationManager.AppSettings["ServerIPAndPort"];

        public static string Md5Key = System.Configuration.ConfigurationManager.AppSettings["Md5Key"];

        public static string Test_Swich = System.Configuration.ConfigurationManager.AppSettings["Test_Swich"]; //只要不为空,都为测试模式

        /// <summary>
        /// 是否处于测试模式.只要不为空,都为测试模式
        /// </summary>
        /// <returns>布尔值</returns>
        public static bool Is_测试模式()
        #region
        {
            if (Test_Swich != "")
            {
                return true;
            }
            return false;
        }

        #endregion

        /// <summary>
        /// send_发送POST请求
        /// </summary>
        /// <param name="vServerPage"></param>
        /// <param name="vPostData"></param>
        /// <returns></returns>
        public static string send_发送POST请求(string vServerPage, string vPostData)
        #region
        {
            byte[] dataArray = Encoding.UTF8.GetBytes(vPostData);
            //创建请求
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(vServerPage);
            request.Method = "POST";
            request.ContentLength = dataArray.Length;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Timeout = 5000;
            //创建输入流
            Stream dataStream = null;
            try
            {
                dataStream = request.GetRequestStream();
            }
            catch (Exception)
            {
                return null;//连接服务器失败
            }

            //发送请求
            dataStream.Write(dataArray, 0, dataArray.Length);
            dataStream.Close();
            //读取返回消息
            string res = string.Empty;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
                reader.Close();
            }
            catch (Exception ex)
            {
                return null;//连接服务器失败
            }
            return res;
        }

        #endregion

        /// <summary>
        /// send_发送Get请求
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string send_发送GET请求(string url)
        #region
        {
            string str = "";

            HttpWebRequest hwr = WebRequest.Create(url) as HttpWebRequest;

            hwr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            hwr.Method = "GET";
            hwr.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:34.0) Gecko/20100101 Firefox/34.0";
            hwr.ContentType = "application/x-www-form-urlencoded";
            hwr.Headers["Accept-Language"] = "zh-cn";
            hwr.Timeout = 3000;

            try
            {
                HttpWebResponse _rep = hwr.GetResponse() as HttpWebResponse;
                Stream _stream = _rep.GetResponseStream();
                StreamReader read = new StreamReader(_stream, Encoding.UTF8);

                str = read.ReadToEnd();
                _rep.Close();
            }
            catch (Exception ex)
            {
                log.WriteLog("商学院数据获取超时? :" + ex.Message + "请求地址为:" + url);
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>数据超时..</p></div>");
                HttpContext.Current.Response.End();
            }
            return str;
        }

        #endregion

        /// <summary>
        /// 发送一张笑脸
        /// </summary>
        public static void send_smiling_face(string str)
        #region
        {
            HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:)</h1><p>" + str + "</p></div>");
        }

        #endregion

        /// <summary>
        /// 发送一张哭脸
        /// </summary>
        /// <param name="str"></param>
        public static void send_unhappy_face(string str)
        #region
        {
            HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top,  #9ee675,  #78cb4c);/* for IE */filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9ee675',endColorstr='#78cb4c'); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;}  *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>" + str + "</p></div>");
        }

        #endregion

        /// <summary>
        /// 维护中
        /// </summary>
        public static void Send_repair()
        #region
        {
            if (HttpContext.Current.Session["Current_Shop_Id"].ToNotNullString() != "6634")
            {
                send_smiling_face("维修中...");
            }
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "')</script>");
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert_back(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "');history.back();</script>");
        }

        #endregion

        /// <summary>
        /// 网页弹出框
        /// </summary>
        /// <param name="obj"></param>
        public static void alert_href(object obj, string url)
        #region
        {
            HttpContext.Current.Response.Write("<script language=javascript>alert('" + obj.ToString() + "');window.location.href='" + url + "';</script>");
        }

        #endregion

        /// <summary>
        /// 在控制台打印出数据
        /// </summary>
        /// <param name="obj"></param>
        public static void log_Console(object obj)
        #region
        {
            HttpContext.Current.Response.Write("<script>console.log(\"" + obj + "\")</script>");
        }

        #endregion

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="obj"></param>
        public static void print(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString());
        }

        #endregion

        /// <summary>
        /// 输出,不换行,使用完直接结束
        /// </summary>
        /// <param name="obj"></param>
        public static void echo(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString());
        }

        #endregion

        /// <summary>
        /// 打印,带换行
        /// </summary>
        /// <param name="obj"></param>
        public static void println(object obj)
        #region
        {
            HttpContext.Current.Response.Write(obj.ToString() + "<br />");
        }

        #endregion

        /// <summary>
        /// 结束网页输出
        /// </summary>
        public static void End()
        #region
        {
            HttpContext.Current.Response.End();
        }

        #endregion

        /// <summary>
        /// 清除网页输出
        /// </summary>
        public static void Clear()
        #region
        {
            HttpContext.Current.Response.Clear();
        }

        #endregion

        /// <summary>
        /// ASE_128_ECB_无填充_64Base_加密函数
        /// </summary>
        /// <param name="content">要加密的内容</param>
        /// <param name="key">一定要16位的密钥</param>
        /// <returns>加密的字符串(字节)</returns>
        public static byte[] Func_AES128加密(string content, string key)
        #region
        {
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(content);

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            //返回字节数组,可用Convert.FromBase64String()转换为字节
            //return Convert.ToBase64String(resultArray, 0, resultArray.Length);

            return resultArray;
        }
        #endregion


        /// <summary>
        ///  ASE_128_ECB_无填充_64Base_解密函数
        /// </summary>
        /// <param name="content">密串(字节)</param>
        /// <param name="keyArray">密钥(字节)</param>
        /// <returns>解密后的字符串</returns>
        public static byte[] Func_AES128解密(byte[] content, byte[] keyArray)
        #region
        {
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.None;
            rDel.BlockSize = 128;

            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(content, 0, content.Length);

            return resultArray;
        }

        #endregion

    }
}

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_33672109/article/details/86327022

智能推荐

数据结构与算法(Python版)—栈的应用—括号匹配_LCHQA的博客-程序员秘密

数据结构与算法(Python版)栈的应用1. 简单括号匹配每个开括号都要恰好对应一个闭括号,对括号是否正确匹配的识别,是很多语言编译器的基础算法。from pythonds.basic.stack import Stackdef parChecker(parStr): s = Stack() for i in range(len(parStr)): if parStr[i] == '(': s.push(parStr[i])

excel中的函数公式使用方法_=sum()公式_小何何何的博客-程序员秘密

excel公式1. sum 求和语法:=sum(数值1,数值2) 或者 =sum(数值1:数值x)。括号中间是逗号表示这2个值相加。如果是冒号则是这一个块区域所有值相加,如下A1:A5就表示1+2+3+4+5。图片演示:2. average 求平均数语法:=average(数据区域) ,平均数表示一组数据总和的量数,部分操作函数已经帮我做了,我们只用选中数据区域就可以了!图片演示:公式分析:A1:A5表示1、2、3、4、5相加总和的量数。如果只需要2个值的平均数,将冒号换为逗号就可以。

MySQL的多表设计和关联查询(数据库设计范式, 外键使用, 关联查询之内外交叉)_月下赶路人的博客-程序员秘密

文章目录多表设计-关联查询为什么需要多表设计?数据库设计范式第一范式(1NF)第二范式(2NF)第三范式(3NF)数据库实例外键数据库实例注意关联查询概述分类内连接(inner join)外连接交叉连接多表设计-关联查询为什么需要多表设计?多表设计的目的就是为了消除冗余的数据,将一张表拆分成为多张表,或者将多张表中的共同数据提取到一张表中.举个例子,有如下两张表编号姓名民族国籍1张三汉族中国2李四汉族中国编号省份国籍1陕西中

linux禁用触控板驱动程序,linux – X11 EvDev触摸屏驱动程序:禁用长按在桌面上单击鼠标右键..._34寸乌克丽丽的博客-程序员秘密

我正在建立一个自助服务终端系统,可以在启动时自动加载全屏网页.标准的东西.问题是连接Acer触摸屏,它与evdev驱动程序工作正常……但它的工作原理有点太好了.如果用户按下并按住屏幕,则会生成右键单击并显示上下文菜单.这会导致界面出现一些问题,我需要禁用此功能,但我还没有找到办法.X11配置文件不是我有很多经验的东西.有没有人有摆脱这个功能的经验?是否可以将触摸屏映射到通用鼠标驱动程序?该系统是:...

python提取包含特定字符串的行_python 提取特定字符所在的行,并构建字典_weixin_39981400的博客-程序员秘密

import reimport anydbmtestfile=open(r"test.txt")teststr=testfile.read()teststr+="\n>"reg=re.compile(r"^\s*(>.+?)$(.+?)(?=(^\s*>))",re.M+re.S)matchs=reg.finditer(teststr)testdb=anydbm.open(r"test.dict"...

matlab里step怎么用,matlab中step意思及如何应用?_刘照庆的博客-程序员秘密

step:动态系统的阶跃响应绘图。具体描述:1.step:计算一个动态系统的阶跃响应。在状态空间的情况下,假定初始状态为零。当它没有输出参数时,调用这个函数在屏幕上的画出阶跃响应。2.stepsys:画出任意一个动态系统模型sys的阶跃响应。这个模型可以是连续的或离散的,和单输入单输出或多输入多输出。多端输入系统的阶跃响应对于每一个输入方式来说都是阶跃响应的集合。模拟持续的时间根据系统的极点和零点...

随便推点

无线通信中FEC 编码原理及评价(4)_WIZnet的博客-程序员秘密

大家好,前面我们给大家介绍了无线通信中FEC编码原理(1)、(2)和(3),今天继续献上最后一篇,FEC编码原理及评价(4),关于无线通信FEC种类的评价,希望对大家有所帮助~FEC编码原理及评价(3)请参考:http://blog.csdn.net/wiznet2012/article/details/7492146  2.无线通信中的FECFEC编码在无线通信中有很多应用。

5. Go语言基础之变量和常量_Just_do_do_IT的博客-程序员秘密

变量和常量是编程中必不可少的部分。5.1 标识符与关键字5.1.1 标识符在编程语言中标识符就是程序员定义的具有特殊意义的词,比如变量名、常量名、函数名等等。 Go语言中标识符由字母数字和__(下划线)组成,并且只能以字母和_开头。 举几个例子:abc、 _、 _123、 a123。5.1.2 关键字关键字是指编程语言中预先定义好的具有特殊含义的标识符。 关键字和保留字都不建议用作变量名。Go语言中有25个关键字:break default func .

深度学习论文: LEDnet: A lightweight encoder-decoder network for real-time semantic segmentation及其PyTorch实现_bilateral attention decoder: a lightweight decoder_mingo_敏的博客-程序员秘密

深度学习论文: LEDnet: A lightweight encoder-decoder network for real-time semantic segmentation及其PyTorch实现LEDnet: A lightweight encoder-decoder network for real-time semantic segmentationPDF:https://arxiv.org/pdf/1905.02423.pdfPyTorch: https://github.com/shan

html5新增Api_qq_38408390的博客-程序员秘密

html5新增Api1 网络状态我们可以通过window.navigator.onLine来检测,用户当前的网络状况,返回一个布尔值, 但是不同浏览器会存在差异所以HTML5 给我们提供了2个事件 online 和 offlineonline用户网络连接时被调用offline用户网络断开时被调用他们监听的对象都是window2 全屏HTML5规范允许用户自定义网页上任一元素全屏显示。1、Node.requestFullScreen() 开启全屏显示2、Node.cancelFullScr

文件上传下载(SpringBoot)- 常用功能_六月船歌zZ的博客-程序员秘密

配置 import org.springframework.boot.web.servlet.MultipartConfigFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import javax...

推荐文章

热门文章

相关标签