漏刻有时API接口实战开发系列(9):短信宝短信接口php开发及调用

封装函数

function sendSMS($phone, $content)
{
    $statusStr = array(
        "0" => "短信发送成功",
        "-1" => "参数不全",
        "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
        "30" => "密码错误",
        "40" => "账号不存在",
        "41" => "余额不足",
        "42" => "帐户已过期",
        "43" => "IP地址限制",
        "50" => "内容含有敏感词"
    );

    $webAPI = array(
        "smsapi" => "http://www.smsbao.com/", //短信网关
        "user" => "YOUR NAME", //短信平台帐号
        "pass" => md5("YOUR PASS"), //短信平台密码
        "content" => $content,//要发送的短信内容
        "phone" => $phone//接受手机号码;
    );

    //执行发送;
    $sendurl = $webAPI["smsapi"] . "sms?u=" . $webAPI["user"] . "&p=" . $webAPI["pass"] . "&m=" . $webAPI["phone"] . "&c=" . urlencode($webAPI["content"]);
    $result = file_get_contents($sendurl);
    return $statusStr[$result];
}

调用函数

//调用函数;
$code = substr(md5(time()), 6, 6);
$content = "【漏刻有时】尊敬的用户,您的验证码是" . $code . ",请于10分钟内正确输入。如非本人操作,请忽略此短信。";
$result = sendSMS("135***", $content);

Done!

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页