获取临时素材
获取临时图片,我们这里就不再进行json的序列化了,因为这个也不算是微信的技术范畴,我们就直接显示json文档出来就可以了
string url = string.Format("https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", obj.access_token,this.TextBox1.Text);
this.labelRes.Text = Tool.HttpGetMeterial(url);Code language: JavaScript (javascript)
下面是封装用来去资料文件
public static string HttpGetMeterial(String Url)
{
string sException = null;
string sRslt = null;
WebResponse oWebRps = null;
WebRequest oWebRqst = WebRequest.Create(Url);
oWebRqst.Timeout = 50000;
try
{
oWebRps = oWebRqst.GetResponse();
}
catch (WebException e)
{
sException = e.Message.ToString();
}
catch (Exception e)
{
sException = e.ToString();
}
finally
{
if (oWebRps != null)
{
System.Drawing.Image downImage = System.Drawing.Image.FromStream(oWebRps.GetResponseStream());
string dertory = string.Format(HttpContext.Current.Server.MapPath("~/")+@"{0}\", DateTime.Now.ToString("yyyy-MM-dd"));
string fileName = oWebRps.Headers["Content-disposition"];
fileName = fileName.Substring(fileName.IndexOf("\"")+1, fileName.LastIndexOf("\"")-fileName.IndexOf("\"")-1);
if (!System.IO.Directory.Exists(dertory))
{
System.IO.Directory.CreateDirectory(dertory);
}
sRslt = dertory + fileName;
downImage.Save(sRslt);
downImage.Dispose();
oWebRps.Close();
}
}
return sRslt;
}Code language: PHP (php)