public function indexAction() { /** * 发送模板短信 * @param to 手机号码集合,用英文逗号分开 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID */ function sendTemplateSMS($to, $datas, $tempId) { //主帐号,对应开官网发者主账号下的 ACCOUNT SID $accountSid = '8a48b551522ff93101523514f7e60ee8'; //主帐号令牌,对应官网开发者主账号下的 AUTH TOKEN $accountToken = '8fdb37dd47e14ce789baf8f0f4a3d067'; //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID //在开发调试的时候,可以使用官网自动为您分配的测试Demo的APP ID $appId = '8a48b551522ff931015235170d2b0ef6'; //请求地址 //沙盒环境(用于应用开发调试):sandboxapp.cloopen.com //生产环境(用户应用上线使用):app.cloopen.com $serverIP = 'sandboxapp.cloopen.com'; //请求端口,生产环境和沙盒环境一致 $serverPort = '8883'; //REST版本号,在官网文档REST介绍中获得。 $softVersion = '2013-12-26'; // 初始化REST SDK // global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion; $rest = new \Rest($serverIP, $serverPort, $softVersion); $rest->setAccount($accountSid, $accountToken); $rest->setAppId($appId); // 发送模板短信 echo "Sending TemplateSMS to {$to} <br/>"; $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { echo "result error!"; break; } if ($result->statusCode != 0) { echo "error code :" . $result->statusCode . "<br>"; echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; echo "dateCreated:" . $smsmessage->dateCreated . "<br/>"; echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>"; //TODO 添加成功处理逻辑 } } //Demo调用 //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* sendTemplateSMS("13890290780", array('6532', '5'), "1"); //手机号码,替换内容数组,模板ID }
/** * 忘记密码发送验证码 do_forget * @param null $telephone * @return bool|int */ public function do_forget($telephone = NULL) { if ($this->create('', self::MODEL_FORGET_PASSWORD)) { /* 定义变量 */ $code = rand('100000', '999999'); $content = array($code, C('API_SMS.lost_time') / 60); $template = 36688; /* 手机号码,替换内容数组,模板ID */ $resultSMS = sendTemplateSMS($telephone, $content, $template); if ($resultSMS->statusCode == 0) { return $code; } } return false; }
<?php require "../include/SendTemplateSMS.php"; require "../include/get_data.php"; $phone = $arr['phone']; $auth_code = rand(1000, 9999); if ($phone != null) { sendTemplateSMS($phone, array($auth_code), 1); //sendTemplateSMS("15800651149",array('7863','4'),1); $return_arr = ["phone" => $phone, "auth_code" => (string) $auth_code]; include "../include/return_data.php"; } else { echo json_encode(0); }
public function send_sms() { /*if(!$this->isPost()){ $this->error('不给你看'); }*/ require './Public/SendSMS/SendTemplateSMS.php'; header("Content-type: text/html; charset=utf-8"); sendTemplateSMS("13627682184", array('6532', '5'), "1"); //手机号码,替换内容数组,模板ID }
/** * 系统重置密码 获取验证码 */ public function resetpasswd_post() { $this->load->model('user_model'); $data = $this->_post_args; try { // 手机号必须 if (!isset($data['tel'])) { throw new Exception('手机号码必须', 400); } // test code // 判断手机号是否合法 if (!preg_match("/1[3458]{1}\\d{9}\$/", $data['tel'])) { throw new Exception('不符合规范的手机号码', 400); } // 判断此手机号码是否已经注册过 $user_ifexist = $this->user_model->getUser(array('tel' => $data['tel'])); if (!$user_ifexist) { throw new Exception('手机号码不存在系统中', 409); // test code } $this->load->helper('encrypt'); // 判断此手机号最后一条验证码是否存在 如果存在并且时间间隔小于配置时间 则提示警告 $verifycode = $this->user_model->getUserCode(array('tel' => $data['tel'], 'type' => 2)); if ($verifycode && strtotime(date('Y-m-d H:i:s', time())) - strtotime($verifycode['createtime']) < REPLAYSMSTIME) { throw new Exception('验证码已经发送到您的手机', 400); } // 判断此手机号码今天发送的验证码条数<=3条 $codenum = $this->user_model->getUserCodeListTodayTotal(array('tel' => $data['tel'])); if ($codenum >= 3) { throw new Exception('已达到今天最大发送条数,请您明日再试', 400); } $verifyCodeRand = encrypt_build_rand_password(1, 4); // 数字密码 4位长度 $id = $this->user_model->createUserCode(array('tel' => $data['tel'], 'code' => $verifyCodeRand, 'type' => 2, 'createtime' => date('Y-m-d H:i:s', time()))); } catch (Exception $e) { $this->response(array('error' => $e->getMessage()), $e->getCode()); } if ($id) { $usercode = $this->user_model->getUserCode(array('id' => $id, 'type' => 2)); // 短信通道 发送短信START $this->load->helper('sendsms'); $smsconfig = $this->config->item('SMSCHANNEL'); if ($smsconfig['enable']) { sendTemplateSMS($data['tel'], array($verifyCodeRand, '1'), "48629"); // 手机号码,替换内容数组,模板ID } $this->response($usercode, 201); // 201 being the HTTP response code } else { $this->response(array('error' => '密码重置失败'), 404); } }
global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion; $rest = new REST($serverIP, $serverPort, $softVersion); $rest->setAccount($accountSid, $accountToken); $rest->setAppId($appId); // 发送模板短信 // echo "Sending TemplateSMS to $to <br/>"; $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { echo 0; } if ($result->statusCode != 0) { // echo "error code :" . $result->statusCode . "<br>"; // echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { // echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; // echo "dateCreated:".$smsmessage->dateCreated."<br/>"; // echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>"; //TODO 添加成功处理逻辑 } } //Demo调用 //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* sendTemplateSMS("", array('', ''), ""); //手机号码,替换内容数组,模板ID
$rest = new REST($serverIP, $serverPort, $softVersion); $rest->setAccount($accountSid, $accountToken); $rest->setAppId($appId); // 发送模板短信 echo "Sending TemplateSMS to {$to} <br/>"; $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { echo "result error!"; break; } if ($result->statusCode != 0) { echo "error code :" . $result->statusCode . "<br>"; echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; echo "dateCreated:" . $smsmessage->dateCreated . "<br/>"; echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>"; //TODO 添加成功处理逻辑 } } //Demo调用 //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* sendTemplateSMS("13890290780", array('666', '5'), "1"); //手机号码,替换内容数组,模板ID
//echo "result error!"; //break; } if ($result->statusCode != 0) { //echo "error code :" . $result->statusCode . "<br>"; //echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 if ($result->statusCode == 160021) { $output['return'] = 1; } } else { //echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 //$smsmessage = $result->TemplateSMS; //echo "dateCreated:".$smsmessage->dateCreated."<br/>"; //echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>"; //TODO 添加成功处理逻辑 $output['return'] = 1; } echo json_encode($output); exit; } //Demo调用 //http://members_api.域名.com/members/service/SendTemplateSMS.php?appid=&accountsid=&accounttoken=&phone={$mobile}&content={$content}&tplid=模板id //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* sendTemplateSMS($_GET['phone'], array($_GET['content'], $_GET['time']), $_GET['tplid']); //手机号码,替换内容数组,模板ID
//if ($code != $_SESSION["code"]) { // operation_fail("验证码验证失败:". $_SESSION["code"]); //} $phone = param("phone"); if ($phone == null || strlen($phone) < 8) { operation_fail("手机号码不能为空或者位数不对"); } $r = VerifyCodeModel::getCodeByPhone($phone); if ($r != null) { // 如果已有验证码,并且还未超过1分钟 if ($r['status'] == 0 && strtotime($r[time]) + 60 > time()) { operation_fail("验证码请间隔1分钟再重试"); } } $code = rand(1000, 9999); $timeout = 1; //json_put("code", $code); $result = sendTemplateSMS($phone, array($code, $timeout), "1"); if ($result == FALSE) { operation_fail("发送验证码失败,请重试"); } else { $r = VerifyCodeModel::updateOrInsertVerifyCode($phone, $code); if ($r == FALSE) { operation_fail("发送验证码失败,请重试"); } } json_put("result", "验证码已下发,请查收"); json_output(); ?>
break; } if ($result->statusCode != 0) { // echo "error code :" . $result->statusCode . "<br>"; // echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { // echo "voiceverify success!<br>"; // 获取返回信息 $voiceVerify = $result->VoiceVerify; // echo "callSid:".$voiceVerify->callSid."<br/>"; // echo "dateCreated:".$voiceVerify->dateCreated."<br/>"; //TODO 添加成功处理逻辑 } } sendTemplateSMS("18813293819", array('666666', '5'), "1"); // voiceVerify("666666","3","18813293819","18813293819","http://121.42.62.105:6080","zh","18813293819"); /* * Copyright (c) 2014 The CCP project authors. All Rights Reserved. * * Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license * that can be found in the LICENSE file in the root of the web site. * * http://www.yuntongxun.com * * An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ class REST {
public function sendmessage($phone_string, $verification_code_string) { $result = sendTemplateSMS($phone_string, array($verification_code_string, '5'), "1"); }
echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; echo "dateCreated:".$smsmessage->dateCreated."<br/>"; echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>"; //TODO 添加成功处理逻辑 } */ } //Demo调用 //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* $mobile = $_GET[mobile]; $validation = $_GET[validation]; $timeout = $_GET[timeout] ? $_GET[timeout] : '60'; $template = $_GET[template]; //获取验证码 /* 74317,发验证码 74318,发密码 75704,验证码登录,发验证码 75705,dev网站的验证码登录,发验证码 */ if (!$template) { $template = '74317'; } sendTemplateSMS($mobile, array($validation, $timeout), $template); //手机号码,替换内容数组,模板ID
// 发送模板短信 echo "Sending TemplateSMS to {$to} <br/>"; $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { echo "result error!"; break; } if ($result->statusCode != 0) { echo "error code :" . $result->statusCode . "<br>"; echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 } else { echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; echo "dateCreated:" . $smsmessage->dateCreated . "<br/>"; echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>"; //TODO 添加成功处理逻辑 } } //Demo调用 //**************************************举例说明*********************************************************************** //*假设您用测试Demo的APP ID,则需使用默认模板ID 1,发送手机号是13800000000,传入参数为6532和5,则调用方式为 * //*result = sendTemplateSMS("13800000000" ,array('6532','5'),"1"); * //*则13800000000手机号收到的短信内容是:【云通讯】您使用的是云通讯短信模板,您的验证码是6532,请于5分钟内正确输入 * //********************************************************************************************************************* header("Content-Type:text/html;charset=utf-8"); $phone = "18328421570"; $num = "4567"; sendTemplateSMS("{$phone}", array("{$num}", '5'), "1"); //手机号码,替换内容数组,模板ID
public function sendPhoneReg() { include "./PhoneMessage/CCPRestSmsSDK.php"; //2 接受手机号码 $phone = I('post.phone'); //3 设置验证码的长度与类型,以及时间 $code = randCode(4, 1); $time = 2; //4 调用方法 $res = sendTemplateSMS($phone, array($code, $time), "1"); //手机号码,替换内容数组,模板ID //5 判断返回信息 if ($res['sign'] == 1) { //设置cookie session('code', $code); } //6 返回json数据 $this->ajaxReturn(json_encode($res)); }