通过免费网关发送短信

发布于 2024-12-03 21:00:09 字数 5506 浏览 1 评论 0原文

请指导我通过网站发送短信的示例代码。如何包含短信网关。请告诉我,我可以使用 way2sms.com 作为网关吗?

这是正确的使用方法吗?请建议我只有这么多代码才有效?

<?php
error_reporting(E_ALL);
ob_implicit_flush(true);


include_once "class.curl.php";
include_once "class.sms.php";

$smsapp=new sms();
$smsapp->setGateway('way2sms'); 


echo "Logging in  ... ";
$smsapp->login('10 digit number','way2sms password');

echo "Sending SMS ... ";
$result=$smsapp->send('receipient number','text message');

if($result=='true')
{
    echo "Message sent";
}
else
{   
    echo "Error encountered : ".$smsapp->getLastError();
}

?>

这是我的 class.curl.php

<?php
class sms
{
    var $username;
    var $password;
    var $curl;
    var $server;
    var $loginDone;
    var $debugMode;
    var $data;
    var $error;
    public function __construct()
    {
        $this->curl=new cURL();
    //  $this->curl->setProxy("");
        $this->loginDone=false;
        $this->debugMode=false;
        $this->data=array();
    }
    public function setGateway($serverName)
    {
        switch($serverName)
        {
            case '160by2':
            $this->server='160by2';
            break;

            case 'way2sms':
            $this->server='way2sms';
            break;

            case 'airtel':
            $this->server='airtel';
            break;

            default :
            $this->server='way2sms';

        }
    }
    public function login($username,$password)
    {
        $server=$this->server;

        call_user_func(array($this,"login_$server"),$username,$password);
        $this->loginDone=true;

    }
    public function send($number,$msg)
    {
        $server=$this->server;
        if($this->loginDone)
        return call_user_func(array($this,"send_$server"),$number,$msg);
        else
        {
            echo "<h2>Please login first before sending SMS</h2>";
        }

    }
    private function login_way2sms($username,$password)
    {
        $out=($this->curl->post("http://www.way2sms.com","1=1"));
        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $domain=trim($matches[1]);

        $this->data['domain']=$domain;

        $out= $this->curl->post("{$domain}auth.cl","username=$username&password=$password&Submit=Sign+in");

        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $referer=trim($matches[1]);
        $this->data['referer']=$referer;


    }


