Send SMS Program
Last Update:2018-12-06
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 ){}}}}}