Exemplo n.º 1
0
 /**
  * 发送短信
  * @param string $mobile 手机号
  * @param string $content 短信内容
  * @param int $business_id 业务ID (可选,默认为0)
  * @param string $broker_id 经纪人ID (可选,默认为0)
  * @param string $user_id 用户ID (可选,默认为10000)
  * @return bool 是否已放入短信发送队列
  * */
 public function send($mobile, $content, $business_id = 0, $broker_id = 0, $user_id = 10000)
 {
     $sender = new SMS_Sender();
     return $sender->send($mobile, $content, $business_id, $broker_id, $user_id);
 }
    public function printView()
    {
        $recips = $successes = $failures = $archived = $blanks = array();
        list($recips, $blanks, $archived) = $this->getRecipients();
        if (empty($recips)) {
            print_message("Did not find any recipients with mobile numbers.  Message not sent.", 'error');
        } else {
            $message = $_POST['message'];
            if (empty($message) || strlen($message) > SMS_MAX_LENGTH) {
                print_message("Your message is empty or too long", "error");
                return;
            }
            $sendResponse = SMS_Sender::send($message, $recips);
            $success = $sendResponse['success'];
            $successes = $sendResponse['successes'];
            $failures = $sendResponse['failures'];
            if (!$success) {
                add_message('Failed communicating with SMS server - please check your config', 'failure');
                return;
            }
            if (!empty($successes) || !empty($failures)) {
                if (!empty($successes)) {
                    print_message('SMS sent successfully to ' . count($successes) . ' recipients');
                    $this->saveAsNote($successes, $message);
                }
                if (!empty($failures)) {
                    print_message('SMS sending failed for ' . count($failures) . ' recipients', 'failure');
                    ?>
					<p><b>Sending an SMS to the following recipients failed.  <span class="clickable" onclick="$('#response').toggle()">Show technical details</span></b></p>
					<div style="display: none" class="well error" id="response"><?php 
                    bam($sendResponse['rawrequest']);
                    bam($sendResponse['rawresponse']);
                    ?>
</div>
					<?php 
                    $persons = $failures;
                    require 'templates/person_list.template.php';
                }
            } else {
                // No check of the response - give a less confident success message
                print_message('SMS dispatched to ' . count($recips) . ' recipients');
                ?>
				<span class="clickable" onclick="$('#response').toggle()">Show SMS server response</span></b></p>
				<div class="hidden standard" id="response"><?php 
                $response;
                ?>
</div>
				<?php 
            }
        }
        if (!empty($archived)) {
            ?>
			<h4>Archived Recipients</h4>
			<p style="clear: both"><?php 
            echo count($archived);
            ?>
 of the intended recipients were not sent the message because they are archived.</p>
			<?php 
        }
        if (!empty($blanks)) {
            ?>
			<h4>Recipients with blank mobile number</h4>
			<p style="clear:both">The following persons were not sent the message because they don't have a mobile number recorded:</b>
			<?php 
            $persons = $blanks;
            $include_special_fields = FALSE;
            require 'templates/person_list.template.php';
        }
        if (empty($archived) && empty($blanks)) {
            ?>
			<a href="javascript:window.history.back()" class="btn"><i class="icon-chevron-left"></i> Back</a>
			<?php 
        }
    }