/// <summary> /// 回复多媒体文件 /// 2014/3/14 ygh /// </summary> /// <param name="wec_request"></param> /// <param name="toUserName"></param> /// <param name="fromUserName"></param> /// <param name="Response"></param> public void responseMediaFile(WEC_REQUEST wec_request, string toUserName, string fromUserName, HttpResponse Response, string type) { WEC_REQUEST_MEDIA conf = new WEC_REQUEST_MEDIA(); conf.TID = wec_request.TID; conf.OrderBy("ADDTIME desc"); WEC_REQUEST_MEDIA media = BLLTable <WEC_REQUEST_MEDIA> .GetRowData(new WEC_REQUEST_MEDIA(), conf); if (media == null) { return; } string mediaid = media.MEIDAID; DateTime addtime = media.ADDTIME; if (addtime.AddDays(3) < DateTime.Now) { //当时间超过3天 微信服务器自动删除用户上传的多媒体文件,所以3天后 用户再次访问的时候,我们需要再次上传 updateMedia(media, conf, type); } string response_content = "<xml>" + "<ToUserName><![CDATA[" + toUserName + "]]></ToUserName>" + "<FromUserName><![CDATA[" + fromUserName + "]]></FromUserName>" + "<CreateTime>" + DateTime.Now.Millisecond + "</CreateTime>" + "<MsgType><![CDATA[" + type + "]]></MsgType>" + "<Image>" + "<MediaId><![CDATA[" + mediaid + "]]></MediaId>" + "</Image>" + "</xml>"; Response.Write(response_content); }
/// <summary> /// 更新微信服务器上的多媒体资源文件 /// ygh 2014/3/17 /// </summary> /// <param name="media"></param> /// <param name="conf"></param> /// <param name="type"></param> public void updateMedia(WEC_REQUEST_MEDIA media, WEC_REQUEST_MEDIA conf, string type) { string filepath = media.FILENAME; string content = HttpUtil.uploadFile(filepath, HttpUtil.getAccessToken(this.APPID, this.APPSECRET), type); StreamWriter sw = new StreamWriter(@"c:\4.txt"); sw.Write("content:" + content); JavaScriptSerializer a = new JavaScriptSerializer(); Dictionary <string, object> o = (Dictionary <string, object>)a.DeserializeObject(content); string media_id = (string)o["media_id"]; WEC_REQUEST_MEDIA update = new WEC_REQUEST_MEDIA(); update.MEIDAID = media_id; BLLTable <WEC_REQUEST_MEDIA> .Update(update, conf); }
protected void btnOK_Click(object sender, EventArgs e) { try { WEC_REQUEST valObj = new WEC_REQUEST(); if (txtTID.Value != "") valObj.TID = Convert.ToDecimal(txtTID.Value); //��ӵ���� if (valObj.TID == 0) { WEC_REQUEST cond = new WEC_REQUEST(); cond.KEYWORD = Convert.ToString(txtKEYWORD.Value); cond.AID = Convert.ToInt32(userBase2.Curraid); if (BLLTable<WEC_REQUEST>.Count(cond) > 0) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "alert('���������ظ��ؼ���')", true); return; } } if(txtAID.Value !="" ) valObj.AID = Convert.ToDecimal(txtAID.Value); if(txtKEYWORD.Value !="" ) valObj.KEYWORD = Convert.ToString(txtKEYWORD.Value); if(txtMATCH_TYPE.Value !="" ) valObj.MATCH_TYPE = Convert.ToInt32(txtMATCH_TYPE.Value); if (txtKIND.Value.Equals("5")) { valObj.MEMO = hidPICURL.Value; ; } else { valObj.MEMO = Convert.ToString(txtMEMO.Value); } if(txtKIND.Value !="" ) valObj.KIND = Convert.ToInt32(txtKIND.Value); if(txtSTATUS.Value !="" ) valObj.STATUS = Convert.ToInt32(txtSTATUS.Value); if(txtADDTIME.Value !="" ) valObj.ADDTIME = Convert.ToDateTime(txtADDTIME.Value); if (valObj.TID >0) { //valObj.TID = Convert.ToDecimal(keyid); count = BLLTable<WEC_REQUEST>.Update(valObj, WEC_REQUEST.Attribute.TID); } else { count = BLLTable<WEC_REQUEST>.Insert(valObj, WEC_REQUEST.Attribute.TID); keyid = valObj.TID.ToString(); } //ͼƬ�ظ� if (kind.Equals("5")) { string path=valObj.MEMO; path = path.Substring(path.LastIndexOf('/')+1); string filepath=Request.PhysicalApplicationPath+path; filepath = filepath.Replace('\\', '/'); string content = HttpUtil.uploadFile(filepath, HttpUtil.getAccessToken("wx69c300b3e390be5b", "3c06a3f6eb8a562b278583dff8b9da1c"), "image"); JavaScriptSerializer a = new JavaScriptSerializer(); Dictionary<string, object> o = (Dictionary<string, object>)a.DeserializeObject(content); string media_id = (string)o["media_id"]; WEC_REQUEST_MEDIA media = new WEC_REQUEST_MEDIA(); media.MEIDAID = media_id; media.TID = valObj.TID; media.ADDTIME = DateTime.Now; media.TYPE = 0; media.FILENAME = filepath; BLLTable<WEC_REQUEST_MEDIA>.Insert(media,WEC_REQUEST_MEDIA.Attribute.ID); } if (count > 0) { StringBuilder sbData = new StringBuilder("{valObj:''"); List<AttributeItem> lstCol = valObj.af_AttributeItemList; for (int i = 0; i < lstCol.Count; i++) { object val = valObj.GetValue(lstCol[i]); if (val != null) { sbData.Append(",").Append(lstCol[i].FieldName).Append(":'").Append(val.ToString()).Append("'"); } } sbData.Append("}"); if (ViewState["sbData"] == null) { ViewState["sbData"] = sbData.ToString(); } else { ViewState["sbData"] += ","+sbData.ToString(); } Button btn = (Button)sender; if (btn.ID.IndexOf("btnOK")!=-1) { if (ViewState["sbData"] == null) { string dataStr = "[" + ViewState["sbData"].ToString() + "]"; ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "if (window.opener){window.opener.returnValue = '" + dataStr + "';}else{window.returnValue = '" + dataStr + "';}window.close();", true); } else { ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "if (window.opener){window.opener.returnValue = 're';}else{window.returnValue = 're';}window.close();", true); } } else { txtTID.Value =""; txtAID.Value =""; txtKEYWORD.Value =""; txtMATCH_TYPE.Value =""; txtMEMO.Value =""; txtKIND.Value =""; txtSTATUS.Value =""; txtADDTIME.Value =""; } } } catch (Exception ex) { litWarn.Text = ex.Message; } }
protected void btnOK_Click(object sender, EventArgs e) { try { WEC_REQUEST valObj = new WEC_REQUEST(); if (txtTID.Value != "") { valObj.TID = Convert.ToDecimal(txtTID.Value); } //Ìí¼ÓµÄÇé¿ö if (valObj.TID == 0) { WEC_REQUEST cond = new WEC_REQUEST(); cond.KEYWORD = Convert.ToString(txtKEYWORD.Value); cond.AID = Convert.ToInt32(userBase2.Curraid); if (BLLTable <WEC_REQUEST> .Count(cond) > 0) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "alert('ÇëÎðÊäÈëÖظ´¹Ø¼ü×Ö')", true); return; } } if (txtAID.Value != "") { valObj.AID = Convert.ToDecimal(txtAID.Value); } if (txtKEYWORD.Value != "") { valObj.KEYWORD = Convert.ToString(txtKEYWORD.Value); } if (txtMATCH_TYPE.Value != "") { valObj.MATCH_TYPE = Convert.ToInt32(txtMATCH_TYPE.Value); } if (txtKIND.Value.Equals("5")) { valObj.MEMO = hidPICURL.Value;; } else { valObj.MEMO = Convert.ToString(txtMEMO.Value); } if (txtKIND.Value != "") { valObj.KIND = Convert.ToInt32(txtKIND.Value); } if (txtSTATUS.Value != "") { valObj.STATUS = Convert.ToInt32(txtSTATUS.Value); } if (txtADDTIME.Value != "") { valObj.ADDTIME = Convert.ToDateTime(txtADDTIME.Value); } if (valObj.TID > 0) { //valObj.TID = Convert.ToDecimal(keyid); count = BLLTable <WEC_REQUEST> .Update(valObj, WEC_REQUEST.Attribute.TID); } else { count = BLLTable <WEC_REQUEST> .Insert(valObj, WEC_REQUEST.Attribute.TID); keyid = valObj.TID.ToString(); } //ͼƬ»Ø¸´ if (kind.Equals("5")) { string path = valObj.MEMO; path = path.Substring(path.LastIndexOf('/') + 1); string filepath = Request.PhysicalApplicationPath + path; filepath = filepath.Replace('\\', '/'); string content = HttpUtil.uploadFile(filepath, HttpUtil.getAccessToken("wx69c300b3e390be5b", "3c06a3f6eb8a562b278583dff8b9da1c"), "image"); JavaScriptSerializer a = new JavaScriptSerializer(); Dictionary <string, object> o = (Dictionary <string, object>)a.DeserializeObject(content); string media_id = (string)o["media_id"]; WEC_REQUEST_MEDIA media = new WEC_REQUEST_MEDIA(); media.MEIDAID = media_id; media.TID = valObj.TID; media.ADDTIME = DateTime.Now; media.TYPE = 0; media.FILENAME = filepath; BLLTable <WEC_REQUEST_MEDIA> .Insert(media, WEC_REQUEST_MEDIA.Attribute.ID); } if (count > 0) { StringBuilder sbData = new StringBuilder("{valObj:''"); List <AttributeItem> lstCol = valObj.af_AttributeItemList; for (int i = 0; i < lstCol.Count; i++) { object val = valObj.GetValue(lstCol[i]); if (val != null) { sbData.Append(",").Append(lstCol[i].FieldName).Append(":'").Append(val.ToString()).Append("'"); } } sbData.Append("}"); if (ViewState["sbData"] == null) { ViewState["sbData"] = sbData.ToString(); } else { ViewState["sbData"] += "," + sbData.ToString(); } Button btn = (Button)sender; if (btn.ID.IndexOf("btnOK") != -1) { if (ViewState["sbData"] == null) { string dataStr = "[" + ViewState["sbData"].ToString() + "]"; ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "if (window.opener){window.opener.returnValue = '" + dataStr + "';}else{window.returnValue = '" + dataStr + "';}window.close();", true); } else { ScriptManager.RegisterStartupScript(Page, this.GetType(), "goto", "if (window.opener){window.opener.returnValue = 're';}else{window.returnValue = 're';}window.close();", true); } } else { txtTID.Value = ""; txtAID.Value = ""; txtKEYWORD.Value = ""; txtMATCH_TYPE.Value = ""; txtMEMO.Value = ""; txtKIND.Value = ""; txtSTATUS.Value = ""; txtADDTIME.Value = ""; } } } catch (Exception ex) { litWarn.Text = ex.Message; } }