Implementation method of sending short message by php calling cloud chip network interface

  • 2021-08-10 07:11:43
  • OfStack

Implementation method of php calling cloud chip network interface to send short message

Cloud film network sends short messages


/**
   * [SendSms description]
   * @param [string] $tpl_content [ Content of SMS sent ]
   * @param     $send_mobile [ Mobile phone number sent ]
   */
  public function SendSms($tpl_content,$send_mobile)
  {
    $this->yunpian_appkey = env('yunpian_appkey');// Cloud film account appkey
    $this->yunpian_secret = env('yunpianSecretXYZ');// Cloud film account secret
    // Initialization 
    $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);
    // Parsing returns the result ( json Format string) 
    $backmassage = json_decode($send_data,true);
    echo '$backmassage ';
    // This is written in job So there is a log that can be ignored! 
    Log::info('smsmessagelog: '.$send_data);
    return [$backmassage,$send_data];
  }

Cloud chip SMS interface document: http://www.yunpian.com/api2.0/api-domestic/single_send. html

If you have any questions, please leave a message or go to this site community to exchange and discuss, thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: