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.調用短信接口發送短信
$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觸發命令。直接后臺執行。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com