/// <summary> /// 发送请求,并获取回复 /// </summary> /// <param name="entity"></param> /// <returns></returns> public static string SendRequest(ActiveCallBaseEntity entity) { string strResult = string.Empty; if (entity == null) { return(strResult); } HttpItem hi = new HttpItem(); hi.URL = ActiveRequest.UrlProcess(entity); if (entity.Protocol.ToLower() == "https") { hi.IsTrustCertificate = true; } hi.Method = entity.Method; hi.Postdata = entity.Content; hi.Encoding = Encoding.UTF8; hi.PostEncoding = entity.PostEncoding; HttpHelper hh = new HttpHelper(); HttpResult hr = hh.GetHtml(hi); strResult = hr.Html; return(strResult); }
/// <summary> /// 构造需要传递给主动请求的ActiveCallBaseEntity对象 /// </summary> /// <param name="url">完整的url,不带参数</param> /// <param name="wxPlatType">平台类型</param> /// <param name="strJson">传递的json数据</param> /// <param name="strMethod">请求方式,默认post</param> /// <param name="dictParams">url上的除access_token参数</param> /// <returns></returns> protected ActiveCallBaseEntity GetEntityByAction(string url, string strJson, Dictionary <string, string> dictParams = null, string strMethod = "post") { ActiveCallBaseEntity entity = new ActiveCallBaseEntity(); string strUrl = string.Empty; strUrl = url; if (this._wxPlatType == WxPlatFormTypeEnum.QY) { entity.AccessToken = new WXQY.WXQYHandler().AccessToken; } else if (this._wxPlatType == WxPlatFormTypeEnum.GZ) { entity.AccessToken = new WXGZ.WXGZHandler().AccessToken; } entity.Url = strUrl; entity.Content = strJson; entity.Params = dictParams; entity.Method = strMethod; entity.PostEncoding = Encoding.UTF8; return(entity); }
/// <summary> /// Url与参数的组装 /// </summary> /// <param name="entity">ActiveCallBaseEntity实例</param> /// <returns></returns> private static string UrlProcess(ActiveCallBaseEntity entity) { string strUrl = string.Empty; if (entity == null) { return(strUrl); } StringBuilder sbUrl = new StringBuilder(); sbUrl.Append(entity.Url).Append("?access_token=" + entity.AccessToken); if (entity.Params != null && entity.Params.Count > 0) { foreach (KeyValuePair <string, string> kvItem in entity.Params) { sbUrl.Append("&" + kvItem.Key + "=" + kvItem.Value); } } strUrl = sbUrl.ToString(); return(strUrl); }