//protected T GetJContainerResult<T>(string strResponse) where T : JContainer //{ // JObject result = (JObject)JsonConvert.DeserializeObject(strResponse); // if (result == null || (string)result["Status"] != "Success") // { // return default(T); // } // return (T)result["Data"]; //} public TResult AjaxAsync <TResult, TPostData>(string url, TPostData jsonData, RequestType requestType, Func <HttpClient, Func <HttpResponseMessage, TResult>, TResult> ajaxAsyncDelegate, AuthenticationHeaderValue authenticationHeaderValue = null) where TResult : class { SetDefaultAuthorizationHeaderValue(ref authenticationHeaderValue); using (HttpClient client = SingleInstanceHelper.GetInstance <HttpClient>()) { client.BaseAddress = new Uri(GetBaseUrl()); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); if (authenticationHeaderValue != null) { client.DefaultRequestHeaders.Authorization = authenticationHeaderValue; } return(ajaxAsyncDelegate(client, response => { string strResponseBody = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == HttpStatusCode.OK) { return SerializationHelper.JsonToObject <TResult>(strResponseBody); } else { LogHelper.Info(strResponseBody); } return default(TResult); })); } }
public static T GetCookieValue <T>(string strKey) where T : class { string strEncryptValue = GetCookieValue(strKey); return(SerializationHelper.JsonToObject <T>(EncryptHelper.Decrypt(strEncryptValue))); }
public static T Get <T>(string url) where T : class { return(SerializationHelper.JsonToObject <T>(Get(url))); }
public static T Post <T>(string url, string param) where T : class { return(SerializationHelper.JsonToObject <T>(Post(url, param))); }
/// <summary> /// 发送手机短信 /// </summary> /// <param name="mobiles">手机号码,以英文“,”逗号分隔开</param> /// <param name="content">短信内容</param> /// <param name="pass">短信通道1验证码通道2广告通道</param> /// <param name="msg">返回提示信息</param> /// <returns>bool</returns> public bool Send(string mobiles, string content, out string msg) { //检查手机号码,如果超过2000则分批发送 int sucCount = 0; //成功提交数量 string errorMsg = string.Empty; //错误消息 string[] oldMobileArr = mobiles.Split(','); int batch = oldMobileArr.Length / 50 + 1; //2000条为一批,求出分多少批 for (int i = 0; i < batch; i++) { StringBuilder sb = new StringBuilder(); int sendCount = 0; //发送数量 int maxLenght = (i + 1) * 50; //循环最大的数 //检测号码,忽略不合格的,重新组合 for (int j = 0; j < oldMobileArr.Length && j < maxLenght; j++) { int arrNum = j + (i * 50); string pattern = @"^1\d{10}$"; string mobile = oldMobileArr[arrNum].Trim(); Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写 Match m = r.Match(mobile); //搜索匹配项 if (m != null) { sendCount++; sb.Append(mobile + ","); } } //发送短信 if (sb.ToString().Length > 0) { try { string strSmsContent = strQianMing + content; //LogHelper.Info(strSmsContent); //strSmsContent = UrlEncode(strSmsContent); string strParams = "action=send&userid=&account=" + smsusername + "&password="******"&mobile=" + DelLastComma(sb.ToString()) + "&content=" + strSmsContent + "&sendTime=&extno="; //_Log.Info(strParams); string result = HttpPost(smsapiurl, strParams, ref errorMsg); //_Log.Info(result); if (result == null) { msg = errorMsg; return(false); } SMSReturnStatus smsReturnStatus = null; try { smsReturnStatus = SerializationHelper.JsonToObject <SMSReturnStatus>(result); if (smsReturnStatus.returnstatus == "Success") { sucCount += sendCount; } else { errorMsg = smsReturnStatus.message; LogHelper.Error(errorMsg); } } catch (Exception ex) { msg = result; return(false); } //成功数量 } catch (Exception ex) { errorMsg = ex.Message + ex.StackTrace; LogHelper.Error("Faild", ex); //没有动作 } } } //返回状态 if (sucCount > 0) { msg = "成功提交" + sucCount + "条,失败" + (oldMobileArr.Length - sucCount) + "条"; return(true); } msg = errorMsg; return(false); }