Home  >  Article  >  Backend Development  >  PHP implementation of sending SMS examples

PHP implementation of sending SMS examples

小云云
小云云Original
2018-03-30 11:35:313594browse

This article mainly shares with you examples of how to send text messages in PHP. It is mainly shared with you in the form of code. I hope it can help you.

1. Call alidayu's tool class package, and then configure the parameters

  public function sendSMS ($mobile, $content,$type,$pcode,$address)
{
    include("TopSdk.php");
    date_default_timezone_set('Asia/Shanghai');    $c = new \TopClient();
    switch ($type){        case '1':            $c->appkey = "*****";            $c->secretKey = "************";            //$req = new AlibabaAliqinFcSmsNumSendRequest;
            $req = new \AlibabaAliqinFcSmsNumSendRequest();            $req->setSmsType("normal");            $req->setSmsFreeSignName("好运生活");            $req->setSmsParam("{\"village\":\"".$content."\",\"pcode\":\"".$pcode."\",\"address\":\"".$address."\"}");            $req->setRecNum($mobile);            $req->setSmsTemplateCode("SMS_127161604");            $resp = $c->execute($req);
            break;
        default :            $c->appkey = "*****";            $c->secretKey = "**********";            //$req = new AlibabaAliqinFcSmsNumSendRequest;
            $req = new \AlibabaAliqinFcSmsNumSendRequest();            $req->setSmsType("normal");            $req->setSmsFreeSignName("顺手拿");            $req->setSmsParam("{\"code\":\"".$content."\",\"product\":\"shunshouna\"}");            $req->setRecNum($mobile);            $req->setSmsTemplateCode("SMS_33580526");            $resp = $c->execute($req);
            break;
    }    if($resp->result->success){        return true;
    }    else{        return false;
    }
}

2. Call the sendSMS method and process it.

 $res = (new Aliyun())->sendSMS($this->_param['mobile'],$this->_param['village'],1,$this->_param['p_code'],$this->_param['address']);

           

1. Call alidayu's tool class package, and then configure the parameters

  public function sendSMS ($mobile, $content,$type,$pcode,$address)
{
    include("TopSdk.php");
    date_default_timezone_set('Asia/Shanghai');    $c = new \TopClient();
    switch ($type){        case '1':            $c->appkey = "*****";            $c->secretKey = "************";            //$req = new AlibabaAliqinFcSmsNumSendRequest;
            $req = new \AlibabaAliqinFcSmsNumSendRequest();            $req->setSmsType("normal");            $req->setSmsFreeSignName("好运生活");            $req->setSmsParam("{\"village\":\"".$content."\",\"pcode\":\"".$pcode."\",\"address\":\"".$address."\"}");            $req->setRecNum($mobile);            $req->setSmsTemplateCode("SMS_127161604");            $resp = $c->execute($req);
            break;
        default :            $c->appkey = "*****";            $c->secretKey = "**********";            //$req = new AlibabaAliqinFcSmsNumSendRequest;
            $req = new \AlibabaAliqinFcSmsNumSendRequest();            $req->setSmsType("normal");            $req->setSmsFreeSignName("顺手拿");            $req->setSmsParam("{\"code\":\"".$content."\",\"product\":\"shunshouna\"}");            $req->setRecNum($mobile);            $req->setSmsTemplateCode("SMS_33580526");            $resp = $c->execute($req);
            break;
    }    if($resp->result->success){        return true;
    }    else{        return false;
    }
}

2. Call the sendSMS method and process it.

 $res = (new Aliyun())->sendSMS($this->_param['mobile'],$this->_param['village'],1,$this->_param['p_code'],$this->_param['address']);

Related recommendations:

php to implement sending SMS

php How to use SMS Bao to send text messages

PHP sends text messages, emails and many other practical PHP code sharing

The above is the detailed content of PHP implementation of sending SMS examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn