这篇文章介绍的内容是关于253短信接口PHP直接调用,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
<?php //namespace Vendor\Sms; class Sms{ private $API_SEND_URL='http://smssh1.253.com/msg/send/'; private $API_ACCOUNT='C0543'; private $API_PASSWORD='ItFBqxd2ed'; public function __construct(){ } function sendSMS($mobile,$msg,$need_status = 1){ //发送短信的接口参数 $post_data = array ( 'un' => $this->API_ACCOUNT, 'pw' => $this->API_PASSWORD, 'msg' => $msg, 'phone' => $mobile, 'rd' => $need_status ); $result = $this->curl_post($this->API_SEND_URL,http_build_query($post_data)); $result=preg_split("/[,\r\n]/",$result); return $result; } function send_state($state){ //返回的状态码 $statusStr = array( '0' =>'发送成功', '101'=>'无此用户', '102'=>'密码错', '103'=>'提交过快', '104'=>'系统忙', '105'=>'敏感短信', '106'=>'消息长度错', '107'=>'错误的手机号码', '108'=>'手机号码个数错', '109'=>'无发送额度', '110'=>'不在发送时间内', '111'=>'超出该账户当月发送额度限制', '112'=>'无此产品', '113'=>'extno格式错', '115'=>'自动审核驳回', '116'=>'签名不合法,未带签名', '117'=>'IP地址认证错', '118'=>'用户没有相应的发送权限', '119'=>'用户已过期', '120'=>'内容不是白名单', '121'=>'必填参数。是否需要状态报告,取值true或false', '122'=>'5分钟内相同账号提交相同消息内容过多', '123'=>'发送类型错误(账号发送短信接口权限)', '124'=>'白模板匹配错误', '125'=>'驳回模板匹配错误', '128'=>'内容解码失败' ); return $statusStr[$state]; } function curl_post($url, $post_data) { $ch = curl_init(); $timeout = 300; curl_setopt($ch, CURLOPT_URL, $url); //curl_setopt($ch, CURLOPT_REFERER, "http://api.dushiyangguan.com/"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt( $ch, CURLOPT_TIMEOUT,$timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } curl_close($ch); return $res; } }
相关推荐:
Atas ialah kandungan terperinci 253短信接口PHP直接调用. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!