/// <SUMMARY>
/// 下载保存多媒体文件,返回多媒体保存路径
/// </SUMMARY>
/// <PARAM name="ACCESS_TOKEN"></PARAM>
/// <PARAM name="MEDIA_ID"></PARAM>
/// <RETURNS></RETURNS>
public string GetMultimedia(string ACCESS_TOKEN, string MEDIA_ID)
{
string file = string.Empty;
string content = string.Empty;
string strpath = string.Empty;
string savepath = string.Empty;
string stUrl = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + ACCESS_TOKEN + "&media_id=" + MEDIA_ID;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(stUrl);
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
strpath = myResponse.ResponseUri.ToString();
WriteLog("接收类别://" + myResponse.ContentType);
WebClient mywebclient = new WebClient();
savepath = Server.MapPath("image") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg";
WriteLog("路径://" + savepath);
try
{
mywebclient.DownloadFile(strpath, savepath);
file = savepath;
}
catch (Exception ex)
{
savepath = ex.ToString();
}
}
return file;
}
class wxmessage
{
public string FromUserName { get; set; }
public string ToUserName { get; set; }
public string MsgType { get; set; }
public string EventName { get; set; }
public string Content { get; set; }
public string Recognition { get; set; }
public string MediaId { get; set; }
public string EventKey { get; set; }
}
private wxmessage GetWxMessage()
{
wxmessage wx = new wxmessage();
StreamReader str = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
XmlDocument xml = new XmlDocument();
xml.Load(str);
wx.ToUserName = xml.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
wx.FromUserName = xml.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
wx.MsgType = xml.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
if (wx.MsgType.Trim() == "text")
{
wx.Content = xml.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
}
if (wx.MsgType.Trim() == "event")
{
wx.EventName = xml.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
wx.EventKey = xml.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText;
}
if (wx.MsgType.Trim() == "voice")
{
wx.Recognition = xml.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;
}
if (wx.MsgType.Trim() == "image")
{
wx.MediaId = xml.SelectSingleNode("xml").SelectSingleNode("MediaId").InnerText;
}
return wx;
}
/// <SUMMARY>
/// 上传多媒体文件,返回 MediaId
/// </SUMMARY>
/// <PARAM name="ACCESS_TOKEN"></PARAM>
/// <PARAM name="Type"></PARAM>
/// <RETURNS></RETURNS>
public string UploadMultimedia(string ACCESS_TOKEN, string Type)
{
string result = "";
string wxurl = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=" + ACCESS_TOKEN + "&type=" + Type;
string filepath = Server.MapPath("image") + "\\hemeng80.jpg";(本地服务器的地址)
WriteLog("上传路径:" + filepath);
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultCredentials;
try
{
byte[] responseArray = myWebClient.UploadFile(wxurl, "POST", filepath);
result = System.Text.Encoding.Default.GetString(responseArray, 0, responseArray.Length);
WriteLog("上传result:" + result);
UploadMM _mode = JsonHelper.ParseFromJson<UPLOADMM>(result);
result = _mode.media_id;
}
catch (Exception ex)
{
result = "Error:" + ex.Message;
}
WriteLog("上传MediaId:" + result);
return result;
}
protected string sendPicTextMessage(Msg _mode, string MediaId)
{
string res = string.Format(@"<xml>
<ToUserName><![CDATA[{0}]]></ToUserName>
<FromUserName><![CDATA[{1}]]></FromUserName>
<CreateTime>{2}</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[{3}]]></MediaId>
</Image>
</xml> ",
_mode.FromUserName, _mode.ToUserName, DateTime.Now, MediaId);
return res;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有