首頁  >  文章  >  後端開發  >  php呼叫雲片網介面發送簡訊的實作方法

php呼叫雲片網介面發送簡訊的實作方法

小云云
小云云原創
2017-11-08 11:01:501313瀏覽

php呼叫雲端片網介面傳送簡訊的實作方法

/**
   * [SendSms description]
   * @param [string] $tpl_content [发送的短信内容]
   * @param     $send_mobile [发送的手机号码]
   */
  public function SendSms($tpl_content,$send_mobile)
  {
    $this->yunpian_appkey = env('yunpian_appkey');//云片账户appkey
    $this->yunpian_secret = env('yunpianSecretXYZ');//云片账户secret
    //初始化
    $ch    = curl_init();
    $data=array('text'=>$tpl_content,'apikey'=>$this->yunpian_appkey,'mobile'=>$send_mobile);
    curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    $send_data = curl_exec($ch);
    curl_close($ch);
    //解析返回结果(json格式字符串)
    $backmassage = json_decode($send_data,true);
    echo '$backmassage ';
    //这里是写在了job里面所以记了个日志可忽略!
    Log::info('smsmessagelog: '.$send_data);
    return [$backmassage,$send_data];
  }

 


#

以上是php呼叫雲片網介面發送簡訊的實作方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn