public function sendToCustomer($customerId)
 {
     $customer = Customer::findOrFail($customerId);
     $message = Input::get('message');
     if (trim($message)) {
         if ($customer->phone) {
             \Sms::send_sms($customer->phone, $message);
         }
     }
     if (!\Sms::error()) {
         \Session::flash('success', 'Sms sent!');
     } else {
         \Session::flash('error', 'Failed!');
     }
     return \Redirect::back();
 }
Exemple #2
0
 /**
  * 生成短信验证码接口
  * AJAX
  * apikey 为云片分配的apikey
  * text 为短信内容
  * mobile 为接受短信的手机号
  */
 public function send_auth_code()
 {
     $info = array('status' => false, 'msg' => '验证码发送失败!');
     // $apikey = "06ec231c5d876ffe119b38013662f661";   // todo  短信接口部署时,需修改这里的APIKEY
     $phoneNumber = Filter::int(Req::args("mobile"));
     $config_inst = Config::getInstance();
     $config = $config_inst->get("sms");
     $apikey = $config['api_key'];
     $authChars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     //验证码生成
     $authCode = '';
     for ($i = 0; $i < 4; $i++) {
         $authCode .= substr($authChars, mt_rand(0, strlen($authChars) - 1), 1);
     }
     $authCode = strtolower($authCode);
     // 变成小写
     // $text = "【全品电台】您的验证码是".$authCode;
     $text = "【全品电台】感谢您的注册,您的验证码是 {$authCode} 。有效期为3分钟,请尽快验证";
     //$text = "【云片网】您的验证码是".$authCode;
     Tiny::log(__FILE__ . '--' . __LINE__ . '--' . $phoneNumber . "--" . $authCode . "--" . $text);
     //验证码与手机号码绑定
     $model = $this->model->table("auth_code");
     $obj = $model->where('phone_number=' . $phoneNumber)->find();
     $time = date('Y-m-d H:i:s', strtotime("+3 minutes"));
     if ($obj == null) {
         $data['phone_number'] = $phoneNumber;
         $data['auth_code'] = $authCode;
         $data['start_time'] = date('Y-m-d H:i:s');
         $data['end_time'] = $time;
         $auth_code_id = $this->model->table("auth_code")->data($data)->insert();
         if ($auth_code_id) {
             //发送验证码,发送成功
             //Tiny::log("auth_code 表 ID--".$auth_code_id);
             // todo SKM 要发短信验证码时,把下面注释去掉
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             // todo SKM SMS服务正式提供后,把下面一行代码注释掉
             //$ret = array('code' => 0, 'msg' => 'OK');
             if (isset($ret['code']) && $ret['code'] == 0) {
                 $info['status'] = true;
                 //$info['msg'] = "发送验证码成功!短信API接口返回:".$ret['msg'];
                 $info['msg'] = "发送验证码成功!";
             } else {
                 $info['status'] = false;
                 //$info['msg'] = "发送验证码失败!短信API接口返回:".$ret['msg'];
                 Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "短信接口发送失败:" . var_export($ret, true));
                 $info['msg'] = "发送验证码失败!";
             }
             echo JSON::encode($info);
         } else {
             // 插入失败
             Tiny::log(__FILE__ . '-' . __LINE__ . '-' . "插入失败:auth_code--" . $auth_code_id);
             echo JSON::encode($info);
         }
     } else {
         // 1分钟内不能发送2次验证码
         $expired_time = strtotime("+3 minutes", intval($obj['start_time']));
         if ($expired_time > strtotime(date('y-m-d h:i:s'))) {
             $info['status'] = false;
             $info['msg'] = "两次验证码发送间隔不能少于60秒!";
             echo JSON::encode($info);
         } else {
             // 已经存在验证码,更新验证码, 从新发送到手机上
             $obj['auth_code'] = $authCode;
             $obj['start_time'] = date('Y-m-d H:i:s');
             $obj['end_time'] = $time;
             $model->data($obj)->update();
             // 重新发送
             $sms = new Sms();
             $ret = $sms->send_sms($apikey, $text, $phoneNumber);
             //$ret = array('code' => 0, 'msg' => 'OK');
             $info['status'] = true;
             $info['msg'] = "发送验证码成功!";
             echo JSON::encode($info);
         }
     }
 }
Exemple #3
0
function send_sms_admin($order_id)
{
    $sms_api_options = get_sms_api_options();
    if (count($sms_api_options) > 0) {
        //$from_sms_send = '79224717444';
        $from_sms_send = $sms_api_options['sms_api_phone'];
        $user_for_send = DB::GetQueryResult("SELECT * FROM `user` WHERE `rang` = 'admin' OR `rang` = 'operator' AND sms = 1", false);
        $send = new Sms($sms_api_options['sms_api_username'], $sms_api_options['sms_api_password']);
        foreach ($user_for_send as $one) {
            if ($one['phone'] != '' && strlen($one['phone']) > 5) {
                $sms_body = 'В системе заказов новый необработанный заказ или сообщение';
                $text_master_send = iconv('utf-8', 'utf-8', $sms_body);
                //Отправляем смс если она не была отправлена ранее
                $result = $send->send_sms($text_master_send, $one['phone'], $from_sms_send);
            }
        }
    }
}