Send SMS Program

Source: Internet
Author: User
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. data; using system. data. sqlclient; using system. configuration; namespace sendready {class program {static void main (string [] ARGs) {console. title = "Send reservation reminder text message"; system. threading. thread th = new system. threading. thread (new system. threading. threadstart (sendalltime); th. isbackground = true; th. start (); consol E. readline ();} public static string urlencode (string URL) {byte [] BS = encoding. getencoding ("gb2312 "). getbytes (URL); stringbuilder sb = new stringbuilder (); For (INT I = 0; I <BS. length; I ++) {If (BS [I] <128) Sb. append (char) BS [I]); else {sb. append ("%" + BS [I ++]. tostring ("X "). padleft (2, '0'); sb. append ("%" + BS [I]. tostring ("X "). padleft (2, '0');} return sb. tostring ();} public static voi D sendalltime () {While (true) {try {dataset Ds; using (sqlconnection conn = new sqlconnection (configurationmanager. connectionstrings ["sendmtmessage. properties. settings. eztcnconnectionstring "]. connectionstring) {Conn. open (); sqldataadapter adapter = new sqldataadapter ("select * From tbreadysendsms where datediff (HH, fsendtime, getdate () = 1 and fstate = '002'", Conn ); DS = new dataset (); ADAP Ter. fill (DS); adapter. dispose (); Conn. close (); Conn. dispose ();} foreach (datarow item in DS. tables [0]. rows) {// string msgid = bllsms. getmaxid (); random Rand = new random (); string url = "http://www.sms10000.com.cn/szdx_sdk/SMS? Cmd = Send & uid = ***** 38368 & psw = ***** & mobiles = "+ item [" fmobile "] +" & msgid = "+ Rand. next (1, 999999 ). tostring () + "& MSG =" + item ["fcontent"] + ""; string encodeurl = urlencode (URL); system. net. webrequest sendhttp = system. net. webrequest. create (encodeurl); system. net. webresponse retresponse = sendhttp. getresponse (); system. io. stream stream = retresponse. getresponsestream (); system. io. streamreader readerresp Onse = new system. Io. streamreader (stream, system. Text. encoding. Default); string result = readerresponse. readtoend (); If (result! = "100") {Throw new exception ("failed to send! ");} Else {using (sqlconnection conn = new sqlconnection (configurationmanager. connectionstrings ["sendmtmessage. properties. settings. eztcnconnectionstring "]. connectionstring) {Conn. open (); Using (sqltransaction trans = Conn. begintransaction () {try {using (sqlcommand cmd = new sqlcommand ("", Conn, trans) {cmd. commandtype = commandtype. text; cmd. commandtext = "Update tbreadysendsms set fstate = '001' where freadysendsmsid =" + item ["freadysendsmsid"]; cmd. executenonquery ();} trans. commit ();} catch {TRANS. rollback () ;}} Conn. close () ;}} retresponse. close (); readerresponse. close (); stream. close ();} Ds. dispose (); system. threading. thread. sleep (100);} catch (exception ex ){}}}}}

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.