Thứ Năm, 28 tháng 2, 2008

SMS Class

using System;using System.Net;using System.Net.Sockets;using System.IO;namespace SMS_Machine{ /// /// Summary description for send. /// public class sms { private static string xmlUrl = "http://xml2.aspsms.com:5061/xmlsvr.asp"; private string orgi; private string userkey; private string password; public sms() { } public sms(string abs, string login, string pw) { this.orgi = abs; this.userkey = login; this.password = pw; } public bool send(int smsid, string number, string text, int FlashMode, int BlinkMode) { sendASP(smsid,number,text,FlashMode,BlinkMode,"", ""); return false ; } private string sendASP(int idsms, string number, string message, int flashing,int blinking, string URLDeliveryNotification, string URLNonDeliveryNotification) { string content = "\r\n" + "\r\n" + "" + userkey + "\r\n" + "" + password + "\r\n" + "" + orgi + "\r\n" + "\r\n" + "" + number + "\r\n" + "" + idsms + "\r\n" + "\r\n" + "" + message + "\r\n" + "" + flashing + "\r\n" + "" + blinking + "\r\n" + "" + URLDeliveryNotification + "id=\r\n" + "" + URLNonDeliveryNotification + "id=\r\n" + "SendTextSMS\r\n" + "\r\n"; string xmlResult = ""; try { HttpWebRequest myWebRequest =(HttpWebRequest)WebRequest.Create(xmlUrl); myWebRequest.Method = "POST"; myWebRequest.ContentType = "text/xml"; myWebRequest.ContentLength = content.Length; // write the http-message body into the request stream StreamWriter requestWriter = new StreamWriter(myWebRequest.GetRequestStream()); requestWriter.Write(content); requestWriter.Close(); //read the response StreamReader responseReader = new StreamReader(myWebRequest.GetResponse().GetResponseStream()); xmlResult = responseReader.ReadToEnd(); responseReader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return xmlResult; } }}

Không có nhận xét nào: