在 Laravel 中向用户手机发送生日短信,在 Laravel 中向用户手机发送生日、周年纪念短信短信设置?

Sending Bithday SMS to user mobile in Laravel and Birthday, Anniversary sms Text message setting in Laravel?

我们如何使用 Laravel 框架在用户移动设备中使用消息文本发送生日和周年纪念短信,例如我们可以创建多条要触发的短信以及生日或周年纪念日之前的天数??

在 Laravel 中使用 Cronjobs 你可以通过制作一个 SMSController 来轻松做到这一点(这里我们使用两个表 clients 和 sms_settings) 代码是:

class SMSController extends Controller{


 public function test(Request $request){

 $date =Carbon::now(); //current system date now

 $date = $date->format('m/d');

  // For Birthday SMS

  $schedule = DB::table('sms_settings')->select('scheduled_type','number_of_days')->where('occasion','Birthday')->get();    
  foreach($schedule as $key=>$results){
  $number_of_days = $results->number_of_days;
  $scheduled_type = $results->scheduled_type;


   // select clients with dob 

    if($scheduled_type=='Before'){



  $required_date  = Carbon::now()->addDays($number_of_days);

    }

  if($scheduled_type=='After'){



  $required_date  = Carbon::now()->subDays($number_of_days);

      }




 $required_month = $required_date->format('m');
 $required_day = $required_date->format('d');

 $req = $required_month."-".$required_day;




 $results = DB::table('clients')->select('dob','mobile','first_name','last_name')->where('dob','LIKE','%'.$req.'%')->get();

 $r1 = DB::table('clients')->select('dob','mobile','first_name','last_name')->where('dob','LIKE','%'.$req.'%')->first();




 if(!$r1=null)
  {  
foreach($results as $key=>$result)
 {

   $dob = $result->dob;
  $mobile_list = $result->mobile;
  $first_name = $result->first_name;
  $last_name = $result->last_name;
  // dd($mobile_list);




   $a =   DB::table('sms_settings')->select('message_header','message')->where('occasion','Birthday')->get();


    foreach($a as $key=>$results){
    $header = $results->message_header;
    $mbody = $results->message;
       }

   $message_text = $header." ".$first_name.","."\n". $mbody;



$authKey = urlencode('Your Auth Key');
// Message details
$mobiles = array($mobile_list);
$sender = urlencode('123456');
$message = rawurlencode($message_text);
$route=2;
$country=5;

$mobiles = implode(',', $mobiles);


// Prepare data for POST request
$data = array('authkey' => $authKey, 'mobiles' => $mobiles, "message" => $message, "sender" => $sender,"route" =>$route,"country" =>$country );

// Send the POST request with cURL
$ch = curl_init('your url');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Process your response here

}

// Execute it via performing cronjobs




  }

 }

//周年纪念短信同上

最后,您必须将您的 Cron 条目输入到您的服务器,并通过将 Laravel 中 Kernel.php 文件上的计划方法作为目标来调用它:

 protected function schedule(Schedule $schedule){

$schedule->call('App\Http\Controllers\SMSController@test')->everyMinute();

 // Perform your task every minutes.

  }