这是一个用php编写的发送SMS消息的类,他可以连接SMS服务器,完成用户验证,并发送SMS信息到用户手机中
<html> <head> <title>SMS Web Sender Demo</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <h2>SMS Web Sender DEMO!</h2> <?php if ($action != "submit") { ?> <i>Any username or password you enter here will not be stored in any way (although we're not using SSL either)</i> <p><i>Also, as you can see most of these are UK sites, not all of them will support international numbers!</i></p> <form method="post" action="demo.php"> <table width="600" border="0" cellspacing="0" cellpadding="4"> <tr> <td align="right"><b>Site</b></td> <td> <select name="site"> <option value="txtuk_net">txtuk.net (no login)</option> <option value="mtnsms_com">mtnsms.com</option> <option value="lycos_co_uk">lycos.co.uk</option> <option value="excite_co_uk">excite.co.uk</option> <option value="uboot_com">uboot.com</option> <option value="genie_co_uk">genie.co.uk</option> </select> </td> </tr> <tr> <td align="right"><b>User</b></td> <td> <input type="text" name="user"> </td> </tr> <tr> <td align="right"><b>Password</b></td> <td> <input type="password" name="pass"> </td> </tr> <tr> <td valign="top" align="right"><b>Number</b></td> <td> <input type="text" name="number"> (eg. +447123123123)</td> </tr> <tr> <td valign="top" align="right"><b>Message</b></td> <td> <textarea name="message" cols="40" rows="8"></textarea> </td> </tr> <tr> <td align="right"><b>Debug</b></td> <td> <input type="checkbox" name="debug" value="yes"> </td> </tr> <tr> <td align="right"> </td> <td> </td> </tr> <tr> <td align="right"> </td> <td> <input type="hidden" name="action" value="submit"> <input type="submit" name="Submit" value="Send!"> </td> </tr> </table> </form> <?php } else { // contains the site details include("sites.php"); // contains main class include("class.sms_web_sender.php"); if (empty($number) || empty($site) || empty($message)) { die("Make sure number, site and message are not empty"); } if (!empty($debug) && $debug == "yes") { $debug = true; } else { $debug = false; } // signature bit of text that's required by some // sites like MTNSMS.com, you can leave as is $signature = "*"; // create instance of sms web sender the one // optional argument will determine if // debug is turned on or not $sms = new sms_web_sender($debug); // add accounts // 1st argument: username // 2nd argument: password // 3rd argument: server // 4th argument: weight (this is only useful when // shuffling the logins, the higher // the weight, the more likely it'll // be placed near the top of the list) // default if left blank: 1 $sms->add_login("$user", "$pass", "$site"); // add Proxy Server details if required // I haven't tested this myself, feature of jm_sms //$sms->setProxyServer("proxyserver"); //$sms->setProxyPort(81); //$sms->setProxyUser("proxyusername"); //$sms->setProxyPass("proxypassword"); //$sms->setProxy(true); // passes the number, signature and message in an array $result = $sms->send_sms(array("number"=>$number, "signature"=>$signature, "message"=>$message)); if ($result) { echo "<h2>Sent!</h2>"; } else { echo "<h2>Could not send :(</h2>"; echo "<p><a href=\"javascript:history.back()\">Go Back</a></p>"; } } ?> </body> </html>
<?php if (!defined("_SITES_INCLUDED")) { define("_SITES_INCLUDED", 1); } define("CLASS_NAME", "sms_web_sender"); /************************************** each class needs to have these functions + login() + logout() + send_sms() ***************************************/ class sms_global { // takes a +44 international style number and returns a UK style number // eg. +447977777777 becomes 07977777777 // used for some sites which don't accept the international format (genie.co.uk - 8/12/01) function uk_num_format($number) { return preg_replace("/\\+[0-9]{2}([0-9]+)/", "0$1", $number); } // get rid of the + sign in the number function strip_plus_sign($number) { return str_replace("+", "", $number); } // return the country code from a number function country_code($number) { if (preg_match("/^\\+([0-9]{2})[0-9]+/", $number, $matches)) { return $matches[1]; } else { return false; } } // return the value of a hidden html form field function hidden_field_val($html, $field_name) { if (preg_match('/type="?hidden"? name="?'.$field_name.'"? value="?([^"]+)"?/i', $html, $matches)) { return $matches[1]; } } } /******************************************************************************************************** ***************** * LYCOS.CO.UK * ***************** ********************************************************************************************************/ class lycos_co_uk extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "sms.lycos.co.uk"; var $server_login = "login.lycos.co.uk"; var $server_logout = "login.lycos.co.uk"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $login_script = "/bin/membership/len_login?StatusCookie=OK"; var $login_command = "member_name=[[USER]]&service=lycos&redirect=http%3A%2F%2Fsms.lycos.co.uk%2Fmobile%2F&target_url=&fail_url=&format=&password=[[PASS]]&product=SMS&x=20&y=10"; // check for this URL var $success_url = "/bin/membership/len_cookie"; // next URL var $next_url = "/mobile/message_center/message_center.jsp"; // message delivered url var $message_delivered_url = "/mobile/message_center/message_delivered.jsp"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] //------------------------- // check for success string var $success_string = "SMS message sent to:"; // check for quota string var $quota_exceeded_string = "You tried to send"; // send command var $send_command = "myaction=send×tamp=[[TIMESTAMP]]&buddy=No+buddies&recsource=receiver&receiver=[[GSM_NUMBER]]&format=sms&body=[[MESSAGE]]&phrase=--+Select+a+phrase+--"; // send URL var $send_script = "/mobile/message_center/message_center.jsp"; // message var $send_message = "[[MESSAGE]]"; // logout URL var $logout_script = "/bin/membership/len_logout?redirect=http:%2F%2Fsms.lycos.co.uk%2Fmobile"; // failure checks var $fail = array(); /************************** constructor ***************************/ function lycos_co_uk() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "body"; $this->fail[0][check_for] = "<b>ERROR:</b> The password supplied for"; $this->fail[0][debug_msg] = "Incorrect password for user: [[USER]]"; $this->fail[1][check_type] = "body"; $this->fail[1][check_for] = "<b>ERROR:</b> There is no member"; $this->fail[1][debug_msg] = "User name not found: [[USER]]"; } /************************** login ***************************/ function login(&$sms_obj) { if (isset($this->server_login)) { $sms_obj->set_server($this->server_login); } // grab login string $command = $this->login_command; $command = str_replace("[[USER]]", urlencode($sms_obj->get_username()), $command); $command = str_replace("[[PASS]]", $sms_obj->get_password(), $command); $result = $sms_obj->post_url($this->login_script, $command); $redirect_url = $sms_obj->parse_redirect($result); // check for incorrect login details if (is_array($this->fail)) { for ($x=0; $x < count($this->fail); $x++) { $check_in = ($this->fail[$x][check_type] == "body") ? $result : $redirect_url; if (strstr($check_in, $this->fail[$x][check_for]) != "") { $sms_obj->debug(str_replace("[[USER]]", $sms_obj->get_username(), $this->fail[$x][debug_msg])); return false; } } } $sms_obj->set_cur_url("http://".$sms_obj->get_server().$redirect_url); if (strstr($redirect_url, $this->success_url)) { $sms_obj->debug("Redirect URL matches Success URL: ".$this->success_url); // switch to main server at this point (incase login servers were used) $sms_obj->set_server($this->server); $sms_obj->set_cur_url("http://".$sms_obj->get_server().$this->next_url); } return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // has to have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($number), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($number), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message), $command); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->message_delivered_url)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; if (strstr($result, $this->quota_exceeded_string)) { $sms_obj->debug("Quota for current user [".$sms_obj->get_username()."] exceeded."); } return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { $sms_obj->debug("Logging out..."); if (isset($this->server_logout)) { $sms_obj->set_server($this->server_logout); } $sms_obj->get_url($this->logout_script); return true; } } /******************************************************************************************************** ***************** * MTNSMS.COM * ***************** ********************************************************************************************************/ class mtnsms_com extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "www.mtnsms.com"; var $server_logout = "www.mtnsms.com"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $login_script = "/session.asp"; var $login_command = "username=[[USER]]&password=[[PASS]]&email=&joinusclick=no&returl=&x=40&y=43"; // check for this URL var $success_url = "/members/contacts/contacts.asp"; // next URL var $next_url = "/sms/xsms.asp"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] //------------------------- // check for success string var $success_string = "your message sent to"; // check for success url var $message_delivered_url = "/sms/msgSent.asp"; // check for quota string var $quota_exceeded_string = "Daily message quota exceeded"; // send command var $send_command = "smsToCTs=&smsToNumbers=[[GSM_NUMBER]]&smsMessage=[[MESSAGE]]&smsSig=1&smsSigDyna=[[SIG]]&msgCL=138&lenSSig=4&lenLSig=3&lenSysSig=11"; // send URL var $send_script = "/sms/xsms.asp"; // message var $send_message = "[[MESSAGE]]"; // logout URL var $logout_script = "/logout.asp"; // failure checks var $fail = array(); /************************** constructor ***************************/ function mtnsms_com() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "URL"; $this->fail[0][check_for] = "/registration/"; $this->fail[0][debug_msg] = "User name not found: [[USER]]"; $this->fail[1][check_type] = "URL"; $this->fail[1][check_for] = "err=204"; $this->fail[1][debug_msg] = "Incorrect password for user: [[USER]]"; } /************************** login ***************************/ function login(&$sms_obj) { if (isset($this->server_login)) { $sms_obj->set_server($this->server_login); } // grab login string $command = $this->login_command; $command = str_replace("[[USER]]", urlencode($sms_obj->get_username()), $command); $command = str_replace("[[PASS]]", $sms_obj->get_password(), $command); $result = $sms_obj->post_url($this->login_script, $command); $redirect_url = $sms_obj->parse_redirect($result); // check for incorrect login details if (is_array($this->fail)) { for ($x=0; $x < count($this->fail); $x++) { $check_in = ($this->fail[$x][check_type] == "body") ? $result : $redirect_url; if (strstr($check_in, $this->fail[$x][check_for]) != "") { $sms_obj->debug(str_replace("[[USER]]", $sms_obj->get_username(), $this->fail[$x][debug_msg])); return false; } } } $result = $sms_obj->get_url($redirect_url); if (strstr($redirect_url, $this->success_url)) { $sms_obj->debug("Redirect URL matches Success URL: ".$this->success_url); // switch to main server at this point (incase login servers were used) $sms_obj->set_server($this->server); $sms_obj->get_url($this->next_url); } return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // should have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($number), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($number), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message."\n"), $command); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->message_delivered_url)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; if (strstr($result, $this->quota_exceeded_string)) { $sms_obj->debug("Quota for current user [".$sms_obj->get_username()."] exceeded."); } return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { $sms_obj->debug("Logging out..."); if (isset($this->server_logout)) { $sms_obj->set_server($this->server_logout); } $sms_obj->get_url($this->logout_script); return true; } } /******************************************************************************************************** ***************** * TXTUK.NET * ***************** ********************************************************************************************************/ class txtuk_net extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "www.txtuk.net"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $login_script = "/sendtxtmsg.php"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] //------------------------- // check for success string var $success_string = "Message Sent to"; // send command var $send_command = "back=default&tnumber=[[GSM_NUMBER]]&message=[[MESSAGE]]"; // send URL var $send_script = "/action_sendtxtmsg.php"; // message var $send_message = "[[MESSAGE]]"; // failure checks var $fail = array(); /************************** constructor ***************************/ function txtuk_net() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "body"; $this->fail[0][check_for] = "Message not authorised"; $this->fail[0][debug_msg] = "Problems sending!"; } /************************** login ***************************/ function login(&$sms_obj) { $result = $sms_obj->get_url($this->login_script); $sms_obj->parse_redirect($result); return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // has to have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($number), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($number), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message), $command); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->success_string)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { return true; } } /******************************************************************************************************** ***************** * GENIE.CO.UK * ***************** ********************************************************************************************************/ class genie_co_uk extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "www.genie.co.uk"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $pre_login_script = "/"; var $login_script = "/login/doLogin"; var $login_command = "username=[[USER]]&password=[[PASS]]&x=9&y=9"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] //------------------------- // check for success string var $success_string = "has been sent"; // check for quota string var $quota_exceeded_string = "You tried to send"; // send command var $send_command = "RECIPIENT=[[GSM_NUMBER]]&ABNUMBER=&left=103&SUBJECT=&check=0&MESSAGE=[[MESSAGE]]&action=Send"; // send URL var $send_script = "/public/gmail/smsconfirm.html"; // message var $send_message = "[[MESSAGE]]"; // logout URL var $logout_script = "/logout/"; // failure checks var $fail = array(); /************************** constructor ***************************/ function genie_co_uk() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "body"; $this->fail[0][check_for] = "User Name and/or Password you entered"; $this->fail[0][debug_msg] = "Incorrect user/pass for user: [[USER]]"; } /************************** login ***************************/ function login(&$sms_obj) { /** NOT NECESSARY! ******** *************************** $result = $sms_obj->get_url($this->pre_login_script); $redirect_url = $sms_obj->parse_redirect($result); $sms_obj->get_url($redirect_url); if (isset($this->server_login)) { $sms_obj->set_server($this->server_login); } */ // grab login string $command = $this->login_command; $command = str_replace("[[USER]]", urlencode($sms_obj->get_username()), $command); $command = str_replace("[[PASS]]", $sms_obj->get_password(), $command); $result = $sms_obj->post_url($this->login_script, $command); $redirect_url = $sms_obj->parse_redirect($result); // check for incorrect login details if (is_array($this->fail)) { for ($x=0; $x < count($this->fail); $x++) { $check_in = ($this->fail[$x][check_type] == "body") ? $result : $redirect_url; if (strstr($check_in, $this->fail[$x][check_for]) != "") { $sms_obj->debug(str_replace("[[USER]]", $sms_obj->get_username(), $this->fail[$x][debug_msg])); return false; } } } if (!$redirect_url) { return false; } return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // has to have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($this->uk_num_format($number)), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($this->uk_num_format($number)), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message), $command); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->success_string)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; if (strstr($result, $this->quota_exceeded_string)) { $sms_obj->debug("Quota for current user [".$sms_obj->get_username()."] exceeded."); } return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { $sms_obj->debug("Logging out..."); if (isset($this->server_logout)) { $sms_obj->set_server($this->server_logout); } $sms_obj->get_url($this->logout_script); return true; } } /******************************************************************************************************** ***************** * UBOOT.COM * ***************** ********************************************************************************************************/ class uboot_com extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "www.uboot.com"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $login_script = "/cgi-bin/login.fcgi/uk/login"; var $login_command = "unickname=[[USER]]&password=[[PASS]]&x=80&y=4"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] //------------------------- // check for success string var $success_string = "transmit_done.gif"; // check for quota string var $quota_exceeded_string = "You tried to send"; // send command var $send_command = "p=csn&a=formaction&messageclass=Uboot%3A%3AMessages%3A%3ASMS&abook=addressbook&unickname=&unumber=&netw=&mobileno=[[GSM_NUMBER]]&smsno=[[GSM_NUMBER]]&date=&time=&num=0&body=[[MESSAGE]]&send.x=43&send.y=6"; // send URL var $send_script = "/cgi-bin/ubox.fcgi"; // message var $send_message = "[[MESSAGE]]"; // logout URL var $logout_script = "/cgi-bin/login.fcgi/uk/dologout"; // failure checks var $fail = array(); /************************** constructor ***************************/ function uboot_com() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "body"; $this->fail[0][check_for] = "entered is not valid"; $this->fail[0][debug_msg] = "Incorrect telephone number entered"; $this->fail[1][check_type] = "body"; $this->fail[1][check_for] = "doesn't exist"; $this->fail[1][debug_msg] = "User name not found: [[USER]]"; $this->fail[2][check_type] = "body"; $this->fail[2][check_for] = "password you entered does not match"; $this->fail[2][debug_msg] = "Incorrect password for user: [[USER]]"; } /************************** login ***************************/ function login(&$sms_obj) { // grab login string $command = $this->login_command; $command = str_replace("[[USER]]", urlencode($sms_obj->get_username()), $command); $command = str_replace("[[PASS]]", $sms_obj->get_password(), $command); $result = $sms_obj->post_url($this->login_script, $command); $redirect_url = $sms_obj->parse_redirect($result); // check for incorrect login details if (is_array($this->fail)) { for ($x=0; $x < count($this->fail); $x++) { $check_in = ($this->fail[$x][check_type] == "body") ? $result : $redirect_url; if (strstr($check_in, $this->fail[$x][check_for]) != "") { $sms_obj->debug(str_replace("[[USER]]", $sms_obj->get_username(), $this->fail[$x][debug_msg])); return false; } } } if (!$redirect_url) { return false; } return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // has to have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($this->strip_plus_sign($number)), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($this->strip_plus_sign($number)), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message), $command); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->success_string)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; if (strstr($result, $this->quota_exceeded_string)) { $sms_obj->debug("Quota for current user [".$sms_obj->get_username()."] exceeded."); } return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { $sms_obj->debug("Logging out..."); if (isset($this->server_logout)) { $sms_obj->set_server($this->server_logout); } $sms_obj->get_url($this->logout_script); return true; } } /******************************************************************************************************** ***************** * EXCITE.CO.UK * ***************** ********************************************************************************************************/ class excite_co_uk extends sms_global { //------------------------- // SERVER DETAILS //------------------------- var $server = "www.excite.co.uk"; var $server_prelogin = "reg.excite.co.uk"; var $server_login = "reg.excite.com"; var $server_logout = "reg.excite.com"; //------------------------- // LOGIN // vars - [[USER]] [[PASS]] //------------------------- var $prelogin_script = "/mps/login?pname=pfp&brand=uk_excite&targeturl=http://www.excite.co.uk/"; var $login_script = "/mps/loginreq?pname=pfp&brand=uk_excite&targeturl=http://www.excite.co.uk/&uid="; var $login_command = "acctname=[[USER]]&passwd=[[PASS]]&snonce=[[SNONCE]]&stime=[[STIME]]×kew=none&crep=none&jerror=none&gofer=Sign+in"; //------------------------- // SEND SMS // vars - [[TIMESTAMP]] [[GSM_NUMBER]] [[MESSAGE]] [[SIG]] [[COUNTRY_CODE]] //------------------------- // check for success string var $success_string = "Has Been Sent To"; // check for quota string var $quota_exceeded_string = "Quota Exceeded"; // send command var $send_command = "partial_address=[[GSM_NUMBER]]&message=[[MESSAGE]]&country_code=[[COUNTRY_CODE]]"; // send URL var $send_script = "/mobile/sms/sent/"; // message var $send_message = "[[MESSAGE]]"; // logout URL var $logout_script = "/mps/signout_val?easyvalue=easy&completevalue=complete&signout_opt=complete&pname=pfp&brand=uk_excite&targeturl=http%3A%2F%2Fwww.excite.co.uk%2F"; // failure checks var $fail = array(); /************************** constructor ***************************/ function excite_co_uk() { //------------------------- // FAILED LOGINS CLUES // vars - [[USER]] //------------------------- $this->fail[0][check_type] = "body"; $this->fail[0][check_for] = "cannot recall your password"; $this->fail[0][debug_msg] = "Incorrect username/password for user: [[USER]]"; } /************************** login ***************************/ function login(&$sms_obj) { $sms_obj->set_server($this->server_prelogin); $result = $sms_obj->get_url($this->prelogin_script); $redirect_url = $sms_obj->parse_redirect($result); $sms_obj->set_server($this->server_login); // grab login string $command = $this->login_command; $command = str_replace("[[USER]]", urlencode($sms_obj->get_username()), $command); $command = str_replace("[[PASS]]", $sms_obj->get_password(), $command); $command = str_replace("[[SNONCE]]", urlencode($this->hidden_field_val($result, "snonce")), $command); $command = str_replace("[[STIME]]", urlencode($this->hidden_field_val($result, "stime")), $command); $result = $sms_obj->post_url($this->login_script, $command); $redirect_url = $sms_obj->parse_redirect($result); // check for incorrect login details if (is_array($this->fail)) { for ($x=0; $x < count($this->fail); $x++) { $check_in = ($this->fail[$x][check_type] == "body") ? $result : $redirect_url; if (strstr($check_in, $this->fail[$x][check_for]) != "") { $sms_obj->debug(str_replace("[[USER]]", $sms_obj->get_username(), $this->fail[$x][debug_msg])); return false; } } } if (!$redirect_url) { return false; } $sms_obj->set_cur_url("http://reg.excite.co.uk/mps/login?pname=pfp&brand=uk_excite&targeturl=http://www.excite.co.uk/"); $sms_obj->clear_cookies(); $result = $sms_obj->get_url($redirect_url); $redirect_url = $sms_obj->parse_redirect($result); //$sms_obj->set_cur_url("http://reg.excite.co.uk/mps/login?pname=pfp&brand=uk_excite&targeturl=http://www.excite.co.uk/"); //$result = $sms_obj->get_url($redirect_url); $sms_obj->set_server($this->server); return true; } /************************** send sms ***************************/ function send_sms($options, &$sms_obj) { // has to have $message, $signature, $number extract($options); if (!$sms_obj->login()) { $sms_obj->debug("Unable to log in"); return false; } $tmp_message = $this->send_message; $tmp_message = str_replace("[[TIMESTAMP]]", time(), $message); $tmp_message = str_replace("[[GSM_NUMBER]]", urlencode($this->strip_plus_sign($number)), $message); $tmp_message = str_replace("[[SIG]]", urlencode($signature), $message); $tmp_message = str_replace("[[MESSAGE]]", urlencode($message), $message); $message = $tmp_message; $command = $this->send_command; $command = str_replace("[[GSM_NUMBER]]", urlencode($this->strip_plus_sign($number)), $command); $command = str_replace("[[SIG]]", urlencode($signature), $command); $command = str_replace("[[MESSAGE]]", urlencode($message), $command); $command = str_replace("[[COUNTRY_CODE]]", urlencode($this->country_code($number)), $command); // too quick? didn't think they'd check it, nice feature, // but seems limit is only enforced on the confirmation page $sms_obj->debug("Sleep for 20 seconds (otherwise Excite will complain you're too quick :)"); sleep(20); $sms_obj->set_cur_url("http://www.excite.co.uk/mobile/sms/confirm/"); $result = $sms_obj->post_url($this->send_script, $command); if (strstr($result, $this->success_string)) { $sms_obj->debug("SMS Message Sent Successfully"); return true; } else { $sms_obj->debug("SMS Send Failed"); // echo $result; if (strstr($result, $this->quota_exceeded_string)) { $sms_obj->debug("Quota for current user [".$sms_obj->get_username()."] exceeded."); } return false; } } /************************** logout ***************************/ function logout(&$sms_obj) { $sms_obj->debug("Logging out..."); if (isset($this->server_logout)) { $sms_obj->set_server($this->server_logout); } $sms_obj->get_url($this->logout_script); return true; } } ?>
<?php if (!defined("_SITES_INCLUDED")) { include("sites.php"); } class sms_web_sender { var $server; var $server_obj; var $cookies = array(); var $login = array(); var $cur_url; var $do_debug = false; var $proxy_server; var $proxy_port; var $proxy_user; var $proxy_pass; var $proxy = false; /********************** * SET/GET FUNCTIONS ***********************/ function get_server() { return $this->server; } function set_server($server) { return $this->server = $server; } function get_cur_url() { return $this->cur_url; } function set_cur_url($cur_url) { return $this->cur_url = $cur_url; } function get_debug() { return $this->do_debug; } function set_debug($debug) { return $this->do_debug = $debug; } function get_proxy_server() { return $this->proxy_server; } function set_proxy_server($proxy_server) { return $this->proxy_server = $proxy_server; } function get_proxy_port() { return $this->proxy_port; } function set_proxy_port($proxy_port) { return $this->proxy_port = $proxy_port; } function get_proxy_user() { return $this->proxy_user; } function set_proxy_user($proxy_user) { return $this->proxy_user = $proxy_user; } function get_proxy_pass() { return $this->proxy_pass; } function set_proxy_pass($proxy_pass) { return $this->proxy_pass = $proxy_pass; } function get_proxy() { return $this->proxy; } function set_proxy($proxy) { return $this->proxy = $proxy; } /********************** * CONSTRUCTOR * sets initial username, password, debug, and server ***********************/ // $server name will determine which class to use function sms_web_sender($debug=false, $username="", $password="", $server="") { if ($debug) { $this->set_debug(true); } if (!empty($server)) { $this->add_login($username, $password, $server); } } /********************** * SET SITE ***********************/ function set_site($site) { if (class_exists($site)) { set_time_limit(60); $this->clear_cookies(); $this->debug($site." class being used"); $this->server_obj = new $site; $this->set_server($this->server_obj->server); $this->set_cur_url($this->get_server()); return true; } else { $this->debug($site." class Not Found!"); if (!$this->next_login()) { $this->debug("No more servers: Exiting.."); exit; } return false; } } /********************** * ADD LOGIN ***********************/ function add_login($username, $password, $server, $weight=1) { $this->login[] = array($username, $password, $server, $weight, count($this->login)); return true; } /********************** * SHUFFLE LOGINS ***********************/ function shuffle_logins() { $tmp_array = array(); $shuffled = array(); // create new array holding biased amount // of each login (based on weight) foreach ($this->login as $val) { for ($x=1; $x<=$val[3]; $x++) { $tmp_array[] = $val; } } // loop through logins randomly picking out // login details to put in the new array while (count($shuffled) < count($this->login)) { mt_srand((double) microtime() * 1000000); $rand_pick = mt_rand(0, count($tmp_array)); if ($rand_pick > 0) $rand_pick--; $remove_id = $tmp_array[$rand_pick][4]; $shuffled[] = $tmp_array[$rand_pick]; foreach ($tmp_array as $key=>$val) { if ($val[4] == $remove_id) { unset($tmp_array[$key]); } } // reset the keys $tmp_array = array_values($tmp_array); } // replace our logins array with our shuffled array $this->login = $shuffled; return true; } /********************** * GET USERNAME ***********************/ function get_username() { return $this->login[key($this->login)][0]; } /********************** * GET PASSWORD ***********************/ function get_password() { return $this->login[key($this->login)][1]; } /********************** * GET SITE ***********************/ function get_site() { return $this->login[key($this->login)][2]; } /********************** * NEXT LOGIN ***********************/ function next_login() { if (next($this->login)) { $this->debug("Advancing to next user."); return $this->set_site($this->get_site()); } else { $this->debug("No more configured users."); return false; } } /********************** * DEBUG OUTPUT ***********************/ function debug($line) { if ($this->do_debug) { echo "- $line<br>\n"; flush(); } return true; } /********************** * GET COOKIES ***********************/ function get_cookies() { $cookies = implode("; ", $this->cookies); $this->debug("Using cookies: ".$cookies); return $cookies; } /********************** * PROCESS COOKIE ***********************/ function process_cookie($cookie) { // sample cookie // NAME=VALUE; path=/; domain=.mydomain.com; expires=Wednesday, 31-Dec-2010 12:10:00 GMT; $cookie_valid = true; $cookie = trim($cookie); if (substr($cookie, -1) == ";") $cookie = substr($cookie, 0, -1); $cookie = explode(";", $cookie, 2); $cookie_attributes = trim($cookie[1]); $cookie_name_val = explode("=", $cookie[0], 2); $cookie_name = trim($cookie_name_val[0]); $cookie_val = trim($cookie_name_val[1]); if ($cookie_val == "") { $cookie_valid = false; } if (preg_match("/expires=[a-z, ]*([0-9]{1,2}[- ][a-z]+[- ][0-9]{4})/i", $cookie_attributes, $matches)) { if (strtotime($matches[1]) < time()) { $this->debug("(-) Expired: ".implode(";", $cookie)); $cookie_valid = false; } } if (!$cookie_valid) { return false; } else { $this->cookies["$cookie_name"] = "$cookie_name=$cookie_val"; $this->debug("(+) Set-Cookie: ".implode(";", $cookie)); return true; } } /********************** * SET COOKIES ***********************/ function set_cookies($cookie) { return $this->process_cookie($cookie); } /********************** * CLEAR COOKIES ***********************/ function clear_cookies() { $this->cookies = array(); return true; } /********************** * POST URL ***********************/ function post_url($url, $formdata, $showme=false) { $full_url = "http://".$this->get_server().$url; $this->debug("[ACTION = POST] URL: ".$full_url); $data = "POST ".$url." HTTP/1.1\r\n"; $data .= $this->generate_http_header(); $data .= "Content-Type: application/x-www-form-urlencoded\r\n"; $data .= "Content-Length: ".strlen($formdata)."\r\n\r\n"; $data .= $formdata; do { $errno = 0; $fp = @fsockopen(($this->get_proxy() ? $this->get_proxy_server() : $this->get_server()), ($this->get_proxy() ? $this->get_proxy_port() : 80), $errno, $errstr, 30); if ($errno) { $this->debug("Retrying Failed POST (".$errno."): ".$errstr); sleep(1); } } while($errno); // shows HTTP POST request if ($showme) die($data); $result = ""; fputs($fp, $data); while(!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); $this->set_cur_url("http://".$this->get_server().$url); return $result; } /********************** * GET URL ***********************/ function get_url($url, $showme=false) { $full_url = "http://".$this->get_server().$url; $this->debug("[ACTION = GET] URL: ".$full_url); $data = "GET ".$url." HTTP/1.1\r\n"; $data .= $this->generate_http_header()."\r\n"; do { $errno = 0; $fp = @fsockopen(($this->get_proxy() ? $this->get_proxy_server() : $this->get_server()), ($this->get_proxy() ? $this->get_proxy_port() : 80), $errno, $errstr, 30); if ($errno) { $this->debug("Retrying Failed GET (".$errno."): ".$errstr); sleep(1); } } while($errno); // shows HTTP GET request if ($showme) die($data); $result = ""; fputs ($fp, $data); while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); $this->set_cur_url("http://".$this->get_server().$url); return $result; } /********************** * GENERATE HTTP HEADERS ***********************/ function generate_http_header() { $data = "Referer: ".$this->get_cur_url()."\r\n"; //$data .= "User-Agent: Mozilla/4.72 [en] (X11; U; Linux 2.2.14-5.0 i586)\r\n"; $data .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:0.9.4) Gecko/20011019 Netscape6/6.2\r\n"; $data .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n"; // line below enabled will not let us search through returned html (as it'll be compressed and appear garbled) //$data .= "Accept-Encoding: gzip\r\n"; $data .= "Accept-Language: en-gb\r\n"; $data .= "Accept-Charset: iso-8859-1,*,utf-8\r\n"; $data .= "Cookie: ".$this->get_cookies()."\r\n"; $data .= "Host: ".$this->get_server()."\r\n"; $data .= "Cache-Control: max-age=259200\r\n"; $data .= "Connection: close\r\n"; if ($this->get_proxy()) $data .= "Proxy-Authorization: Basic ".base64_encode($this->get_proxy_user().":".$this->get_proxy_pass())."\r\n"; return $data; } /********************** * PARSE REDIRECT ***********************/ function parse_redirect($http_header) { $header_parts = explode("\r\n", $http_header); while(list($key, $val) = each($header_parts)) { if (substr($val, 0, 10) == "Location: ") { $location = substr($val, 10); } else if (preg_match("/^Set-Cookie: /i", substr($val, 0, 12))) { $this->set_cookies(substr($val, 12)); } } if (!empty($location) && substr($location, 0, 7) == "http://") { $location = substr($location, 7); if (!strstr($location, "/")) { $this->set_server($location); } else { $this->set_server(substr($location, 0, strpos($location, "/"))); } if (substr_count($location, "/") == 0) { $location = "/"; } else { $location = substr($location, strpos($location, "/")); } } if (!empty($location)) { $location = trim($location); $location = ($location[0] != "/") ? "/".$location : $location; $this->debug("Found HTTP Redirect To: ".$location); return $location; } else { return false; } } /********************** * LOGIN ***********************/ function login() { $result = $this->server_obj->login($this); if (!$result && $this->next_login()) { return $this->login(); } else { return $result; } } /********************** * SEND SMS ***********************/ function send_sms($options) { if (!is_object($this->server_obj)) { $this->set_site($this->get_site()); } $this->set_cur_url("http://".$this->get_server()."/"); $result = $this->server_obj->send_sms($options, $this); if (!$result && $this->next_login()) { return $this->send_sms($options); } else { return $result; } } /********************** * LOGOUT * not necessary for most stuff ***********************/ function logout() { return $this->server_obj->logout($this); } } ?>
<?php /* $Date: 2001/12/09 03:51:55 $ $Revision: 1.2 $ ------------------------------------------------- SMS WEB SENDER 0.1 (08-DEC-2001) Keyvan Minoukadeh - keyvan@k1m.com http://www.k1m.com/ ------------------------------------------------- This is an example file showing you how to use the class... */ // contains the site details include("sites.php"); // contains main class include("class.sms_web_sender.php"); // your mobile number in international format (+###########) $number = "+447123123123"; // signature bit of text that's required by some // sites like MTNSMS.com, you can leave as is $signature = "*"; // main body of the message $message = "This is a test message"; // create instance of sms web sender the one // optional argument will determine if // debug is turned on or not $sms = new sms_web_sender(true); // add accounts // 1st argument: username // 2nd argument: password // 3rd argument: server // 4th argument: weight (this is only useful when // shuffling the logins, the higher // the weight, the more likely it'll // be placed near the top of the list) // default if left blank: 1 $sms->add_login("user", "pass", "uboot_com", 1); $sms->add_login("user", "pass", "genie_co_uk", 1); $sms->add_login("user", "pass", "lycos_co_uk", 10); $sms->add_login("user", "pass", "mtnsms_com", 1); $sms->add_login("user", "pass", "excite_co_uk", 5); $sms->add_login("", "", "txtuk_net", 1); // shuffle logins $sms->shuffle_logins(); // add Proxy Server details if required // I haven't tested this myself, feature of jm_sms //$sms->setProxyServer("proxyserver"); //$sms->setProxyPort(81); //$sms->setProxyUser("proxyusername"); //$sms->setProxyPass("proxypassword"); //$sms->setProxy(true); // passes the number, signature and message in an array $sms->send_sms(array("number"=>$number, "signature"=>$signature, "message"=>$message)); ?>
相关推荐
手机短信sms接入web页面php源代码类,全英文版
在Android平台上,发送SMS(短消息服务)和监控接收到的SMS消息是常见的功能,尤其在开发涉及到消息通信的应用时。以下将详细讲解如何实现这两个功能,并提供相关的代码示例。 **一、发送SMS消息** 1. **权限申请*...
根据这个描述,我们可以推测这篇文章会介绍如何将Java编写的SMS4类打包到Tomcat应用服务器中,以便PHP可以通过HTTP请求来调用这些Java服务。 标签“php sms4”表明这是关于使用PHP进行短信发送操作,而“sms4”可能...
标题中的“SMS发送工具,支持将文本文件通过SMS发送”是指一种软件应用,它能够帮助用户将文本文件的内容转换为短信并发送出去。这个工具在许多场景下都非常实用,比如在没有网络连接或者网络不稳定的情况下,需要...
在Web服务器上发送SMS(短消息服务)是网络应用程序中常见的功能,特别是在用户验证、通知服务和客户服务场景中。在ASP.NET环境中实现这一功能,我们可以利用各种库和服务API来完成。下面将详细介绍如何在ASP.NET中...
结合标题和标签,我们可以推测这是一个使用PHP与SMS服务集成的项目,可能包括发送和接收短信的功能。 从压缩包内的文件名来看,我们有以下四个文件: 1. inbound.class.php:这可能是一个名为“inbound”的类,用于...
在 PHP 开发中,有时我们需要实现发送验证码、通知消息等功能,这时 EasySMS 就能发挥重要作用。它集成了多个短信服务商的 API,使得开发者可以方便地切换不同的服务商,而无需大幅度修改代码。 首先,让我们详细...
通过AWS SNS发送SMS消息的软件包 介绍 通过AWS SNS发送电子邮件 例子 package main import ( "context" sms "github.com/gofor-little/aws-sms" ) func main () { // Initialize the SMS package. if err := sms...
`SendSMSForms`可能是用于发送短信的窗体,用户可以在这里输入接收方电话号码和消息内容,点击发送按钮后,程序会通过后台逻辑执行发送操作。 为了实现这些功能,开发者可能使用了如`System.Net.Sockets`库来处理...
"d6oo"可能是项目或库的名称,"sendsms.php"可能是一个与发送短信相关的类或函数文件,"php_mobile"暗示了这是针对移动端的PHP开发,"php_sendsms"和"sms_php"则再次强调了使用PHP进行短信发送的特性。 在实际应用...
### SMS AT设计文档知识点 #### 一、概览与背景 本设计文档旨在详细阐述SMS AT命令在系统中的实现方式,包括其结构定义以及关键命令的处理流程。SMS(Short Message Service)即短信息服务,是一种广泛应用于移动...
使用 Twilio 通过电子邮件发送 SMS 消息。 一个 node.js 脚本。下面是我的服务器环境列表。 CentOS 发布 5.3 32 位。 发送邮件 8.13.8-2.el5。 节点 v0.10.33。 您还需要一个帐户。 我的服务器主机名是“zen1....
在`sms工具类`中,我们可以封装上述步骤,提供如`sendSms(String phoneNumber, String templateCode, Map, String> params)`这样的方法,使得业务代码只需传入必要参数即可发送短信。此外,还可以考虑加入缓存机制...
在PHP中,`SmsSend.class.php`可能是一个包含飞信短信发送逻辑的类文件。类在面向对象编程中是一种封装数据和方法的结构,这里`SmsSend`可能是类的名称,它可能包含了设置短信内容、接收者、发送请求等功能的方法。 ...
【标题】"sms文档"可能指的是与短信服务或者短信管理系统相关的技术文档,这通常涉及到移动通信、企业级消息传递或客户服务等场景。源码和工具的标签暗示了这个压缩包可能包含了一些源代码示例或者实用工具,帮助...
这个源代码项目,"vc++编写的 发送手机短信 源代码 sms",显然是利用VC++来实现发送手机短信的功能。让我们深入探讨这个主题,了解相关的关键知识点。 1. **VC++编程基础**: - VC++是基于C++编程语言的集成开发...
在Android开发中,追踪和确认SMS(Short Message Service,短信)消息传递是一个关键功能,尤其在需要确保消息发送成功和接收方已经接收到的情况下。以下将详细解释如何在Android应用中实现这一功能。 首先,要追踪...
4. **demo_class.php**:示例类文件,提供了使用smsapi.class.php的示例代码,开发者可以通过运行这个示例来快速理解如何在实际项目中集成短信接口类。 5. **demo_fun.php**:类似地,这个文件可能包含了一些使用...