/** * 发送短信 * @param $smsFreeSignName 签名 * @param $smsParam 短信模板中的参数 : 例如:'{"code":"我爱你","product":"京西商城"}'; * @param $recNum 接收号码 * @param $smsTemplateCode 短信模板的编号 */ function sendSMS($smsFreeSignName, $smsParam, $recNum, $smsTemplateCode) { //加载vendor下的 阿里大鱼 vendor('Alidayu.TopSdk'); date_default_timezone_set('Asia/Shanghai'); $c = new TopClient(); //从配置文件中得到短信应用的配置 $sms_config = C('SMS_CONFIG'); //设置应用的APP_KEY $c->appkey = $sms_config['appkey']; //安全码 $c->secretKey = $sms_config['secretKey']; //发送短信的对象 $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); //短信类型. 必须要修改 $req->setSmsType("normal"); //短信签名 $req->setSmsFreeSignName($smsFreeSignName); //为短信模板中的变量赋值 $req->setSmsParam($smsParam); //接收短信的手机号 $req->setRecNum($recNum); //短信模板的编号 $req->setSmsTemplateCode($smsTemplateCode); // 验证码${code},您正在注册成为${product}用户,感谢您的支持! //发送短信 $resp = $c->execute($req); }
function sendSMSAli($mobile, $mobile_code, $time = '', $mid = '') { include "TopSdk.php"; $c = new TopClient(); $c->appkey = "23278568"; //这里填写您申请的appkey $c->secretKey = "87410133aa8ab0cdfd2ba521209a3793"; //这里填写您申请的secretKey $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); //填写什么都可以 $req->setSmsType("normal"); //短信类型,不用修改 $req->setSmsFreeSignName("注册验证"); //这里填写短信签名 $req->setSmsParam("{\"code\":\"{$mobile_code}\",\"product\":\"钰盈堂净颜梅\"}"); //按要求引入变量 $req->setRecNum($mobile); //接收短信的手机变量 $req->setSmsTemplateCode("SMS_2950020"); //这里填写短信模板编号 $resp = $c->execute($req); $reArray = xmlToArray($resp); //返回结果 if (isset($reArray["code"]) && $reArray["code"] > 0) { return false; } else { return true; } }
function sendSMSAli($mobile, $mobile_code, $time = '', $mid = '') { include "TopSdk.php"; $c = new TopClient(); $c->appkey = "23294546"; //这里填写您申请的appkey $c->secretKey = "7f5f7a5d562089d01792ac5372f81d08"; //这里填写您申请的secretKey $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); //填写什么都可以 $req->setSmsType("normal"); //短信类型,不用修改 $req->setSmsFreeSignName("注册验证"); //这里填写短信签名 $req->setSmsParam("{\"code\":\"{$mobile_code}\",\"product\":\"技师达\"}"); //按要求引入变量 $req->setRecNum($mobile); //接收短信的手机变量 $req->setSmsTemplateCode("SMS_3991033"); //这里填写短信模板编号 $resp = $c->execute($req); $reArray = xmlToArray($resp); //返回结果 if (isset($reArray["code"]) && $reArray["code"] > 0) { return false; } else { return true; } }
public function send() { include_once __DIR__ . "/../../taobao-sdk-PHP-auto/TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $c = new \TopClient(); $c->appkey = $this->ak; $c->secretKey = $this->sk; $req = new \AlibabaAliqinFcSmsNumSendRequest(); $sessionKey = null; $req->setSmsType($this->smsType); $req->setSmsFreeSignName($this->smsFreeSignName); $req->setSmsParam($this->smsParam); $req->setRecNum($this->recNum); $req->setSmsTemplateCode($this->smsTemplateCode); $resp = $c->execute($req, $sessionKey); $json = json_encode($resp); $result = json_decode($json, TRUE); $this->result = $json; if (isset($result['result']['success'])) { $this->sended = 1; $this->sended_at = new \DateTime('NOW'); $this->save(); } else { $this->sended = 0; $this->sended_at = null; $this->save(); } return $result; }
/** * 短信发送的方法(单发) * @param string $cellPhone 目标手机号码 * @param string $smsSign 短信签名(允许的值:http://www.alidayu.com/admin/service/sign) * @param string $product 短信主体内容 * @param type $template 短信模板(允许的值:http://www.alidayu.com/admin/service/tpl) * @return stirng json格式的字符串 */ public function sendSms($cellPhone = '', $smsSign = '', $product = '', $template = 'SMS_4756069') { // 测试默认值 // $cellPhone = '15577375746'; $smsSign = '身份验证'; // $product = '陈培捷商城的(我手机号被限制了,用别的测试一下)'; if (empty($cellPhone)) { return false; // 缺少参数$cellphone } if (!@(include LIB_PATH . "Org/Aliyun/TopSdk.php")) { //引入淘宝SDK入口文件 return false; // 找不到对应文件 } $validTime = (int) 60; // 该次请求验证码有效时间 $code = rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9); // 6位随机验证码 // 60S不能再次发送 $nowTime = (int) time(); $Mo = M('system_message'); $where['method'] = array('EQ', 'sms'); $where['target'] = array('EQ', $cellPhone); $result = $Mo->field('send_time')->where($where)->order('send_time desc')->limit(1)->find(); $lastTime = (int) $result['send_time']; $remainingTime = $nowTime - $lastTime; $fail_data = ['remainingTime' => $remainingTime]; if ($remainingTime < $validTime) { return false; // 特定时间内不能重复发送手机验证码 } // 调用阿里大鱼API进行发送操作 $appkey = C('TAOBAO_KEY'); $secret = C('TAOBAO_SECRET'); $c = new \TopClient(); $c->appkey = $appkey; $c->secretKey = $secret; $req = new \AlibabaAliqinFcSmsNumSendRequest(); // $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName($smsSign); $req->setSmsParam(json_encode(['code' => $code, 'product' => $product])); $req->setRecNum($cellPhone); $req->setSmsTemplateCode($template); $resp = (array) $c->execute($req); $resp['result'] = (array) $resp['result']; // 成功后存入数据库中做记录 if (!empty($resp['result']['success']) && $resp['result']['success'] == 'true') { $nowTime = (int) time(); $insertData = ['method' => 'sms', 'type' => 'code', 'target' => (string) $req->getRecNum(), 'identification' => (string) $resp['request_id'], 'title' => (string) $req->getSmsFreeSignName(), 'content' => (string) $req->getSmsParam(), 'send_time' => $nowTime]; $Mo->data($insertData)->add(); $succ_data = ['smsCode' => $code, 'validTime' => $validTime, 'identification' => (string) $resp['request_id']]; return $succ_data; // 发送成功 } else { return false; // 阿里大鱼API导致的发送失败 } }
public function sendSMS($tel) { //>>1. 随机生成一个数字 $randomNumber = String::randString(6, 1); session('SMS_CODE', $randomNumber); //为了和用户输入的短信验证码进行验证码 //>>2.将该数字发送到$tel手机号D:\thinkphp\ThinkPHP\Library\Vendor\SMS vendor('SMS.TopSdk'); $c = new \TopClient(); date_default_timezone_set('Asia/Shanghai'); //设置时区 $c->appkey = '23268864'; //创建应用上面的appkey $c->secretKey = '69f0728011dec573eb02f3f57583cb80'; //创建应用上面的secretKey $req = new \AlibabaAliqinFcSmsNumSendRequest(); // $req->setExtend("123456"); $req->setSmsType("normal"); //不改变 $req->setSmsFreeSignName("注册验证"); //用来验证 $req->setSmsParam("{'code':'{$randomNumber}','product':'源代码商城'}"); $req->setRecNum($tel); //接收的电话 $req->setSmsTemplateCode("SMS_2345004"); //模板id $resp = $c->execute($req); //判定发送的状态 // return ((string)$resp->result->success)==='true'; return $resp->result->success; }
public function sendSms($mobile, $smsParams) { $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setSmsType("normal"); $req->setSmsFreeSignName(env('ALIDAYU_SIGN')); $req->setSmsParam(json_encode($smsParams)); $req->setRecNum($mobile); $req->setSmsTemplateCode(env('ALIDAYU_SMS')); return $this->topclient->execute($req); }
public function sendSms($phone, $code, $template_code, $sign, array $msg_param = null) { $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setSmsType('normal'); $req->setExtend($code); $req->setSmsFreeSignName($sign); if ($msg_param) { $msg_param_json = json_encode($msg_param); $req->setSmsParam($msg_param_json); } $req->setRecNum($phone); $req->setSmsTemplateCode($template_code); return $this->topclient->execute($req); }
public function send() { $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); //确定发给的是哪个用户,参数为用户id $req->setSmsType("normal"); $req->setSmsFreeSignName($this->name); $req->setSmsParam($this->content); //这里设定的是发送的短信内容:验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!” $req->setRecNum($this->phone); //参数为用户的手机号码 $req->setSmsTemplateCode($this->code); $resp = $this->TopClient->execute($req); return $resp; }
function send($mobile, $data, $template, $sign) { $a = (include APP_FILE . "use/alisdk/TopSdk.php"); $c = new TopClient(); $c->appkey = "23310798"; $c->secretKey = "754cbdbd9aeff8f64077d522420fc3cb"; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setSmsType("normal"); $req->setSmsFreeSignName($sign); //短信签名 $req->setSmsParam($data); $req->setRecNum($mobile); $req->setSmsTemplateCode($template); $resp = (array) $c->execute($req); return $resp['result']['err_code'] == 0; }
public static function sms($phone, $template, $smsParam = array()) { if (empty($phone)) { return false; } $smsInfo = Config::getConfig('sms_info'); $smsInfo = json_decode($smsInfo, true); $smsParam = json_encode($smsParam); $c = new \TopClient(); $c->appkey = $smsInfo['appkey']; $c->secretKey = $smsInfo['secretKey']; $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend($phone); $req->setSmsType("normal"); $req->setSmsFreeSignName($smsInfo['signName']); $req->setSmsParam($smsParam); $req->setRecNum($phone); $req->setSmsTemplateCode($template); $resp = $c->execute($req); return !!$resp->result->success; }
/** * 大鱼短信发送接口 * @param $mobile 接受信息的手机号码 * @param $content array 发送的信息 * @param $template 模板ID * @author copoet * * 示例如下: * 模板名称: 用户注册 * 模板ID: SMS_3990623 * 验证码${code},您正在注册成为${product}用户,感谢您的支持! * @return mixed|\ResultSet|\SimpleXMLElement */ public static function topSent($mobile, $content = array(), $template) { $config = self::getSmsConf(); //获取短信配置 $appkey = $config['appkey']; $secretKey = $config['secretkey']; $SignName = $config['signname']; //签名 vendor('Topsdk.TopSdk'); date_default_timezone_set('Asia/Shanghai'); $c = new \TopClient(); $code = json_encode($content); //内容转为json格式 $c->appkey = $appkey; $c->secretKey = $secretKey; $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend(""); $req->setSmsType("normal"); $req->setSmsFreeSignName("{$SignName}"); $req->setSmsParam("{$code}"); $req->setRecNum("{$mobile}"); $req->setSmsTemplateCode("{$template}"); $resp = $c->execute($req); $info = array(); if ($resp->result->success == true) { $info['status'] = 10; } else { $info['status'] = 20; } $info['provider_name'] = '阿里大鱼'; self::log_sms($mobile, $content['code'], $info['provider_name'], $info['status']); switch ($info['status']) { case 10: return true; case 20: return false; default: return false; } }
function sendSms($type, $phone, array $params = []) { $types = ['register_verify' => ["注册验证", "SMS_3690282"], 'forgot_password_verify' => ["变更验证", "SMS_3690280"], 'phone_change' => ["身份验证", "SMS_3690285"], 'invite_registered' => ['智艺创想', 'SMS_5200318'], 'invite_anonymous' => ['智艺创想', 'SMS_5190328']]; if (!isset($types[$type])) { return false; } array_walk($params, function (&$v) { $v = strval($v); }); $c = new \ClusterTopClient('23289245', '1f32c93cfc513623f5457252b433c103'); $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setSmsType("normal"); $req->setSmsFreeSignName($types[$type][0]); $req->setSmsParam(json_encode($params)); $req->setRecNum($phone); $req->setSmsTemplateCode($types[$type][1]); $resp = $c->execute($req); //print_r($resp); if ($resp && isset($resp->result) && isset($resp->result->err_code)) { return $resp->result->err_code == 0; } else { return false; } }
/** * @param $tel * 根据电话号码 * 发送手机短信验证码 */ public function sendSMS($tel) { //随机生成一个6位数字的验证码 $phoneverify = String::randString(6, 1); //将验证码存到session中 session('PHONE_VERIFY', $phoneverify); //发送验证码给此手机用户 vendor('SMS.TopSdk'); date_default_timezone_set('Asia/Shanghai'); $c = new \TopClient(); $c->appkey = '23269098'; $c->secretKey = '8f1dd873ef3e792eab786e8d2845f60d'; $req = new \AlibabaAliqinFcSmsNumSendRequest(); // $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("注册验证"); $req->setSmsParam("{'code':'{$phoneverify}','product':'e商城'}"); $req->setRecNum("{$tel}"); $req->setSmsTemplateCode("SMS_2370004"); $resp = $c->execute($req); return (string) $resp->result->success === 'true'; }
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $c = new TopClient(); $c->appkey = '23302808'; $c->secretKey = '866a0f29b7c81e1c3c7eb4295dad8119'; $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("注册验证"); $req->setSmsParam('{"code":"哎呀我去~","product":"京西商城"}'); $req->setRecNum("18758546284"); $req->setSmsTemplateCode("SMS_4730837"); $resp = $c->execute($req);
/** * 发送短信 * @param $smsFreeSignName 短信签名 * @param $smsParam 短信模板参数 * @param $recNum 发送号码 * @param $smsTemplateCode 短信模板编号 */ function sendSMS($smsFreeSignName, $smsParam, $recNum, $smsTemplateCode) { //加载vendor中的阿里大鱼 vendor('Alidayu.TopSdk'); date_default_timezone_set('Asia/Shanghai'); $c = new TopClient(); //获取配置数据 $sms_config = C('SMS_CONFIG'); // $c->appkey = '23302808'; // $c->secretKey = '866a0f29b7c81e1c3c7eb4295dad8119'; //APP_KEY $c->appkey = $sms_config['appkey']; // //安全码 $c->secretKey = $sms_config['secretKey']; //创建发送短信的类对象 $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); //短信类型 $req->setSmsType("normal"); //短信签名 $req->setSmsFreeSignName($smsFreeSignName); //为短信模板中的变量赋值,确定要发送什么样的短信内容 $req->setSmsParam($smsParam); //发到哪里 $req->setRecNum($recNum); //短信模板编号 $req->setSmsTemplateCode($smsTemplateCode); //发射 $resp = $c->execute($req); }
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $appkey = '23302291'; $secret = 'dd85fe67813e5fdaede732d982614bf7'; $c = new TopClient(); $c->appkey = $appkey; $c->secretKey = $secret; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("登录验证"); $req->setSmsParam('{"code":"123456","product":"alidayu"}'); $req->setRecNum("15577375746"); $req->setSmsTemplateCode("SMS_4756068"); $resp = $c->execute($req); var_dump($resp);
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $httpdns = new HttpdnsGetRequest(); $client = new ClusterTopClient("4272", "0ebbcccfee18d7ad1aebc5b135ffa906"); $client->gatewayUrl = "http://api.daily.taobao.net/router/rest"; var_dump($client->execute($httpdns, "6100e23657fb0b2d0c78568e55a3031134be9a3a5d4b3a365753805")); $c = new TopClient(); $c->appkey = $appkey; $c->secretKey = $secret; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("°¢Àï´óÓã"); $req->setSmsParam('{"code":"1234","product":"alidayu"}'); $req->setRecNum("13131931531"); $req->setSmsTemplateCode("SMS_585014"); $resp = $c->execute($req);
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $appkey = '23354528'; $secret = 'e740ca6ca069ee03bf2f53ac767306d6'; $c = new TopClient(); $c->appkey = $appkey; $c->secretKey = $secret; $c->format = 'json'; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("注册验证"); $req->setSmsParam("{\"code\":\"1234\",\"product\":\"阿里健\"}"); $req->setRecNum("13808172540"); $req->setSmsTemplateCode("SMS_8295464"); $resp = $c->execute($req); print_r($resp); /** * https://api.alidayu.com/doc2/apiDetail?spm=a3142.7791109.1.19.deHdVv&apiId=25450 App Key: 23354528 App Secret: e740ca6ca069ee03bf2f53ac767306d6 SDK: 短信用于测试的签名和模板暂不可用,先选用以下系统自带模板 签名:注册验证||身份验证||登录验证||阿里健 模板名称: 身份验证验证码
/** * 发送短信 * @param $SmsParam '参数json字符串' * @param $RecNum '手机号' */ function sendSMS($SmsParam, $RecNum) { //引入文件 vendor('Alidayu.TopSdk'); //设置默认时区 date_default_timezone_set('Asia/Shanghai'); //实例化对象 $c = new TopClient(); //设置用户 $SMS_config = C('SMS_CONFIG'); $c->appkey = $SMS_config['appkey']; $c->secretKey = $SMS_config['secret']; $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); //回传参数 $req->setSmsType("normal"); //短信类型,默认normal即可 $req->setSmsFreeSignName($SMS_config['SmsFreeSignName']); $req->setSmsParam($SmsParam); //{"code":"1234","product":"alidayu"} 传入json字符串 $req->setRecNum($RecNum); $req->setSmsTemplateCode($SMS_config['SmsTemplateCode']); //发送短信 $c->execute($req); }
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $c = new TopClient(); //设置应用的APP_KEY $c->appkey = '23268328'; //安全码 $c->secretKey = 'a7bd32620043c504d76564c8badcc1ad'; //发送短信的对象 $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); //短信类型. 必须要修改 $req->setSmsType("normal"); //短信签名 $req->setSmsFreeSignName("注册验证"); //为短信模板中的变量赋值 $req->setSmsParam('{"code":"我爱你","product":"京西商城"}'); //接收短信的手机号 $req->setRecNum("15183833775"); //短信模板的编号 $req->setSmsTemplateCode("SMS_2245271"); // 验证码${code},您正在注册成为${product}用户,感谢您的支持! //发送短信 $resp = $c->execute($req);
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); /*$client = new ClusterTopClient("",""); $req = new AlibabaAliqinFcSmsNumSendRequest; $req->setSmsType("normal"); $req->setSmsFreeSignName("�����֤"); $req->setSmsParam("{\"product\":\"��ľ\",\"code\":\"123456\"}"); $req->setRecNum("18180565001"); $req->setSmsTemplateCode("TTS_3690289"); $resp = $client->execute($req);*/ $c = new TopClient(); $c->appkey = '23289245'; $c->secretKey = '1f32c93cfc513623f5457252b433c103'; $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("注册验证"); $req->setSmsParam('{"product":"积木","code":"123456"}'); $req->setRecNum("18180565001"); $req->setSmsTemplateCode("SMS_3690282"); $resp = $c->execute($req); print_r($resp);
/** * 安全检查 * @param array $userData * @param string $location * @return bool */ public function securityCheck($userData = [], $location = '') { if (!$location) { return false; } if (!$userData['phone']) { return false; } // 是否配置SMS接口 $config = DI::getDefault()->get('config'); if (!$config->sms->appID) { return false; } $dateTime = date('Y-m-d H:i:s', time() - 86400 * 90); $sql = "SELECT t.location, COUNT(1) times\n FROM(SELECT location FROM `logsLogin` WHERE user_id=:user_id AND location IS NOT null AND result=1 AND create_time>'{$dateTime}' ORDER BY id DESC LIMIT 300) t\n GROUP BY t.location\n ORDER BY times DESC"; $bind = array('user_id' => $userData['id']); $query = DI::getDefault()->get('dbBackend')->query($sql, $bind); $query->setFetchMode(Db::FETCH_ASSOC); $data = $query->fetchAll(); if (count($data) <= 1) { return true; } if ($data['0']['location'] == $location) { return true; } if ($data['1']['location'] == $location && $data['1']['times'] > 2) { return true; } // 短信通知 $location = explode(' ', $location); $local = !empty($location['1']) ? $location['1'] : ''; $local .= !empty($location['2']) ? $location['2'] : ''; $params = ['time' => (new \DateTime('now', new \DateTimeZone('Asia/Shanghai')))->format('H点i分'), 'location' => $local]; include BASE_DIR . $config->application->pluginsDir . 'alidayu/TopSdk.php'; $c = new \TopClient(); $c->appkey = $config->sms->appID; $c->secretKey = $config->sms->appKey; $req = new \AlibabaAliqinFcSmsNumSendRequest(); $req->setSmsType("normal"); $req->setSmsFreeSignName($config->sms->signName); $req->setSmsParam(json_encode($params)); $req->setRecNum($userData['phone']); $req->setSmsTemplateCode($config->sms->tempSafety); $c->execute($req); }
<?php ob_start(); header("Content-Type:application/json; charset=UTF-8"); include "../ali-api/TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); $redis = new Redis(); $redis->connect('127.0.0.1', 6379); /** * Created by PhpStorm. * User: dong_rui * Date: 2016-01-29 * Time: 14:56 */ session_start(); $ran_num = rand(1000, 9999); $redis->set(session_id() . '_verify_code', $ran_num); $redis->expire(session_id() . '_verify_code', 60); $c = new TopClient(); $c->appkey = '23305908'; $c->secretKey = '9655a0b98c6f8f3bfaf9a40cad1b5696'; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("百变女人"); $req->setSmsParam("{\"code\":\"{$ran_num}\", \"product\":\"Lady荟\"}"); $req->setRecNum($_POST["phone_number"]); $req->setSmsTemplateCode("SMS_5000839"); $resp = $c->execute($req); $_SESSION["mobile"] = $_POST["phone_number"]; echo json_encode($resp);
/** * 发送短信 * @param string $to 手机号 * @param int $code 验证码 * @param string $template 短信模板 * @param string $activity 活动名称 * @return int */ public static function sendSMS($to, $code, $template = 'login', $activity = '') { require APP_PATH . "/aliyun/TopSdk.php"; //选择短信模板 $sign = ''; switch ($template) { case 'login': $template = 'SMS_4741148'; $sign = '登录验证'; break; case 'register': $template = 'SMS_4741146'; $sign = '注册验证'; break; case 'verify': $template = 'SMS_4741149'; $sign = '身份验证'; break; case 'abnormal': $template = 'SMS_4741147'; $sign = '登录验证'; break; case 'pwd': $template = 'SMS_4741144'; $sign = '变更验证'; break; case 'info': $template = 'SMS_4741143'; $sign = '变更验证'; break; case 'activity': $template = 'SMS_4741145'; $sign = '活动验证'; break; } //设置短信模板字段 if ($activity) { $activity = ',"item":"' . $activity . '"'; } $param = '{"code":"' . $code . '","product":"问唠"' . $activity . '}'; $c = new TopClient(); $c->appkey = SMS_APP_KEY; $c->secretKey = SMS_APP_SECRET; $req = new AlibabaAliqinFcSmsNumSendRequest(); //$req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName($sign); $req->setSmsParam($param); $req->setRecNum($to); $req->setSmsTemplateCode($template); $resp = $c->execute($req); if ($resp->result->err_code != 0) { return SMS_SEND_FAIL; } return OK; }
<?php include "TopSdk.php"; date_default_timezone_set('Asia/Shanghai'); // $httpdns = new HttpdnsGetRequest; // $client = new ClusterTopClient("4272","0ebbcccfee18d7ad1aebc5b135ffa906"); // $client->gatewayUrl = "http://api.daily.taobao.net/router/rest"; // var_dump($client->execute($httpdns,"6100e23657fb0b2d0c78568e55a3031134be9a3a5d4b3a365753805")); $c = new TopClient(); $c->appkey = '23299465'; $c->secretKey = 'c2aac6cb08f94287a791ed7325b939b4'; $req = new AlibabaAliqinFcSmsNumSendRequest(); $req->setExtend("123456"); $req->setSmsType("normal"); $req->setSmsFreeSignName("注册验证"); $array = array('code' => '1234', 'product' => 'alidayu'); $code = json_encode($array); $req->setSmsParam("{$code}"); $req->setRecNum("17096836686"); $req->setSmsTemplateCode("SMS_3990626"); $resp = $c->execute($req); echo '<pre>'; print_r($resp);