本文整理匯總了PHP中Sms::send_sms方法的典型用法代碼示例。如果您正苦於以下問題:PHP Sms::send_sms方法的具體用法?PHP Sms::send_sms怎麽用?PHP Sms::send_sms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sms
的用法示例。
在下文中一共展示了Sms::send_sms方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendToCustomer
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();
}
示例2: send_auth_code
/**
* 生成短信驗證碼接口
* 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);
}
}
}
示例3: send_sms_admin
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);
}
}
}
}