PHP sends mass text messages (text message interface connection problems)

Source: Internet
Author: User
//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");} 

 

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.