198 lines
9.1 KiB
C#
198 lines
9.1 KiB
C#
using Api.Framework.Tools;
|
||
using System;
|
||
using System.Drawing;
|
||
using System.IO;
|
||
using Weixin.TBCirclePromotion.Properties;
|
||
|
||
namespace Weixin.TBCirclePromotion
|
||
{
|
||
public static class Tools
|
||
{
|
||
/// <summary>
|
||
/// 背景图片地址
|
||
/// </summary>
|
||
public static string PosterPathImgUrl { get; private set; }
|
||
public static string PosterPathImgUrl2 { get; private set; }
|
||
|
||
static Tools()
|
||
{
|
||
PosterPathImgUrl = Util.MapFile("优惠券底图.jpg", "File\\Image");
|
||
PosterPathImgUrl2 = Util.MapFile("优惠券背景图.jpg", "File\\Image");
|
||
}
|
||
|
||
#region 获取底图的地址
|
||
/// <summary>
|
||
/// 获取底图的地址
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
/// <returns></returns>
|
||
public static void GetBaseIco()
|
||
{
|
||
if (!File.Exists(PosterPathImgUrl))
|
||
{
|
||
Bitmap bit = Resources.优惠券底图;
|
||
bit.Save(PosterPathImgUrl);
|
||
}
|
||
|
||
if (!File.Exists(PosterPathImgUrl2))
|
||
{
|
||
Bitmap bit = Resources.优惠券背景图;
|
||
bit.Save(PosterPathImgUrl2);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region h5Top xxx
|
||
|
||
//private static string _cookies = string.Empty;
|
||
|
||
//private static string Cookies
|
||
//{
|
||
// get
|
||
// {
|
||
// if (string.IsNullOrEmpty(_cookies))
|
||
// {
|
||
// HttpHelper http = new HttpHelper();
|
||
// string cookies = http.GetHtml(new HttpItem() { URL = "http://api.m.taobao.com/h5/mtop.alimama.union.hsf.coupon.get/1.0/?v=1.0&api=mtop.alimama.union.hsf.coupon.get&appKey=12574478&t=1521082116428&callback=mtopjsonp1&type=jsonp&sign=e102e09c3da2505790412f4b5904cfec&data=%7B%22e%22%3A%22kKwRS8jKFeIGQASttHIRqX4ccS%252BmEB0fPkvI%252B9vDGidk3qypIGt1zv02HjWWzK8QrVVJXxMdEXoJP%252FpVy45HN79fwBwwUiqlbZt%252F%252F9VQxkYKu2xm%252BXzUVW7PVn13QcLNcISolD8QJ4rvZt%252BicRrQwg%253D%253D%22%2C%22pid%22%3A%22mm_96747532_17602904_63786428%22%7D", Timeout = 5000, ReadWriteTimeout = 5000 }).Cookie;
|
||
// _cookies = HttpHelper.GetSmallCookie(cookies);
|
||
// }
|
||
// return _cookies;
|
||
// }
|
||
// set { _cookies = value; }
|
||
//}
|
||
|
||
//const string appKey = "12574478";
|
||
|
||
//public static Dictionary<string, object> GetH5Result(string api, object data, string version = "6.0")
|
||
//{
|
||
// bool next = false;
|
||
// int number = 0;
|
||
//Next:
|
||
// string time = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString();
|
||
// string mh5Tk = HttpExtend.GetCookiesValue("_m_h5_tk", Cookies);
|
||
// mh5Tk = string.IsNullOrEmpty(mh5Tk) ? "f64aa152f943661f750e6212ebc98804_1481170439770" : mh5Tk;
|
||
// string json = (data.GetType() == typeof(string)) ? data.ToString() : HttpHelper.ObjectToJson(data).Replace("\\u0026", "&").Replace("_params", "param");
|
||
// string temp_ = mh5Tk + "&" + time + "&" + appKey + "&" + json;
|
||
// string sign = HttpExtend.GetMD5String(temp_);
|
||
// string send = HttpExtend.UrlEncode(json);
|
||
// string temp = string.Format("http://h5api.m.taobao.com/h5/{5}/{4}/?jsv=2.4.11&v={4}&api={5}&appKey={0}&t={1}&callback=mtopjsonp1&type=jsonp&sign={2}&data={3}", appKey, time, sign, send, version, api);
|
||
// var html = M_GET_HTML(temp).Trim();
|
||
// if (html.Contains("令牌过期") || html.Contains("令牌为空") || html.Contains("失效"))
|
||
// {
|
||
// if (!next && number <= 10)
|
||
// {
|
||
// number++;
|
||
// next = true;
|
||
// goto Next;
|
||
// }
|
||
// }
|
||
// if (html.Contains("挤爆") && number <= 10)
|
||
// {
|
||
// Dictionary<string, object> _json = HttpExtend.JsonToDictionary(html);
|
||
|
||
// string _url = (_json["data"] as Dictionary<string, object>)["url"].ToString();
|
||
// next = false;
|
||
// number++;
|
||
// goto Next;//??
|
||
// }
|
||
|
||
// var reg = Regex.Match(html, @"^mtopjsonp1\((.*?)\)$", RegexOptions.IgnoreCase);
|
||
// if (reg.Success)
|
||
// {
|
||
// var dic = HttpExtend.JsonToDictionary(reg.Groups[1].Value);
|
||
// if (dic.ContainsKey("data") && html.Contains("SUCCESS::调用成功"))
|
||
// return dic["data"] as Dictionary<string, object>;
|
||
// throw new Exception(reg.Groups[1].Value);
|
||
// }
|
||
// throw new Exception(html);
|
||
//}
|
||
|
||
//internal const string _key = "<RSAKeyValue><Modulus>wmUZgme6iOPOaMTZtPu5DKQ8Dph9fSgy6abFyQv25MD8xOMPBBo0wsLUOVt8r9sk+li11mIg1fs1HPJ75UmIle+w9xhIx/nsXWejuQhXlQV0VyJtzI+id8G+FcyYaog91MfPndJoO3m30fSjE/0KDLDmv1EeQcP24RAzeA29p7c=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
|
||
//internal const int _appid = 10004;
|
||
//internal const string _host = "https://cps.api.52cmg.cn";
|
||
|
||
//private static string M_GET_HTML(string tempUrl)
|
||
//{
|
||
// try
|
||
// {
|
||
// HttpItem item = new HttpItem()
|
||
// {
|
||
// URL = tempUrl,//URL 必需项
|
||
// Method = "get",//URL 可选项 默认为Get
|
||
// IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
|
||
// Cookie = Cookies + ";random=" + new Random().Next(),//字符串Cookie 可选项
|
||
// Referer = "http://m.taobao.com",//来源URL 可选项
|
||
// Timeout = 5000,//连接超时时间 可选项默认为100000
|
||
// ReadWriteTimeout = 5000,//写入Post数据超时时间 可选项默认为30000
|
||
// UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
|
||
// ContentType = "text/html",//返回类型 可选项有默认值
|
||
// Allowautoredirect = false,//是否根据301跳转 可选项
|
||
// };
|
||
// HttpHelper http = new HttpHelper();
|
||
// int i = 0;
|
||
// Next:
|
||
// HttpResult result = http.GetHtml(item);
|
||
// string html = result.Html;
|
||
// if (Regex.IsMatch(html, "亲,小二正忙,滑动一下马上回来|挤爆|rgv587_flag"))
|
||
// {
|
||
// var r = item.SetProxyIP(http, new AuthEndpoint()
|
||
// {
|
||
// Host = _host + "/api/webtool.asmx/send_data",
|
||
// Appid = _appid,
|
||
// Enckey = _key,
|
||
// Method = "find_proxy"
|
||
// });
|
||
// i++;
|
||
// if (r && i < 3) goto Next;
|
||
// }
|
||
// if (!string.IsNullOrEmpty(result.Cookie))
|
||
// {
|
||
// Cookies = HttpExtend.UpdateCookies(Cookies, result.Cookie);
|
||
// }
|
||
// return html;
|
||
// }
|
||
// catch (Exception)
|
||
// {
|
||
// return string.Empty;
|
||
// }
|
||
//}
|
||
#endregion
|
||
|
||
#region 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
|
||
/// <summary>
|
||
/// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
|
||
/// </summary>
|
||
/// <param name="path"></param>
|
||
/// <returns></returns>
|
||
public static Bitmap ReadImageFile(string path)
|
||
{
|
||
FileStream fs = File.OpenRead(path); //OpenRead
|
||
int filelength = 0;
|
||
filelength = (int)fs.Length; //获得文件长度
|
||
Byte[] image = new Byte[filelength]; //建立一个字节数组
|
||
fs.Read(image, 0, filelength); //按字节流读取
|
||
Image result = Image.FromStream(fs);
|
||
fs.Close();
|
||
Bitmap bit = new Bitmap(result);
|
||
return bit;
|
||
}
|
||
#endregion
|
||
|
||
public static Bitmap getnew(Image bit, int width, int height)//beishu参数为放大的倍数。放大缩小都可以,0.8即为缩小至原来的0.8倍
|
||
{
|
||
Bitmap destBitmap = new Bitmap(width, height);
|
||
using (Graphics g = Graphics.FromImage(destBitmap))
|
||
{
|
||
g.Clear(Color.Transparent);
|
||
//设置画布的描绘质量
|
||
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||
g.DrawImage(bit, new Rectangle(0, 0, destBitmap.Width, destBitmap.Height), 0, 0, bit.Width, bit.Height, GraphicsUnit.Pixel);
|
||
}
|
||
return destBitmap;
|
||
}
|
||
|
||
}
|
||
}
|