コード例 #1
0
ファイル: SmsTopUp.php プロジェクト: klsandbox/SmsManager
 public function fire()
 {
     $this->comment('top up ');
     $balance = SmsBalance::first();
     if (!$balance) {
         $this->error('Sms Balance not found');
         return;
     }
     $amount = $this->argument('amount');
     $balance->TopUp($amount, 'Top Up From Console');
 }
コード例 #2
0
ファイル: SmsSender.php プロジェクト: klsandbox/SmsManager
 public function send($route, $target_id, \Illuminate\Database\Eloquent\Model $user, \Illuminate\Console\Command $command)
 {
     $messageObject = $this->getMessage($route, $target_id, $user, $command);
     $note = "message:{$messageObject->message} - to:{$messageObject->to} - number:{$messageObject->receiver_number}";
     $sms_host = Config::get('sms-manager.host');
     $sms_route = Config::get('sms-manager.route');
     $sms_username = urlencode(Config::get('sms-manager.username'));
     $sms_password = urlencode(Config::get('sms-manager.password'));
     $sms_sender = urlencode(Config::get('sms-manager.sender'));
     $sms_type = urlencode(Config::get('sms-manager.type'));
     $message = urlencode($messageObject->message);
     $url = "http://{$sms_host}/{$sms_route}?username={$sms_username}&password={$sms_password}&message={$message}&mobile={$messageObject->receiver_number}&sender={$sms_sender}&type={$sms_type}";
     $command->comment("SMS - {$note} - url:{$url}");
     if (Config::get('sms-manager.pretend')) {
         $command->comment("pretend - {$note} - url:{$url}");
     } else {
         $response = file_get_contents($url);
         if ($command->option('verbose')) {
             $command->comment('response:' . $response);
         }
         if (preg_match('/^1701/', $response)) {
             $balance = SmsBalance::first();
             $balance->Spend($note);
             return $response;
         } elseif (preg_match('/^1704/', $response)) {
             $command->error('Insufficient Credits from provider');
         } elseif (preg_match('/^1705/', $response)) {
             $command->error('Invalid Mobile Number');
             $item = new InvalidPhone();
             $item->phone = $messageObject->receiver_number;
             $item->save();
         } else {
             $command->error('Unmatched Error:' . $response);
         }
     }
     return false;
 }