speshow--自娱自乐

MSN:Jone_yin@live.cn

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 最近开发项目中要用到发送短信功能,看了一下短信接口,由于是web开发, 选择了接口中的com的api !

 

当然先要引用接口中的empp.dll文件,需要注册

然后实现下面代码    

/// <summary>
///短信发送类
/// </summary>
public class SMS:DB
{
  /// <summary>
  /// 发送手机短信
  /// </summary>
  /// <param name="nRecordCount">手机号码,多个手机号用|隔开,并以|结尾</param>
  /// <param name="nOrder">短信内容</param>
  public static void SendSMS(string mobiles,string contents)
  {
    //短信服务器IP
    string host = "211.136.163.68";
    //短信服务器端口
    int port = 9981;

    //发送账户
    string accountId = "";
    string serviceId = "0";
    //发送账户密码
    string password = "";
    EMPPLib.emptcl empp = new EMPPLib.emptclClass();

    EMPPLib.ConnectResultEnum result = ConnectResultEnum.CONNECT_OTHER_ERROR;
    result = empp.connect(host, port, accountId, password);

    String msg = contents;
    EMPPLib.ShortMessage shortMsg = new EMPPLib.ShortMessageClass();
    shortMsg.srcID = accountId;
    shortMsg.ServiceID = serviceId;
    shortMsg.needStatus = true;
    EMPPLib.Mobiles mobs = new EMPPLib.MobilesClass();
    if (mobiles.IndexOf("|") > -1)
    {
      char[] cut = new char[] { '|'};
      for (Int32 i = 0; i < mobiles.Split(cut).Length-1; i++) {
        mobs.Add(mobiles.Split(cut)[i].ToString());
      }
    }
    else
    {
      mobs.Add(mobiles);
    }
    shortMsg.DestMobiles = mobs;
    shortMsg.content = msg;
    shortMsg.SendNow = true;

    empp.needStatus = true;
    if (empp != null && empp.connected == true)
    {
      empp.submit(shortMsg);
    }
  }

 

   

posted on 2010-07-20 16:00  speshow  阅读(2388)  评论(3编辑  收藏  举报