//First, write a method.
Function Sendsms ( $ HTTP , $ Username , $ Password , $ Sendmobile , $ Send_content ){ $ Httpurl = $ HTTP ; $ Data = Array ( 'Username' => $ Username , // User Account 'Password' => $ Password , // User Password 'Mobile' => $ Sendmobile , // Number 'Content' => mb_convert_encoding ( $ Send_content , 'Gb2312', 'utf-8 '), // Content ); $ Re = $ This -> Postsms ( $ Httpurl , $ Data ); // Post submission If ( Trim ( $ Re )> 0 ){ Return "Success" ;} Else { Return "Error" ;}} Function Postsms ( $ Httpurl , $ Data ='' ){ $ Row = Parse_url ( $ Httpurl ); $ Host = $ Row ['Host' ]; $ Port =Isset ( $ Row ['Port'])? $ Row ['Port']: 80 ; $ File = $ Row ['Path' ]; $ Post ='' ; While ( List ( $ K , $ V ) = Each ($ Data )){ $ Post . = ( $ K ). "= ".( $ V )."&" ;} $ Post = Substr ( $ Post , 0,-1 ); $ Len = Strlen ( $ Post ); $ Fp = @ Fsockopen ( $ Host , $ Port , $ Errno , $ Errstr , 10 ); If (! $ Fp ){ Return " $ Errstr ( $ Errno ) \ N" ;} Else { $ Receive ='' ; $ Out = "Post $ File HTTP/1.1 \ r \ n" ; $ Out . = "Host: $ Host \ R \ n" ; $ Out . = "Content-Type: Application/X-WWW-form-urlencoded \ r \ n" ; $ Out . = "Connection: Close \ r \ n" ; $ Out . = "Content-Length: $ Len \ R \ n" ; $ Out . = $ Post ; Fwrite ( $ Fp , $ Out ); While (! Feof ( $ Fp )){ $ Receive . = Fgets ( $ Fp , 128 );} Fclose ( $ Fp ); $ Receive = Explode ("\ R \ n ", $ Receive ); Unset ( $ Receive [0 ]); Return Implode ("", $ Receive );}}
PHP processing page
$ Sendmobile = Isset ( $ _ Post ['Mobile'])? Trim ( $ _ Post ['Mobile']):'' ; $ Hm_arr = Explode (',', $ Sendmobile ); $ Sendtime = Isset ( $ Time )? Strtotime ( $ Time ): $ Systime ; $ Sendcontent = Isset ( $ _ Post ['Contentname'])? Trim ( $ _ Post ['Contentname']):'' ; $ Sendstatus = 1 ; $ Sendsign = Isset ( $ _ Post ['Sendsign'])? Trim ( $ _ Post ['Sendsign']):'' ; $ Send_content = $ Sendcontent .'--'. $ Sendsign ; $ Httpurl =$ Sms_config ['Httpurl' ]; $ Username = $ Sms_config ['Username' ]; $ Password = $ Sms_config ['Password' ]; $ Balance_info = $ Balance -> Getblanceinfo ( $ Uid ); $ Balance_sy =$ Balance_info ['Balance _ info']- $ Balance_info ['Rate' ]; $ Rate = $ Balance_info ['Rate' ]; If ( $ Balance_sy > $ Rate ){ $ HP = $ Balance -> Sendsms ( $ Httpurl ,$ Username , $ Password , $ Sendmobile , Preg_replace ('/\ S +/', '% 20 ', $ Send_content )); If ( $ HP = 'Success' ){ $ SQL _c = "Update { $ Tablepre } Sms_info set balance_info =' $ Balance_sy ', Amount = Amount + '1' where userid ='$ Uid '" ; $ Rs = $ DB -> Query ( $ SQL _c ); $ SQL _s = "Update { $ Tablepre } Company set corpname =' $ Sendsign 'Where userid =' $ Uid '" ; $ Rs_s = $ DB -> Query ($ SQL _s ); $ SQL = "Insert { $ Tablepre } Sms_log (sendmobile, userid, sendtime, sendcontent, sendtype, sendstatus, sendmoney) values (' $ Sendmobile ',' $ Uid ',' $ Sendtime ',' $ Sendcontent ',' $ Sendtype ',' $ Sendstatus ',' $ Rate ')" ; $ Rs = $ DB -> Query ( $ SQL ); Header ("Location: index. php? C = sigle_send_mess & s = 1" );} Else { Header ("Location: index. php? C = sigle_send_mess & s = 2" );}} Else { Header ("Location: index. php? C = sigle_send_mess & s = 3");}