你要考虑你的短信平台提供商是否能在你所在 地发送短信。
还要短信提供商为你提供 DLL 和相关文档!(关键是接口)

解决方案 »

  1.   

    http://www.yesky.com/SoftChannel/72342380468109312/20040523/1800310.shtml
      

  2.   

    通过MSCOMM..我只写出了关键技术。
    #region 手机与电脑连接和断开事件=========================================
    private void btnCnn_Click(object sender, System.EventArgs e)
    {

    lblcnnInfo.Text="";
    btnClose.Enabled =false;

    if (MSCOMM.PortOpen)
    {
    MessageBox.Show("端口已打开!","提示信息");
    }
    else
    {
    MSCOMM.PortOpen =true;
    lblcnnInfo.Text="COM1已打开!";
    }

    MSCOMM.InBufferCount = 0;
    string strTemp="AT\r";
    int T = Environment.TickCount;
    int L;
    string Buffer = "";
    MSCOMM.Output = strTemp;


    do
    {
    System.Windows.Forms.Application.DoEvents(); Console.WriteLine(Environment.TickCount - T );
    lblcnnInfo.Text  = "COM1 已打开," +"\r"+  "正在连接手机 ...";
    Buffer += MSCOMM.Input;
    L=Buffer.IndexOf("OK\r\n"); 
    } while(L == -1 && Environment.TickCount - T <=2500);

    if (L!=-1)
    {
    btnCnn.Enabled=false;
    btnClose.Enabled =true;
    btnSendSMS.Enabled =true;
    lblcnnInfo.Text  = "COM1 已打开," + (char)13 + "连接手机成功!";
    }
    else 
    {
    btnCnn.Enabled =true;
    btnClose.Enabled =false;
    MSCOMM.PortOpen =false;
    btnSendSMS.Enabled =false;
    lblcnnInfo.Text  = "COM1 已打开," + (char)13 + "连接手机失败!";

    }
    }
    private void btnClose_Click(object sender, System.EventArgs e)
    {
    if (MSCOMM.PortOpen)
    {
    MSCOMM.PortOpen =false;
    }
    btnCnn.Enabled =true;
    btnClose.Enabled =false;
    btnSendSMS.Enabled =false;
    lblcnnInfo.Text  = "COM1关闭, 已断开手机的连接!";
    }
    #endregion
      

  3.   

    #region 发送短信=========================================================
    private void btnSendSMS_Click(object sender, System.EventArgs e)
    {
    lblSMS.Text="";
    if(this.txtCenter.Text.Trim()=="")
    {

    MessageBox.Show("提示:请输入短信中心服务号码!","短信发送");
    this.txtCenter.Focus();
    return;

    }
    else if(this.txtMobile.Text.Trim()=="")
    {
    MessageBox.Show("提示:请输入要发送的手机号!","短信发送");
    this.txtMobile.Focus();
    return;
    }
    else if(this.txtSMS.Text.Trim()=="")
    {
    MessageBox.Show("提示:请输入要发送的短信内容!","短信发送");
    this.txtSMS.Focus();
    return;
    }

    //将没字转换成16进制

    string strInput=txtSMS.Text;
    string txt="";
    string strTemp="";
    for (int i = 0; i < strInput.Length; i++) 
    {
    string str = "0000" + ((int)strInput[i]).ToString("X");
    txt += str.Substring(str.Length - 4);
    }


    //有效期 string cbo =this.cboBox3.Text;
    cbo=cbo.Substring(0,2); strInput =txt;
    strTemp = strTemp + "08";           //SMSC地址信息的长度(91683110301405F0共八位字节)
    strTemp = strTemp + "91";           //SMSC地址格式(TON/NPI)
    strTemp = strTemp + strTOstr(txtCenter.Text.Substring(1)); //SMSC地址(8613010341500南京的短信服务中心号码)
    strTemp = strTemp + "11"  ;         //基本参数(TP-MTI/VFP)( 发送,接收为84)
    strTemp = strTemp + "00" ;          //MR Message Reference
    strTemp = strTemp + "0D" ;          //目标SIM卡号码长度(683159717456F4按阿拉伯数字个数计)
    strTemp = strTemp + "91" ;          //同上
    strTemp = strTemp + "68";
    strTemp = strTemp + strTOstr(txtMobile.Text); //要发送的手机号
    strTemp = strTemp + "00";           //普通GSM类型,点到点方式
    strTemp = strTemp + "08";           //UCS2编码
    strTemp = strTemp + cbo; //有效期
    string SMSLength = (txt.Length / 2).ToString("X");

    strTemp=strTemp + SMSLength;
    strTemp=strTemp + txt;
    strTemp = strTemp + (char)26;
    //   MSCOMM.Output = "AT+CMGF=0" + vbCr '以Pdu模式发送短信

    MSCOMM.Output = "AT+CMGS=" + (15 + txtSMS.Text.Length * 2) + (char)13;

    Thread.Sleep(2000);
    MSCOMM.Output = strTemp;
    lblSMS.Text="正在发送手机短信...";

    int T = Environment.TickCount;
    int L;
    string Buffer = "";


    do
    {
    System.Windows.Forms.Application.DoEvents(); Console.WriteLine(Environment.TickCount - T );
    Buffer += MSCOMM.Input;
    L=Buffer.IndexOf("OK\r\n");  } while(L == -1 && Environment.TickCount - T <=5500);

    if (L!=-1)
    {
    lblSMS.Text  = "短信发送成功!";
    }
    else 
    {
    lblSMS.Text  = "短信发送失败!";

    }
    }
    #endregion
      

  4.   

    hehe, 
    要不要买我们公司的产品啊我们的项目里面也需要一个手机发送功能
    于是让另外一个部门帮我们设计了一个外挂设备
    类似于机顶盒的东西,往电脑上一插就再挂上个小软件就可以发了
    我们要发短信的时候就写数据库,他自动检测数据库里面数据,然后发送
    不过,要插SIM卡,插在那个小盒子里面呵呵
      

  5.   

    和腾讯、网易合作,那都是要钱的,哪可能白给你啊。你只是自已用用,买个GSM Modem吧,直接用at指令发。
      

  6.   

    呵呵
    这个问题现在有简单的方法了。新浪提供了一个webservice,可以提供这个功能。只要项目中添加web引用就可以了。
      

  7.   

    写几个类
    public class SMSPdu
    {
    private string SCA;
    private string PduType;
    private string MR;
    // private string Oa;
    private string Da;
    private string PID;
    private string DCS;
    // private string SCTS;
    private string VP;
    private string Udl;
    private string Ud; public SMSPdu(string sDA, byte[] bsUD)
    {
    DCS = "18";
    PID = "90";
    SCA = "0891683108200405F0";
    VP = "04";
    PduType = "11";
    MR = "00";
    Da = "0D91" + Conversion.toBCD("86" + sDA + "F");
    Ud = Conversion.toHexString(bsUD, 2);
    Udl = (Ud.Length / 2).ToString("X").PadLeft(2, '0');
    } public SMSPdu(string sDA, string sUD, int CharLength)
    {
    DCS = "18";
    PID = "90";
    SCA = "0891683108200405F0";
    VP = "04";
    PduType = "11";
    MR = "00";
    Da = "0D91" + Conversion.toBCD("86" + sDA + "F");
    //Da = ("86" + ReceiveNo).Length.Tostring("X").PadLeft(2, '0')  + "91" + Conversion.toBCD("86" & ReceiveNo & "F");
    Ud = Conversion.toHexString(sUD, CharLength);
    // Right("00" + Hex(LenB(.Ud) \ 4), 2);
    Udl = (Ud.Length / 2).ToString("X").PadLeft(CharLength, '0');
    } public override string ToString() 
    {   
    string sPdu; sPdu = SCA + PduType + MR +
    Da + PID + DCS +
    VP + Udl + Ud;
    return sPdu;
    } public int Length()
    {
    string sData = "";
    sData = PduType + MR + Da + PID + DCS + VP + Udl + Ud;
    return sData.Length ;
    }
    }}
      

  8.   

    要是用其他网站上的webservice,要线注册手机,不能白用。
    你可以考虑用个短信中心战。
      

  9.   

    /// </summary>
    public class SmsPduCodec 
    {

    private  const char EMPTYCHAR = (char)0x100;
    private  const char EXTTABLEESCAPE = (char)0x1B;
    // private static char[] gsmToIsoMap; // GSM ==> ISO88591
    // private static char[] isoToGsmExtMap; private static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7',
      '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
      }; public static bool MessageDecode(String encmsg, out string sResult)
    {
    int o;
    StringBuilder msg = new StringBuilder(160);
    String ostr;
    char c; // assumes even number of chars in octet string.
    for(int i = 0; i < encmsg.Length; i += 2) 
    {
    ostr = encmsg.Substring(i, 2);
    o = int.Parse(ostr, NumberStyles.HexNumber);
    c= (char) o;
    //c = gsmToIsoMap[c];
    msg.Append(c);
    }
    sResult = msg.ToString();
    return true;
    } public static bool MessageDecode(String encmsg, out char[] bytResult)
    {
    // encmsg: encoded string to decode.
    // msglen: the requested number of characters to decode.
    int o;
    char[] bytTmp;
    String ostr; bytTmp = new char[encmsg.Length/2];
    // assumes even number of chars in octet string.
    for(int i = 0; i < encmsg.Length; i += 2) 
    {
    ostr = encmsg.Substring(i, 2);
    o = int.Parse(ostr, NumberStyles.HexNumber);
    bytTmp[i / 2] = (char)o;
    } bytResult = bytTmp; return true;
    } // // nicely display time and date of received SMS
    // public static String displayTimeDate(Calendar cal)
    (60*60*1000)*4;
    // if (month_str.Length < 2) month_str ="0" + month_str;
    // if (day_str.Length < 2) day_str = "0" + day_str;
    // if (hour_str.Length < 2) hour_str = "0" + hour_str;
    // if (minute_str.Length < 2) minute_str = "0" + minute_str;
    // if (second_str.Length < 2) second_str = "0" + second_str;
    // sResult = hour_str + ":" + minute_str + ":" + second_str + "  ";
    // sResult = sResult + day_str + "-" + month_str + "-" + year_str;
    // return sResult;
    // }
    public static String swapDigits(String str) 
    {
    if( str == null )
    return str; int strlen = str.Length;
    StringBuilder sb = new StringBuilder(strlen); for(int i=0; (i+1) < strlen; i=i+2) 
    {
    sb.Append(str[i+1]);
    sb.Append(str[i]);
    }
    return sb.ToString();
    } // converts an 8 bit integer into a hexadecimal string
    public static String toHexString(int b) 
    {
    char[] digits = new char[2];
    b = b & 255; digits[0] = hexDigits[b / 0x10];
    digits[1] = hexDigits[b % 0x10]; return new String(digits);
    }   
    // Conversion: 7 bit character string --> 8 bit bytes as hex string   
    public static String sevenBitEncode(string message) {
    if(message == null)
    return message;

    string encmsg = "";
    int bb = 0, bblen = 0, i;
    char o='\0', c='\0';

    for(i=0; i < message.Length || bblen>=8; i++) {
    if(i<message.Length) {
    c = message[i];
    //tc = isoToGsmMap[c];
    /*
    if(tc == EXTTABLEESCAPE) {
    //msg.insert(i+1, isoToGsmExtMap[c]);
    }
    */
    //c = tc;

    //c &= ~(1 << 7); // clear (discard) eight bit.
    unchecked 
    {
    c &= (char)~(1 << 7);
    }// clear (discard) eight bit. bb |= (c << bblen); // insert c to bb.
    bblen += 7;
    }

    while(bblen >= 8) { // we have a full octet.
    o = (char) (bb & 255); // take 8 bits.
    encmsg += (SmsPduCodec.toHexString(o));
    //bb >>>= 8;
    bb >>= 8;
    bblen -= 8;
    }

    } // end: for(i=0; i<msglen || bblen>=8; i++) {

    if( (bblen > 0) )
    encmsg += (SmsPduCodec.toHexString(bb));

    return encmsg.ToString();
    }

    public static String sevenBitDecode(String encmsg) {
    return sevenBitDecode(encmsg, encmsg.Length);
    }

    // Conversion: 8 bit bytes as hex strings --> 7 bit characters string
    public static String sevenBitDecode(String encmsg, int msglen)
    {
    // encmsg: encoded string to decode.
    // msglen: the requested number of characters to decode.

    int i, o, r=0, rlen=0, olen=0, charcnt=0; // ints are 32 bit long.
    StringBuilder msg = new StringBuilder(160);
    int encmsglen = encmsg.Length;
    String ostr;
    bool exttableescape = false;
    char c;

    // assumes even number of chars in octet string.
    for(i=0; ((i+1)<encmsglen) && (charcnt<msglen); i=i+2) 
    {
    ostr = encmsg.Substring(i, 2);
    o = int.Parse(ostr, NumberStyles.HexNumber);
    olen = 8;

    if(rlen >= 7) 
    { // take a full char off remainder.
    c = (char) (r & 127);
    //r >>>= 7;
    r >>= 7;
    rlen -= 7;
    msg.Append(c);
    charcnt++;
    }

    o <<= rlen; // push remainding bits from r to o.
    o |= r;
    olen += rlen;

    c = (char) (o & 127); // get first 7 bits from o.
    //o >>>= 7;
    o >>= 7;
    olen -= 7;

    r = o; // put remainding bits from o to r.
    rlen = olen;


    if( c == EXTTABLEESCAPE ) 
    { // ext table character handling.
    exttableescape = true;
    continue;

    else if( exttableescape == true) 
    {
    exttableescape = false;
    //c = gsmToIsoExtMap[c];
    }

    msg.Append(c);
    charcnt++;
    } // end: for(i=0; ((i+1)<encmsglen) && (charcnt<msglen); i=i+2) {

    if( (rlen>0) && (charcnt<msglen) )
    msg.Append((char)r);

    return msg.ToString();
    }

    //
    // // creates timestamp from given date/time information
    // public static String TimeStampEncode(Calendar time)
    (60*60*1000)*4;
    if (hour_str.Length<2) hour_str="0" + hour_str;
    // if (minute_str.Length<2) minute_str="0" + minute_str;
    // if (second_str.Length<2) second_str="0" + second_str;
    // if (zone_str.Length<2) zone_str="0" + zone_str;
    // String sResult = year_str + month_str + day_str + hour_str + minute_str + second_str + zone_str;
    // sResult = swapDigits(sResult);
    // return sResult;
    // }
    //
    //
    // // decode timestamp from received sms
    // public static GregorianCalendar TimeStampDecode(String timestamp)
    // {
    // timestamp = StringtoBCD(timestamp);
    // int year = int.Parse(timestamp.Substring(0,2));
    // int month = int.Parse(timestamp.Substring(2,4)) - 1;
    // int day = int.Parse(timestamp.Substring(4,6));
    // int hour = int.Parse(timestamp.Substring(6,8));
    // int minute = int.Parse(timestamp.Substring(8,10));
    // int second = int.Parse(timestamp.Substring(10,12));
    // int zone = int.Parse(timestamp.Substring(10,12))*(60*60*1000)/4;
    // GregorianCalendar time= new GregorianCalendar(year,month,day,hour,minute,second);
    // return time;
    // }
    //
    //    
    // Conversion: 8 bit bytes as hex strings --> 8 bit characters string
    public static String StringDecode(String encmsg, int bitDecode)
    {
    // encmsg: encoded string to decode.
    // msglen: the requested number of characters to decode.

    int i, o;
    StringBuilder msg = new StringBuilder(160);
    String ostr;
    char c;
    int iStep = 0;

    if (bitDecode == 8)
    {
    iStep = 2;
    }
    else if (bitDecode == 16)
    {
    iStep = 4;
    }
    // assumes even number of chars in octet string.
    for(i=0; i<encmsg.Length; i += iStep) 
    {
    ostr = encmsg.Substring(i, iStep);
    o = int.Parse(ostr, NumberStyles.HexNumber);
    c= (char) o;
    ///c = gsmToIsoMap[c];
    msg.Append(c);
    }
    return msg.ToString();
    }
      

  10.   

    public class SmsReceivedPacket : ReceivedPacket
    {
    // double[] electricitys = new double[12];
    // double[] voltages = new double[12] ;
    // double[] powers = new double[12];
    // byte[] digitals = new byte[32];
    // DateTime reportTime = System.DateTime.Now ; public SmsReceivedPacket(string msg, int loopCount, int digitalsCount)
    {
    toReceivedPacket(msg.ToCharArray());
    } public SmsReceivedPacket(char[] bReceived, int loopCount, int digitalsCount)
    {
    toReceivedPacket( bReceived);
    } public override int getLoopCount()
    {
    return 12;
    } public override int getDigitalsCount()
    {
    return 32;
    } public override int getMetersCount()
    {
    return 1;
    } public override int getSwitchCount()
    {
    return 4;
    } protected override void toReceivedPacket(char[] bReceived)
    {
    int digitalsIndex = 0; if ((bReceived.Length != PacketConst.PacketLength) || (bReceived[2] != '\x80')
    ||(bReceived[0] != PacketConst.PacketHead[0]) ||(bReceived[1] != PacketConst.PacketHead[1]))
    {
    throw new Exception("Invalid Packet");
    } switch((Command)(int)bReceived[3])
    {
    case Command.cmdCheck:
    // electricity
    for( int i = 0; i < 12; i++)
    {
    // electricity 忽略前4位
    electricitys[i] = (bReceived[3 + 2 * i + 1] & 0x0f) * 256 + bReceived[1 + 2 * i + 2];
    //voltage
    voltages[i] = (bReceived[27  + 2 * i + 1] * 256 & 0x0f) + bReceived[27  + 2 * i + 2];
    //power
    powers[i] = (bReceived[51  + 2 * i + 1] * 256 & 0x0f) + bReceived[51  + 2 * i + 2];
    } for (int i = 0; i < 4; i++)
    {
    for (int j = 0; j < 8; j++)
    {
    digitals[i] = (byte)(bReceived[75  + i + 1] & (2 ^ (7 - j))) ;
    digitalsIndex ++;
    }
    }
    reportTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month , 
    DateTime.Now.Day, (int) bReceived[80],(int)bReceived[81], 0);
    break; } }