// Reference
Using System. Text;
Using System. Net;
Using System. IO;
Using cn. sh. unicom. groupsms;
// SendMobile code
Private string _ MobNum;
Private string _ MobMsg;
Public SendMobile (string MobNum, string MobMsg)
{
This. _ MobNum = MobNum;
This. _ MobMsg = MobMsg;
}
Public void SendMsg ()
{
If (CheckType (this. _ MobNum ))
ToMobile ();
Else
ToUnicom ();
}
Public void ToMobile ()
{// Mobile Interface
Encoding encoding = Encoding. GetEncoding ("gb2312 ");
String incluiseid = "123456"; // enterprise code
String accountid = "1581"; // account
String pwd = "23"; // Password
String postData = "enterpriseid =" + enterpriseid + "& accountid =" + accountid + "& pswd =" + pwd + "& mobs =" + this. _ MobNum + "& msg =" + this. _ MobMsg;
String strUrl = "http: // 211.136.163.68: 8000/httpserver ";
Byte [] DATA = encoding. getbytes (postdata );
// Prepare the request...
Httpwebrequest myrequest = (httpwebrequest) webrequest. Create (strurl );
Myrequest. method = "Post ";
Myrequest. contenttype = "application/X-WWW-form-urlencoded ";
Myrequest. contentlength = data. length;
Stream newstream = myrequest. getrequeststream ();
// Send data
Newstream. Write (data, 0, Data. Length );
Newstream. Close ();
}
Public void ToUnicom ()
{// Unicom Interface
Cn. sh. unicom. groupsms. Login myLogin = new cn. sh. unicom. groupsms. Login ();
String MySessionID = "";
MyLogin. username = "yourname"; // 123456789 username
MyLogin. userType = "0 ";
MyLogin. password = "yourpwd"; // password
LoginMes mes1 = new LoginMes ();
Mes1.login = myLogin;
SmWSImplService Binding = new SmWSImplService ();
OpResult Value1 = new OpResult ();
Try
{
Value1 = Binding. memberLogin (mes1 );
}
Catch
{
;
}
MySessionID = Value1.sessionId; // obtain the sessionid.
SendBatchSMS (Binding, MySessionID, this. _ MobMsg, "companycode"); // companycode is the enterprise code 1112345
Value1 = Binding. logout (mes1 );
}
Public bool CheckType (string MobileNum)
{
String ForeStr = MobileNum. Substring (0, 3 );
Int ForeNum = Convert. ToInt32 (ForeStr );
If (ForeNum <= 134)
Return false;
Else
Return true;
}
// Page code
Private void SendMassage (string Telephone, string text)
{
SendMobile sm = new SendMobile (Telephone, text );
Sm. SendMsg ();
}