php短信验证码接口代码示例(简单、易用)

今天给大家分享的代码示例是秒赛短信验证码平台为方便用户接入网站/app/各种系统,提供的PHP短信接口请求的代码示例,供大家参考。

PHP短信接口代码具体内容如下:

<?php
header("Content-Type:text/html;charset=utf-8");

//账号
$account = "***************"; 

//密码
$pswd = "***************"; 

//修改为您要发送的手机号
$mobile = "***************"; 

//发送地址,请咨询客服
$url = "***************"; 

//是否需要状态报告,为true即可
$needstatus = "true"; 

//产品,为空即可
$product = ""; 

$ch = curl_init();

/* 设置验证方式 */
curl_setopt($ch, CURLOPT_HTTPHEADER, 
array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded','charset=utf-8'));

/* 设置返回结果为流 */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

/* 设置超时时间*/
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

/* 设置通信方式 */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


// 发送短信
$msg="【秒赛科技】您的验证码是:1234";  
$data=array('msg'=>$msg,'account'=>$account,'pswd'=>$pswd,'mobile'=>
$mobile,'needstatus'=>$needstatus,'product'=>$product);
$result = send($ch,$data);
echo '<pre>';print_r($result);

curl_close($ch);

/***************************************************************************************/


//验证码
function send($ch,$data){
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    return curl_exec($ch);
}


?>

猜你喜欢

转载自blog.csdn.net/qq_42388208/article/details/80609288