騰訊雲短信SDK-精簡版


/**
    * 騰訊雲短信SDK-精簡版
    * 本模塊使用-向騰訊雲短信服務器發送請求
    * @return json 騰訊服務器返回值-json字符串
    */  
  private function send_sms($nationCode, $phoneNumber, $content) {
     
      $sdkappid = config('SMS_APP_ID');  // 申請的APP_ID
      $appkey   = config('SMS_APP_KEY');   // 申請的APP_KEY
      $url      = "https://yun.tim.qq.com/v3/tlssmssvr/sendsms"; // 基礎地址
      $wholeUrl = $url."?sdkappid=".$sdkappid."&random=".Session::get('sms_code'); //完成的訪問地址

      $tel = new \stdClass();
      $tel->nationcode = $nationCode;                // 手機區域碼 中國內地為86
      $tel->phone = $phoneNumber;                    // 用戶手機
      $jsondata = new \stdClass();
      $jsondata->tel = $tel;                        // 結構數據
      $jsondata->type = "0";                        // 請求模式
      $jsondata->msg = $content;                    // 具體短信內容 
      $jsondata->sig = md5($appkey.$phoneNumber);   // 生成簽名
      $jsondata->extend = "";                       // 根據需要添加,一般保持默認
      $jsondata->ext = Session::get('sms_code');     // 根據需要添加,一般保持默認

      $curlPost =json_encode($jsondata);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $wholeUrl);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      $ret = curl_exec($ch);
      if($ret === false) {
        return  curl_error($ch);
      } else {
          $json = json_decode($ret);
          if($json === false) {
            return  $ret;
          } else {
            return  $json;
          }
      }
      curl_close($ch);
  } 

$nationCode -------- 區號 。國內使用86

$phoneNumber ------------- 手機號碼
$content ------------ 模板。具體的短信內容
親測可用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM