我的公共类库

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 = ;
//创建输入流
Stream dataStream = null;
try
{
dataStream = request.GetRequestStream();
}
catch (Exception)
{
return null;//连接服务器失败
} //发送请求
dataStream.Write(dataArray, , 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 = ; 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() != "")
{
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, , 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 = ; ICryptoTransform cTransform = rDel.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(content, , content.Length); return resultArray;
} #endregion }
}

C# - Lee 公共类库的更多相关文章

  1. ThinkPHP 3.2公共类库、应用类库ThinkPHP/Library讲解

    一.ThinkPHP的类库主要包括公共类库和应用类库,都是基于命名空间进行定义和扩展的.只要按照规范定义,都可以实现自动加载.        公共类库 公共类库通常是指ThinkPHP/Library ...

  2. Java笔记-添加自定义公共类库

    大型项目,为了方便团队开发,需要建立公共类库,提高类库的重用性和维护性步骤如下: --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/387 ...

  3. android studio发布公共类库到服务器maven仓库

    在上一篇中提到了怎么创建私有maven库,这篇主要结合android studio的使用,直接进入正题,看以下步骤 1.创建android项目 创建Project,然后加一个library的modul ...

  4. C#通用公共类库ZXNetStandardDepot.Common

    总结了一下写项目中遇到的各种方法,总结前辈们的经验,生成了该类库,引用net standard类库,支持net core/net framework. 使用方法 1.nuget 搜索 ZXNetSta ...

  5. ApacheCommons的Java公共类库(实现如Log这些功能)

    Apache Commons是Apache软件基金会的项目,曾隶属于Jakarta项目.Commons的目的是提供可重用的.开源的Java代码. 解释:http://baike.baidu.com/i ...

  6. EF中的MySql返回 DataTable公共类库

    public static class SqlHelper { /// <summary> /// EF SQL 语句返回 dataTable /// </summary> / ...

  7. Sangmado 公共基础类库

    Sangmado 涵盖了支撑 .NET/C# 项目开发的最基础的公共类库,为团队在不断的系统开发和演进过程中发现和积累的最公共的代码可复用单元. Sangmado 公共类库设计原则: 独立性:不与任何 ...

  8. 一个技术汪的开源梦 —— 基于 .Net Core 的公共组件之序列化

    一个技术汪的开源梦 —— 目录 想必大家在项目中都接触过 JSON 或者 XML 吧,为了将对象在网络上传输或者将其持久化必须将其序列化为一个字符串然后进行后续操作.常见的就是将其序列化成 JSON ...

  9. 一个技术汪的开源梦 —— 基于 .Net Core 的公共组件之目录结构

    一个技术汪的开源梦 —— 目录 这篇文章是开源公共组件的开篇那就先说说项目的 Github 目录结构和 .Net Core 的项目结构. 1. GitHub 目录结构和相关文件 - src 源码项目目 ...

随机推荐

  1. Android 转载一篇.9图片详解文章

    感谢作者,原文链接为 http://blog.csdn.net/ouyang_peng/article/details/9242889

  2. iOS viewDidAppear 和 viewWillAppear

    今天发现,如果用navigation push一个controller,那么从动画开始就调用viewwillappear,动画全部停止才会调用viewDidAppear,不知道是否正确,先做记录,带验 ...

  3. 改变服务器sshd 的22的端口

    [root@v01-svn-test-server ~]# vi /etc/ssh/sshd_config Port 22 Port 5001 #新增加5001端口给sshd,现在22,5001都是s ...

  4. iptables 开启3306端口

    [root@mysqld ~]# mysql -uroot -h 192.168.1.35 -p Enter password: ERROR 1130 (HY000): Host '192.168.1 ...

  5. margin和padding那点事及常见浏览器margin padding相关Bug

    用Margin还是用Padding 何时应当使用margin: 需要在border外侧添加空白时. 空白处不需要背景(色)时. 上下相连的两个盒子之间的空白,需要相互抵消时.如15px + 20px的 ...

  6. Eclipse快捷键及各种设置(转载)

    1.提示键配置一般默认情况下,Eclipse ,MyEclipse 的代码提示功能是比Microsoft Visual Studio的差很多的,主要是Eclipse ,MyEclipse本身有很多选项 ...

  7. hrbustoj 1429:凸多边形(计算几何,判断点是否在多边形内,二分法)

    凸多边形 Time Limit: 2000 MS    Memory Limit: 65536 K Total Submit: 130(24 users)   Total Accepted: 40(1 ...

  8. hdu 1159:Common Subsequence(动态规划)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. Java Hour 51 CheckStyle

    Plan List: 1 mysql 相关 2 java code style 安装体验 1 直接从eclipse install new software 安装,莫名奇妙失败,提示为缺少依赖项. 这 ...

  10. SQL DEVELOPER工具找不到database时的解决

    1.配置SQL DEVELOPER管理工具 这里省略Oracle数据库和PL/SQL Developer的安装步骤,注意在安装PL/SQL Developer软件时,不要安装在Program File ...