C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Text;

/// <summary>
/// Mysms 的摘要说明
/// </summary>
public class Mysms
{
 public Mysms()
 {
       
 }
    [DllImport("D:\\uucom\\Mysms.dll")]
    private extern static bool InitModem(int com, int beter);
    [DllImport("D:\\uucom\\Mysms.dll")]
    private extern static bool SendSms(int com, int beter, string context, string code, bool english, bool mianti, bool report);
    [DllImport("D:\\uucom\\Mysms.dll")]
    private extern static bool ReadSms(int com, int beter, int smsId, StringBuilder context, StringBuilder code, StringBuilder gettime, bool del);
    [DllImport("D:\\uucom\\Mysms.dll")]
    private extern static bool Dail(int com, int beter, string code, string wav);
    [DllImport("D:\\uucom\\Mysms.dll")]
    private extern static bool HangUp(int com, int beter);
  
    public static bool init()                   //初始化
    {
        if (InitModem(1, 115200))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public static bool Send(int i,string context,string code)       //发送短信
    {
        if (init())
        {
            if (context.Length > 70)
            {
                string  str=context;
                int size = 70;
                while (str.Length >size)
                {
                    string sms = str.Substring(0,size);
                    SendSms(i, 115200, sms, code, false, false, true);
                    str = str.Substring(size);
                    bool mCheck = false;
                    DateTime dt = DateTime.Now;
                    while (!mCheck)
                    {
                        TimeSpan ts = DateTime.Now - dt;
                        mCheck = ts.Seconds > 8 ? true : false;                       
                    }
                }
                if (str.Length > 0)
                {
                    SendSms(i, 115200, str, code, false, false, true);
                }
                return true;
            }
            else
            {
                if (SendSms(i, 115200, context, code, false, false, true))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
          
        }
        else
        {
            return false;
        }
    }
    public static bool Read(int com,int sid,StringBuilder context,StringBuilder code,StringBuilder gettime)     //接收短信
    {
        if (init())
        {
            if (ReadSms(com, 115200, sid, context, code, gettime, true))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    public static bool Call(int com,string code,string wav)         //呼叫
    {
        if (init())
        {
            if (Dail(com, 115200, code, wav))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    public static bool RingOff(int com) //挂机
    {
        if (HangUp(com, 115200))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

posted on 2008-08-13 10:20  王德田  阅读(448)  评论(0编辑  收藏  举报