using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using LitJson;
using System.Drawing;
using System.Drawing.Imaging;namespace WetChat
{
public class Chat
{
public string Path; public string Width; public string Savepath; public string Codes;
public Chat(string savepath,string codes)
{
this.Path = "pages/index/index?codes="+ codes;
this.Savepath = savepath+"qr_"+codes+".png";
this.Codes = codes;
}
/// <summary>
/// 获取acesstoken
/// </summary>
/// <returns></returns>
public string GetAccess_Token()
{
string urls = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=";
HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(urls); //请求api
HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
string respText = "";
using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.Default);
respText = reader.ReadToEnd();
resStream.Close();
}
JavaScriptSerializer Jss = new JavaScriptSerializer();
Dictionary<string, object> respDic = (Dictionary<string, object>)Jss.DeserializeObject(respText);
//通过键access_token获取值
return respDic["access_token"].ToString();
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="width"></param>
/// <param name="savepath"></param>
public void GetWxCode()
{
string url = "https://img.zhankr.net/34rjjgqgyk3176930);
byte[] byData = new Byte[mstream.Length];
mstream.Position = 0;
mstream.Read(byData, 0, byData.Length); mstream.Close();
return byData;
}
/// <summary>
/// 第一步:将文件流转换为image
/// </summary>
/// <param name="streamByte"></param>
/// <returns></returns>
public System.Drawing.Image ReturnPhoto(byte[] streamByte)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
return img;
} }
}
普通二维码有下面的微信的logo 所以截取
分了三部:
第一:将文件流转换为image
第二:将image截取
第三:将image转换为文件流
生成100个编码总共用时40s(着实有点多,转换哪里太浪费了)