php-调用阿里云第三方短信接口

  1. 去云市场找一个短信接口
    https://market.aliyun.com/products/56928004/cmapi023305.html?spm=5176.2020520132.101.7.791372187l0Zqa

  2. 购买短信包

  3. 找到自己的appcode,进入 管理控制台找到自己的appcode
    php-调用阿里云第三方短信接口_第1张图片
    php-调用阿里云第三方短信接口_第2张图片

  4. 调用接口即可

<?php
    $host = "http://dingxin.market.alicloudapi.com";
    $path = "/dx/sendSms";
    $method = "POST";
    $appcode = "你自己的AppCode";
    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    $querys = "mobile=159xxxx9999¶m=code%3A1234&tpl_id=TP1711063";
    $bodys = "";
    $url = $host . $path . "?" . $querys;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, true);
    if (1 == strpos("$".$host, "https://"))
    {
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    var_dump(curl_exec($curl));
?>

你可能感兴趣的:(php)