public function SendMessageByTemplate($mobile, $par1, $par2, $templateId) { $rs = array("status" => -1); $options['accountsid'] = C('MSG.accountsid'); $options['token'] = C('MSG.token'); //初始化 $options必填 $ucpass = new Ucpaas($options); $appId = C('MSG.appId'); $to = $mobile; //$templateId ='23832';// C('MSG.templateId'); $param = $par1 . ',' . $par2; //echo $param; $result = $ucpass->templateSMS($appId, $to, $templateId, $param); //echo dump($result); $r = json_decode($result, TRUE); if ($r) { $code = $r["resp"]["respCode"]; if ($code == '000000') { $rs["status"] = 0; } else { //echo dump($r); $rs["msg"] = "发送失败." . $code; } } return $rs; }
function sendCode($mobile, $code) { $options['accountsid'] = '8bd7e8279a0390eb9beaaf5063b4cdec'; $options['token'] = '3b3cdd3c9e4170697fc823a7913701f5'; //初始化 $options必填 $ucpass = new Ucpaas($options); //开发者账号信息查询默认为json或xml $ucpass->getDevinfo('xml'); $appId = "5c5f239bfb97495d84cce1ddf9ea1d36"; $templateId = "10990"; $param = "{$code},2"; $ucpass->templateSMS($appId, $mobile, $templateId, $param); }
function send_sms($num, $code) { global $_G; $config = $_G['cache']['plugin']['nyasec']; if (!$config['accountsid'] || !$config['token'] || !$config['appid'] || !$config['tmplid']) { return -1; } $ucpass = new Ucpaas(array('accountsid' => $config['accountsid'], 'token' => $config['token'])); $params = " {$code},10 "; $sms = $ucpass->templateSMS($config['appid'], $num, $config['tmplid'], $params); $result = json_decode($sms, true); return $result['resp']['respCode']; }
public function voiceVerify($to, $code) { $config = ['accountsid' => $this->accountSid, 'token' => $this->accountToken]; $ucpass = new \Ucpaas($config); $response = $ucpass->voiceCode($this->appId, $code, $to, $type = 'json'); $result = json_decode($response); if ($result === null) { return $this->result; } if ($result->resp->respCode === '000000') { $this->result['success'] = true; } $this->result['info'] = $result->resp->respCode; $this->result['code'] = $result->resp->respCode; return $this->result; }
function sendSMS($phone, $code, $templateId) { //发送验证码 //初始化必填 $options['accountsid'] = 'ae9fa29bcd06ba08599e14bcc40c777d'; $options['token'] = 'bbde082ad947d5d867cdbabcf3858c7e'; //初始化 $options必填 $ucpass = new Ucpaas($options); //开发者账号信息查询默认为json或xml //echo $ucpass->getDevinfo('xml'); //短信验证码(模板短信),默认以65个汉字(同65个英文)为一条(可容纳字数受您应用名称占用字符影响),超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。 $appId = "ce27a03259e04de485d9efd82ba70d95"; $to = $phone; $param = $code . ',20'; $result = $ucpass->templateSMS($appId, $to, $templateId, $param); return $result; }
/** * template sms send process * @param $tempId * @param $to * @param array $data * * @return mixed */ public function sendTemplateSms($tempId, $to, array $data) { $config = ['accountsid' => $this->accountSid, 'token' => $this->accountToken]; $ucpaas = new \Ucpaas($config); $response = $ucpaas->templateSMS($this->appId, $to, $tempId, $data); $result = json_decode($response); if ($result == null || $result->resp->respCode != '000000') { //sent failed $this->result['success'] = false; $this->result['info'] = $this->currentAgentName . ':' . $result->resp->respCode; $this->result['code'] = $result->resp->respCode; } elseif ($result->resp->respCode == '000000') { //sent success $this->result['success'] = true; $this->result['info'] = $this->currentAgentName . ':' . $result->resp->respCode; $this->result['code'] = $result->resp->respCode; } }
function _sendUcpassSms($to, $from_type) { require_once VENDOR_PATH . 'Ucpaas.php'; //初始化必填 $options['accountsid'] = $this->config['accountSid']; $options['token'] = $this->config['authToken']; $ucpass = new \Ucpaas($options); //短信验证码(模板短信),默认以65个汉字(同65个英文)为一条(可容纳字数受您应用名称占用字符影响),超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。 $appId = $this->config['appId']; if ($from_type == 'card') { $templateId = (int) $this->config['cardTemplateId']; $param[] = rand(1111, 9999); $param[] = $this->config['expire']; $is_lock = smsLock($to); if ($is_lock) { $resStr = $ucpass->templateSMS($appId, $to, $templateId, implode(',', $param)); $res = json_decode($resStr, true); } else { $result['result'] = 0; $result['msg'] = "获取验证码太频繁"; return $result; } } else { //Todo } if ($res['resp'] && $res['resp']['respCode'] == "000000") { $data['phone'] = $to; $data['plat_type'] = $this->config['type']; $data['from_type'] = $from_type; $data['code'] = $param[0]; $data['status'] = 0; $data['smsId'] = $res['resp']['respCode']['smsId']; $data['cTime'] = time(); $this->add($data); $result['result'] = 1; $result['msg'] = "发送成功"; } else { $result['result'] = 0; $result['msg'] = "发送失败"; } return $result; }
/** * [send_code 发送手机验证码, 成功返回验证码, 失败返回 NULL] */ public function send_code($phone, $code) { $ucpass = new Ucpaas($this->options); return $ucpass->templateSMS($this->appId, $phone, $this->templateId, $code); }
<?php //载入ucpass类 require_once 'lib/Ucpaas.class.php'; //初始化必填 $options['accountsid'] = '8bd7e8279a0390eb9beaaf5063b4cdec'; $options['token'] = '3b3cdd3c9e4170697fc823a7913701f5'; //初始化 $options必填 $ucpass = new Ucpaas($options); //开发者账号信息查询默认为json或xml $ucpass->getDevinfo('xml'); $appId = "5c5f239bfb97495d84cce1ddf9ea1d36"; $to = $_POST["phone"]; $templateId = "10990"; $arr = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; $code = ""; for ($i = 0; $i < 6; $i++) { $code .= $arr[rand(0, count($arr))]; } $param = "{$code},2"; $ucpass->templateSMS($appId, $to, $templateId, $param); echo $code;
private function _sendMsg($phone, $templateId, $param, $sMsgType, $sMsgContent) { //call api require_once 'Ucpaas.class.php'; $ucpass = new Ucpaas($this->msgApiInfo); $resMsg = $ucpass->templateSMS($this->appId, $phone, $templateId, $param); $oResMsg = json_decode($resMsg); $aMsgRes = $this->_objectToArray($oResMsg); $aRes = array(); $aRes['rawResponse'] = $resMsg; if ($aMsgRes['resp']['respCode'] != '000000') { $aRes['error'] = $aMsgRes['resp']['respCode']; $aRes['msg'] = '短信发送失败'; } else { $aRes['error'] = 0; $aRes['msg'] = '短信发送成功'; } global $db; //save data to DB $aNewMsg = array('msg_to' => $phone, 'msg_type' => $sMsgType, 'msg_content' => $sMsgContent, 'msg_param' => $param, 'msg_id' => $aMsgRes['resp']['templateSMS']['smsId'], 'msg_created_date' => $aMsgRes['resp']['templateSMS']['createDate'], 'msg_error_info' => $aMsgRes['resp']['respCode'], 'msg_response_json' => $resMsg, 'created_date' => $db->now()); $id = $db->insert('mobile_message', $aNewMsg); return $aRes; }
<?php //载入ucpass类 require_once 'lib/Ucpaas.class.php'; //初始化必填 $options['accountsid'] = '38542bb2c01501e1db92b44c8bca8810'; $options['token'] = '434c3a1cab14d7391828cb52ce3a11bd'; //初始化 $options必填 $ucpass = new Ucpaas($options); //开发者账号信息查询默认为json或xml echo $ucpass->getDevinfo('json'); //短信验证码(模板短信),默认以65个汉字(同65个英文)为一条(可容纳字数受您应用名称占用字符影响),超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。 $appId = "f0b1c14f5a88401297bed6ede4872b08"; //$to = "13026139128"; //$to = "15991431396"; $to = "18210450103"; //$to = "15910813505"; $templateId = "10199"; $code = mt_rand(100000, 900000); $param = "{$code},1"; $res = $ucpass->templateSMS($appId, $to, $templateId, $param); echo "res:\n"; var_dump($res);
function sms($mobile, $content, $minute = 1) { //短信供应商提供的代码 //$sn='SDK-WSS-010-07787'; //短信供应商提供的密码 // $password='******'; // $pwd=md5($sn.$password); // $pwd=strtoupper($pwd); // $content=urlencode($content); // $url="http://sdk2.entinfo.cn:8061/mdsmssend.ashx?sn=$sn&pwd=$pwd&mobile=$mobile&content=$content&ext=&stime=&rrid=&msgfmt="; // $status=curl_get($url); // return $status; import('SendScm.Ucpaas'); $ucpass = new \Ucpaas(C('SMS_CONFIG')); $appId = C('SMS_APPID'); // "f0b1c14f5a88401297bed6ede4872b08";//应用id $to = $mobile; $templateId = C('SMS_TEMPLATE'); //"10199";//短信模板id $param = "{$content}," . $minute; $res = $ucpass->templateSMS($appId, $to, $templateId, $param); $ret = json_decode($res, true); if ($ret['resp']['respCode'] == '000000') { return 1; } else { return -1; } }
/** * 获取验证码 * * @param [int] $[userPhone] [手机号] * * @return [type] [description] */ public function getAuthCode() { $retCode = SUCCESS; $retMsg = ""; do { $userPhone = Input::get('user_phone'); if (empty($userPhone)) { $retCode = -10004; $retMsg = Lang::get('errormessages.-10004'); break; } $accountsid = Config::get('ucpaas.accountsid'); $token = Config::get('ucpaas.token'); $option = array('accountsid' => $accountsid, 'token' => $token); try { $ucpaas = new Ucpaas($option); } catch (Exception $e) { $retCode = -10005; $retMsg = Lang::get('errormessages.-10005'); break; } // 生成验证码 $authCode = $this->generateAuthCode(); // 判断重复获取验证码 $registCode = RegistCode::find($userPhone); if (empty($registCode)) { $registCode = new RegistCode(); $registCode->user_phone_id = $userPhone; $registCode->code = $authCode; $registCode->update_time = Carbon::now(); if (!$registCode->save()) { $retCode = -15001; $retMsg = Lang::get('errormessages.-15001'); break; } } else { $updateTime = strtotime($registCode->update_time); $nowTime = strtotime(Carbon::now()); $breakTime = ceil(($nowTime - $updateTime) / AUTHCODE_MIN); if ($breakTime < AUTHCODE_TIME) { $authCode = $registCode->code; } else { $registCode->code = $authCode; $registCode->update_time = Carbon::now(); if (!$registCode->save()) { $retCode = -15002; $retMsg = Lang::get('errormessages.-15002'); break; } } } $appId = Config::get('ucpaas.appId'); $templateId = Config::get('ucpaas.templateId'); $isDebug = Config::get('app.debug'); if ($isDebug) { $templateId = AUTHCODE_TEST; $param = $authCode; } else { $templateId = $templateId; $param = "{$authCode}"; // $param = AUTHCODE_NAME . "," . $authCode . "," . AUTHCODE_TIME; } $result = $ucpaas->templateSMS($appId, $userPhone, $templateId, $param); Log::warning($result); $resultArray = json_decode($result, true); if (isset($resultArray['resp']['respCode'])) { if (0 != strcmp($resultArray['resp']['respCode'], AUTHCODE_SUCCESS)) { $retCode = -10006; $retMsg = Lang::get('errormessages.-10006'); break; } } else { $retCode = -10007; $retMsg = Lang::get('errormessages.-10007'); break; } } while (false); if (SUCCESS != $retCode) { $context = array("errorCode" => $retCode); Log::error($retMsg, $context); } $sendMsgArray = array("ret_code" => $retCode, "msg" => $retMsg); return Response::json($sendMsgArray); }