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 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!