发送SMS短信(JSON) 转载

http://blog.csdn.net/ldl22847/article/details/42553883

public   static string GetMobileConfByUserId(string userid)
          {
              string rs = null;
              if (!string.IsNullOrEmpty(userid))
              {
                  if (string.IsNullOrEmpty(strOnLine))
                  {
                      strOnLine = ConfigurationManager.AppSettings["OnLineUrl"];
                  }
                  ServicePointManager.DefaultConnectionLimit = 300;
                  System.GC.Collect();
                  CookieContainer cookieContainer = new CookieContainer();
                  // 设置提交的相关参数
                  HttpWebRequest request = null;
                  HttpWebResponse SendSMSResponse = null;
                  Stream dataStream = null;
                  StreamReader SendSMSResponseStream = null;
                  try
                  {
                      request = WebRequest.Create(strOnLine) as HttpWebRequest;
                      request.Method = "POST";
                      request.KeepAlive = false;
                      request.ServicePoint.ConnectionLimit = 300;
                      request.AllowAutoRedirect = true;
                      request.Timeout = 10000;
                      request.ReadWriteTimeout = 10000;
                      request.ContentType = "application/json";
                      request.Accept = "application/xml";
                      request.Headers.Add("X-Auth-Token",   HttpUtility.UrlEncode("openstack"));
                      string strContent =   "{\"appId\":\"\",\"method\":\"\",\"tokenId\":\"\",\"data\":{\"userAccountId\":\""   + userid +   "\"}}";            
                      byte[] bytes =   Encoding.UTF8.GetBytes(strContent);                                       
                      request.Proxy = null;
                      request.CookieContainer = cookieContainer;
                      using (dataStream = request.GetRequestStream())
                      {
                          dataStream.Write(bytes, 0, bytes.Length);
                      }          
                      SendSMSResponse = (HttpWebResponse)request.GetResponse();
                      if (SendSMSResponse.StatusCode == HttpStatusCode.RequestTimeout)
                      {
                          if (SendSMSResponse != null)
                          {
                              SendSMSResponse.Close();
                              SendSMSResponse = null;
                          }
                          if (request != null)
                          {
                              request.Abort();
                          }
                          return null;
                      }
                      SendSMSResponseStream = new StreamReader(SendSMSResponse.GetResponseStream(),   Encoding.GetEncoding("utf-8"));
                      string strRespone = SendSMSResponseStream.ReadToEnd();
                   
                      return strRespone;
                  }
                  catch (Exception ex)
                  {
                  
                      if (dataStream != null)
                      {
                          dataStream.Close();
                          dataStream.Dispose();
                          dataStream = null;
                      }
                      if (SendSMSResponseStream != null)
                      {
                          SendSMSResponseStream.Close();
                          SendSMSResponseStream.Dispose();
                          SendSMSResponseStream = null;
                      }
                      if (SendSMSResponse != null)
                      {
                          SendSMSResponse.Close();
                          SendSMSResponse = null;
                      }
                      if (request != null)
                      {
                          request.Abort();
                      }
                  }
                  finally
                  {
                      if (dataStream != null)
                      {
                          dataStream.Close();
                          dataStream.Dispose();
                          dataStream = null;
                      }
                      if (SendSMSResponseStream != null)
                      {
                          SendSMSResponseStream.Close();
                          SendSMSResponseStream.Dispose();
                          SendSMSResponseStream = null;
                      }
                      if (SendSMSResponse != null)
                      {
                          SendSMSResponse.Close();
                          SendSMSResponse = null;
                      }
                      if (request != null)
                      {
                          request.Abort();
                      }
                  }
              }
              return rs;
          }

http://www.lanzsoft.cn/Product/cp1/dxapi/

短信API文档

一.短信接口文档说明

1、概述:

本文档详细描述了商务短信快车短信接口接入办法及注意事项,接口发送短信的三网合一代码为10690422,支持全国范围内三网短信收发,短信API调用简单,欢迎免费注册短信接口帐号体验。

2、重点注意事项:

1 地址:www.lanz.net.cn域名对应的IP地址是219.136.252.188
2 登录:密码需加密传输(加密方式 SHA1 40位大写)。加密转换工具:点击进行转换操作
3 短信内容:自助获取测试帐号的用户短信内容需按照专用模板进行编辑,点击查看模板说明
4 发送频率:建议间隔0.1秒提交一次,群发一次最多提交1000个手机号码。另我司短信系统启用了同一个手机发送频率限制,第一条发送后,2秒后才能发第2条,第3条10分钟后才能发,隔2秒后才能发第4条,以此类推(默认一天最多发10条,特殊情况可联系技术放开限制)。
5 编码:数据提交统一使用 GB2312编码,Content参数需要注意编码规则,部分开发语言需做URLENCODE编码,详细参见代码示例。密码加密和编码转换工具:点击进行转换操作
6 安全防护:对于发送短信验证码类的用户(验证码、密码、注册等行为的短信),需要加强安全管理。建议采用以下三个防范措施:A、采用安全图片验证码;B、单IP请求次数限制;C、发送时间间隔限制。

二.短信接口功能

    • 短信发送
    • 回复短信
    • 查询余量
    • 语音发送
    • 推送模式
    • 错误代码
 
 
  • 发送短信 DirectSendSMSs(群发一次最多1000个手机号码)
    URL:http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp
    1)输入参数:
    名称 类型 是否必须 示例值 描述
    UserID String 999999 用户ID (6位纯数字)
    Account String LanzSoft88 用户名
    PassWord String Lanz2016FG 密码(密码需加密传输 SHA1 40位大写)
    Content String 您的注册验证码为8268,该验证码10分钟内有效。 如非本人操作请忽略此短信!【浪驰软件】 短信按照70个字数计费为一条短信,但当短信内容大于70字时,即为长短信长短信计费按66个字数计费为一条短信,最长不超过300字
    Phones String 15322063938 手机号码,用“;”(分号)分隔,最后一个不带“;”(分号)
    PostFixNum int 1234 扩展号码。必须是数字,如无需扩展此处为空即可(注:首先在不扩展的情况下测试看看手机收到的106号码的是多少位,如果是20位了这里扩展没用,工信部标准最大长度是20位。PostFixNum = 20 -(在不扩展的情况 手机收到的号码长度)
    SendDate String 2016-1-1 定时发送的日期,立即发送可以不输入或者为空
    SendTime String 15:00:00 定时发送的时间,立即发送可以不输入或者为空
    ReturnXJ int 1 返回值格式 默认XML格式 如果需要JSON格式 该值填写 “1”
           
    2)举例:
    http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp?UserID=993965&Account=admin&Password=555555&Content=test&Phones=1111111111
     
    3)返回值:
    ErrorNum 0:短信成功, 其它:详见错误代码说明
    JobID 分配的短信任务号
    PhonesSend 服务器接收的有效手机号码数量
    ErrPhones 服务器拒绝的短信,用”;”分隔
    DeductionSMSs 扣费条数
     
    XML:
    <?xml version="1.0" encoding="GB2312"?> <LANZ_ROOT> <ErrorNum>0</ErrorNum> <JobID>2321313130</JobID> <PhonesSend>98</PhonesSend> <ErrPhones>13855556666;13611112222</ErrPhones> <DeductionSMSs>1000</DeductionSMSs> </LANZ_ROOT>
     
    JSON:
    {"LANZ_ROOT":{"ErrorNum":"0","JobID":"2321313130","PhonesSend":"98","ErrPhones":"13855556666;13611112222","DeductionSMSs":"1000"}}
     
上一篇:单例模式之C++实现


下一篇:用Beyond Compare比较文本时,忽略不重要文本的方法