    private function send_way2sms($number,$msg)
    {
        $domain=$this->data['domain'];
        $html=$this->curl->post("{$domain}jsp/InstantSMS.jsp?val=0","1=1",$this->data['referer']);
        if($this->debugMode)
        {
        echo "<h2>After logging in, the HTML returned by server is</h2>";
        echo $html;
        }

        $pattern = '/name="Action".+?value="(.*)"/';
        preg_match($pattern, $html, $matches);

        $custfrom=$matches[1];
        $msg=urlencode($msg);
        $html=$this->curl->post("{$domain}FirstServletsms?custid=","custid=undefined&HiddenAction=instantsms&Action={$custfrom}&login=&pass=&MobNo=$number&textArea=$msg");
        $pattern = '/class="style1">(.+?)<\/span>/';
        preg_match($pattern, $html, $matches);
        $out=($matches[1]);

        if(!preg_match("/successfully/",$out))
        {
        $this->setError($out);
        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }
    public function getLastError()
    {
        return $this->error;

    }
    private function setError($error)
    {
        $this->error=$error;
    }
    private function login_160by2($username,$password)
    {
    //  $out2=$this->curl->get("http://m.160by2.com");
        $out=$this->curl->post("http://m.160by2.com/LoginCheck.asp?l=1&txt_msg=&mno=","txtUserName=$username&txtPasswd=$password&RememberMe=Yes&cmdSubmit=Login");
        $pattern="/MyMenu.asp\?Msg=(.+?)&/";

        preg_match($pattern,$out,$matches);
        $id=trim($matches[1]);
        $this->data['id']=$id;

    }

    private function send_160by2($number,$msg)
    {
        $msg=urlencode($msg);
        $id=$this->data['id'];
        $out1=$this->curl->post("http://m.160by2.com/SaveCompose.asp?l=1","txt_mobileno=$number&txt_msg=$msg&cmdSend=Send+SMS&TID=&T_MsgId=&Msg=$id");
        //echo $out1;
        $pattern = '/\<table.+?\>(.+)\<\/table/s';
        preg_match($pattern, $out1, $matches);

        $out=strip_tags(@$matches[1]);
        if(count($matches)<1)
        {
        $pattern="/\<div.+?background:.+?yellow.+?\>(.+?)\<\/div\>/s";

        preg_match($pattern,$out1,$matches);

        $out=strip_tags($matches[1]);
        }

//
    //  echo "out is $out";

        if(!preg_match("/successfully/i",$out))
        {

        $this->setError($out);

        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }

    private function login_airtel($username,$password)
    {
        $this->data['username']=$username;
        $this->data['password']=$password;

    }


    private function send_airtel($number,$msg)
    {

    }
}

?>

代替用户名和密码,我应该使用哪个用户名和密码?

Please guide me with sample code for sending sms through website. How to include sms gateway. Please tell me, can i use way2sms.com as gateway?

is it the right way to use? please suggest me only this much of code works?

<?php
error_reporting(E_ALL);
ob_implicit_flush(true);


include_once "class.curl.php";
include_once "class.sms.php";

$smsapp=new sms();
$smsapp->setGateway('way2sms'); 


echo "Logging in  ... ";
$smsapp->login('10 digit number','way2sms password');

echo "Sending SMS ... ";
$result=$smsapp->send('receipient number','text message');

if($result=='true')
{
    echo "Message sent";
}
else
{   
    echo "Error encountered : ".$smsapp->getLastError();
}

?>

here is my class.curl.php

<?php
class sms
{
    var $username;
    var $password;
    var $curl;
    var $server;
    var $loginDone;
    var $debugMode;
    var $data;
    var $error;
    public function __construct()
    {
        $this->curl=new cURL();
    //  $this->curl->setProxy("");
        $this->loginDone=false;
        $this->debugMode=false;
        $this->data=array();
    }
    public function setGateway($serverName)
    {
        switch($serverName)
        {
            case '160by2':
            $this->server='160by2';
            break;

            case 'way2sms':
            $this->server='way2sms';
            break;

            case 'airtel':
            $this->server='airtel';
            break;

            default :
            $this->server='way2sms';

        }
    }
    public function login($username,$password)
    {
        $server=$this->server;

        call_user_func(array($this,"login_$server"),$username,$password);
        $this->loginDone=true;

    }
    public function send($number,$msg)
    {
        $server=$this->server;
        if($this->loginDone)
        return call_user_func(array($this,"send_$server"),$number,$msg);
        else
        {
            echo "<h2>Please login first before sending SMS</h2>";
        }

    }
    private function login_way2sms($username,$password)
    {
        $out=($this->curl->post("http://www.way2sms.com","1=1"));
        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $domain=trim($matches[1]);

        $this->data['domain']=$domain;

        $out= $this->curl->post("{$domain}auth.cl","username=$username&password=$password&Submit=Sign+in");

        $pattern="/Location:(.+?)\n/";
        preg_match($pattern,$out,$matches);
        $referer=trim($matches[1]);
        $this->data['referer']=$referer;


    }


    private function send_way2sms($number,$msg)
    {
        $domain=$this->data['domain'];
        $html=$this->curl->post("{$domain}jsp/InstantSMS.jsp?val=0","1=1",$this->data['referer']);
        if($this->debugMode)
        {
        echo "<h2>After logging in, the HTML returned by server is</h2>";
        echo $html;
        }

        $pattern = '/name="Action".+?value="(.*)"/';
        preg_match($pattern, $html, $matches);

        $custfrom=$matches[1];
        $msg=urlencode($msg);
        $html=$this->curl->post("{$domain}FirstServletsms?custid=","custid=undefined&HiddenAction=instantsms&Action={$custfrom}&login=&pass=&MobNo=$number&textArea=$msg");
        $pattern = '/class="style1">(.+?)<\/span>/';
        preg_match($pattern, $html, $matches);
        $out=($matches[1]);

        if(!preg_match("/successfully/",$out))
        {
        $this->setError($out);
        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }
    public function getLastError()
    {
        return $this->error;

    }
    private function setError($error)
    {
        $this->error=$error;
    }
    private function login_160by2($username,$password)
    {
    //  $out2=$this->curl->get("http://m.160by2.com");
        $out=$this->curl->post("http://m.160by2.com/LoginCheck.asp?l=1&txt_msg=&mno=","txtUserName=$username&txtPasswd=$password&RememberMe=Yes&cmdSubmit=Login");
        $pattern="/MyMenu.asp\?Msg=(.+?)&/";

        preg_match($pattern,$out,$matches);
        $id=trim($matches[1]);
        $this->data['id']=$id;

    }

    private function send_160by2($number,$msg)
    {
        $msg=urlencode($msg);
        $id=$this->data['id'];
        $out1=$this->curl->post("http://m.160by2.com/SaveCompose.asp?l=1","txt_mobileno=$number&txt_msg=$msg&cmdSend=Send+SMS&TID=&T_MsgId=&Msg=$id");
        //echo $out1;
        $pattern = '/\<table.+?\>(.+)\<\/table/s';
        preg_match($pattern, $out1, $matches);

        $out=strip_tags(@$matches[1]);
        if(count($matches)<1)
        {
        $pattern="/\<div.+?background:.+?yellow.+?\>(.+?)\<\/div\>/s";

        preg_match($pattern,$out1,$matches);

        $out=strip_tags($matches[1]);
        }

//
    //  echo "out is $out";

        if(!preg_match("/successfully/i",$out))
        {

        $this->setError($out);

        return false;
        }
        else
        {
        return true;
        $this->setError("No errors");
        }

    }

    private function login_airtel($username,$password)
    {
        $this->data['username']=$username;
        $this->data['password']=$password;

    }


    private function send_airtel($number,$msg)
    {

    }
}

?>

in the place of username and password, which username and password i should use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无所谓啦 2024-12-10 21:00:09

是的,或者您可以使用无线运营商自己提供的网关,就像使用 PHP 邮件向他们发送电子邮件一样简单函数

其中(号码) 中,您必须包含他们的 10 位数电话号码。这意味着您必须包含他们的区号。

AT&T
(数字)@txt.att.net

T-Mobile
(数字)@tmomail.net

Sprint
(数字)@messaging.sprintpcs.com

Verizon
(数字)@vtext.com 或 (数字)@vzwpix.com

Yeah, or you could use the gateways as provided by the wireless carriers themselves, as then it's as simple as sending them an email with PHP's mail function.

Where (Number) is, you must include their 10 digit phone number. So that means that you must include their area code.

AT&T
(Number)@txt.att.net

T-Mobile
(Number)@tmomail.net

Sprint
(Number)@messaging.sprintpcs.com

Verizon
(Number)@vtext.com OR (Number)@vzwpix.com

苏辞 2024-12-10 21:00:09

您使用的代码完全过时了。 Way2sms 改变了他们的身份验证方式。
如果您想使用新代码,那么这里是解决方案: http://ritesh-chandora.blogspot.in/2012/02/php-code-for-sending-free-sms.html
该博客将提供轻松发送短信的新方式。

THE Code you are using is totally outdated. Way2sms change their way of authentication.
If you want to use new code then here is solution : http://ritesh-chandora.blogspot.in/2012/02/php-code-for-sending-free-sms.html
this blog will provide new way of sending sms easily.

廻憶裏菂餘溫 2024-12-10 21:00:09

看起来不错,除了一行
改变这个

if($result=='true')
to
if($result == true)

It seems fine, except one line
change this

if($result=='true')
to
if($result == true)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文