php调用云片网接口发送短信的实现方法

2025-05-29 0 111

php调用云片网接口发送短信的实现方法

云片网发送短信

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30
/**

* [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];

}

云片短信接口文档:http://www.yunpian.com/api2.0/api-domestic/single_send.html

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

原文链接:http://blog.csdn.net/qq_34827048/article/details/70237543

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 php调用云片网接口发送短信的实现方法 https://www.kuaiidc.com/93296.html

相关文章

发表评论
暂无评论