php用不同平臺批量發(fā)短信的方法
1.首先將需要發(fā)送信息的手機(jī)號存入redis緩存
$redis = new \redis(); $conn = $redis->connect('localhost', 6379); $auth = $redis->auth('*****'); //redis設(shè)置了密碼,需要認(rèn)證 $list = Testuser::find()->asarray()->all(); for ($i=0; $i < count($list); $i++) { $redis->lpush('list',$list[$i]['email']); }
將所需發(fā)送的手機(jī)號存入到redis緩存中
推薦:《PHP教程》
2.調(diào)用短信接口發(fā)送短信
$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);//從結(jié)尾處彈出一個(gè)值,超時(shí)時(shí)間為60s $phonenumber = $phone[1]; $sendmsg = send($phonenumber); if($sendmsg){ //處理發(fā)送成功的邏輯 }else{ //處理發(fā)送失敗的邏輯 } usleep(500000);//微秒,調(diào)用第三方接口,需要注意頻率, }
這里結(jié)合php的cli模式,通過函數(shù)exec觸發(fā)命令。直接后臺執(zhí)行。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com