php用不同平台批量发短信的方法
1.首先将需要发送信息的手机号存入redis缓存
$redis = new \redis(); $conn = $redis->connect('localhost', 6379); $auth = $redis->auth('*****'); //redis设置了密码,需要认证 $list = Testuser::find()->asarray()->all(); for ($i=0; $i < count($list); $i++) { $redis->lpush('list',$list[$i]['email']); }
将所需发送的手机号存入到redis缓存中
推荐:《PHP教程》
2.调用短信接口发送短信
立即学习“PHP免费学习笔记(深入)”;
$redis = new \redis(); $conn = $redis->connect('localhost', 6379); $auth = $redis->auth('*****'); $lenth = $redis->llen('list'); for ($i=0; $i < $lenth ; $i++) { $phone = $redis->brpop('list',1,60);//从结尾处弹出一个值,超时时间为60s $phonenumber = $phone[1]; $sendmsg = send($phonenumber); if($sendmsg){ //处理发送成功的逻辑 }else{ //处理发送失败的逻辑 } usleep(500000);//微秒,调用第三方接口,需要注意频率, }
这里结合php的cli模式,通过函数exec触发命令。直接后台执行。
以上就是php用不同平台批量发短信的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号