php调用云片网接口发送短信的实现方法
程序员文章站
2023-08-27 23:30:03
php调用云片网接口发送短信的实现方法
云片网发送短信
/**
* [sendsms description]
* @param [string...
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]; }
云片短信接口文档:
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇: 什么是亚罗号事件?发生的背景是什么