TypechoJoeTheme

Dcr163的博客

统计

阿里短信服务PHP 发送短信验证码实例

2017-10-08
/
0 评论
/
629 阅读
/
正在检测是否收录...
10/08
/**
 * 新版阿里大于的发送 appcode 方式
 * @param  [type] $code   [验证码]
 * @param  [type] $mobile [目标手机号码]
 * @return [type]         [状态]
 */
function dayuSend($code,$mobile){

   $host = "http://sms.market.alicloudapi.com";
   $path = "/singleSendSms";
   $method = "GET";
   $appcode = "xxxxxxx";      //短信平台appcode,,替换成自己的
   $headers = array();
   array_push($headers, "Authorization:APPCODE " . $appcode);

   $request_paras = array(
      'ParamString' => '{"code":"'.62544.'"}',        //模板代码的变量,根据自己的模板进行修改
      'RecNum' => '13800000000',                            //发送的目标手机号码
      'SignName' =>'xxxx',                        //短信签名,替换成自己的
      'TemplateCode' => 'SMS_1010600701'               //短信模板Code,替换成自己的
   );
   $rlt = '';

   foreach ($request_paras as $k => $v) {
      $rlt .= urlencode($k) . '=' . urlencode($v) . '&';
   }

   $querys = $rlt;
   $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);
   }
   $info = curl_exec($curl);
   curl_close($curl);

   //查询返回的状态
   $s = strpos($info,'{') ;
   $e = strpos($info,'}') + 1;
   $info = json_decode(substr($info, $s,$e),true);
   return $info;
}


朗读
赞(0)
版权属于:

Dcr163的博客

本文链接:

http://dcr163.cn/171.html(转载时请注明本文出处及文章链接)

评论 (0)

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. slot mpo terbaru
    2025-02-08
  2. Sherry Stockdill
    2025-01-28
  3. slot demo
    2025-01-13
  4. 陌天
    2025-01-09
  5. Kerrie Bostick
    2024-12-28

标签云