private static string smssign = "【" + ConfigHelper.GetConfigAppSettingsValue("QYBSMSSign") + "】"; //配置签名 /// <summary> /// 发送短消息 /// </summary> /// <param name="phones">群发可以提交不超过50000个手机号码,每个号码用英文逗号间隔。</param> /// <param name="content">为短信内容,须加上签名,例如"【微软科技】",短信内容为utf-8编码,有特殊符号请urlencode内容</param> /// <param name="sendOneTime">相同手机多久可以发送一次短信</param> /// <param name="needstatus">是否需要推送短信 值为true或false;</param> /// <param name="port">又说是端口(又说是扩展码),默认为空</param> /// <param name="sendtime">发送时间(定时)为空则立即发送</param> /// <returns></returns> public static String SendMsg(string phones, string content, int sendOneTime, String needstatus, String port, String sendtime) { if (string.IsNullOrEmpty(phones)) { return("手机号不能为空"); } if (!SMSCommons.IsEnabledSend(phones, sendOneTime)) { return("操作频繁," + sendOneTime + "分钟内只可以发一次"); } if (string.IsNullOrEmpty(content)) { return("短信内容不能为空"); } string postDate = string.Format("username={0}&passwd={1}&phone={2}&msg={3}{4}&needstatus={5}&port={6}&sendtime={7}", username, passwd, phones, smssign, content, needstatus, port, sendtime); try { return(SMSCommons.PushToWeb(postUrl, postDate, Encoding.UTF8)); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 发送短信接口 /// </summary> /// <param name="mobile">手机号码 可以群发 用,分割</param> /// <param name="content">内容</param> /// <param name="sendOneTime">一分钟后可以发送</param> /// <param name="smsSign">s短信签名</param> /// <returns></returns> public static string SendSMS(string mobile, string content, int sendOneTime, string smsSign = "") { if (string.IsNullOrEmpty(mobile)) { return("手机号不能为空"); } if (sendOneTime > 0 && !SMSCommons.IsEnabledSend(mobile, sendOneTime)) { return("操作频繁," + sendOneTime + "分钟内只可以发一次"); } if (string.IsNullOrEmpty(content)) { return("短信内容不能为空"); } StringBuilder sms = new StringBuilder(); sms.AppendFormat("name={0}", Account); //账号 sms.AppendFormat("&pwd={0}", PWD); //密码 sms.AppendFormat("&content={0}", content); sms.AppendFormat("&mobile={0}", mobile); sms.AppendFormat("&sign={0}", smsSign.IsNullEmpty() ? Sign : smsSign);// 公司的简称或产品的简称都可以 sms.Append("&type=pt"); try { string resp = SMSCommons.PushToWeb(SMSServiceUrl, sms.ToString(), Encoding.UTF8); string[] msg = resp.Split(','); if (msg[0] == "0") { //errMsg = "提交成功:SendID=" + msg[1]; return("OK"); } else { return("发送失败:错误信息=" + msg[1]); } } catch (Exception ex) { return(ex.Message); } }