China Unicom mobile sends text messages

Source: Internet
Author: User
Tags sendmsg

// 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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.