chenrunxuan
/**
    * 腾讯云短信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 ------------ 模板。具体的短信内容
亲测可用。

分类:

技术点:

相关文章:

  • 2021-11-23
  • 2021-08-20
  • 2021-08-18
  • 2021-11-23
  • 2021-11-23
  • 2021-12-15
猜你喜欢
  • 2021-12-19
  • 2021-11-23
  • 2021-11-23
  • 2021-07-15
  • 2021-12-05
  • 2021-12-15
相关资源
相似解决方案