Exemplo n.º 1
0
/**
 * 语音验证码
 * @param verifyCode 验证码内容,为数字和英文字母,不区分大小写,长度4-8位
 * @param playTimes 播放次数,1-3次
 * @param to 接收号码
 * @param displayNum 显示的主叫号码
 * @param respUrl 语音验证码状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知
 * @param lang 语言类型。取值en(英文)、zh(中文),默认值zh。
 * @param userData 第三方私有数据
 * @param welcomePrompt  欢迎提示音,在播放验证码语音前播放此内容(语音文件格式为wav)           
 * @param playVerifyCode  语音验证码的内容全部播放此节点下的全部语音文件
 */
function voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl, $lang, $userData, $welcomePrompt, $playVerifyCode)
{
    // 初始化REST SDK
    $ci =& get_instance();
    $sms = $ci->config->item('SMSCHANNEL');
    $accountSid = $sms['accountSid'];
    $accountToken = $sms['accountToken'];
    $appId = $sms['appId'];
    $serverIP = $sms['serverIP'];
    $serverPort = $sms['serverPort'];
    $softVersion = $sms['softVersion'];
    // global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    //调用语音验证码接口
    $result = $rest->voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl, $lang, $userData, $welcomePrompt, $playVerifyCode);
    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 添加成功处理逻辑
    }
}
Exemplo n.º 2
0
/**
 * 语音文件上传
 * @param filename     文件名
 * @param path   文件所在路径
 */
function MediaFileUpload($filename, $path)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    $filePath = $path;
    $fh = fopen($filePath, "rb");
    $body = fread($fh, filesize($filePath));
    fclose($fh);
    // 调用语音文件上传接口
    $result = $rest->MediaFileUpload($filename, $body);
    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 "MediaFileUpload success!<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 3
0
/**
 * 发送验证码 sendTemplateSMS
 * @param $to
 * @param $datas
 * @param $tempId
 * @return mixed|SimpleXMLElement|内容数据
 */
function sendTemplateSMS($to = NULL, $datas = NULL, $tempId = NULL)
{
    $result = '';
    if ($to && $datas && $tempId) {
        $accountSid = C('API_SMS.accounts_id');
        //主帐号,对应开官网发者主账号下的 ACCOUNT SID
        $accountToken = C('API_SMS.account_token');
        //主帐号令牌,对应官网开发者主账号下的 AUTH TOKEN
        $appId = C('API_SMS.app_id');
        //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID, 在开发调试的时候,可以使用官网自动为您分配的测试Demo的APP ID
        $serverIP = C('API_SMS.server_ip');
        //请求地址 沙盒环境(用于应用开发调试):sandboxapp.cloopen.com,生产环境(用户应用上线使用):app.cloopen.com
        $serverPort = C('API_SMS.server_port');
        //请求端口,生产环境和沙盒环境一致
        $softVersion = C('API_SMS.soft_version');
        //REST版本号,在官网文档REST介绍中获得。
        import('@.ORG.CCPRestSmsSDK');
        $rest = new \REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);
        /* 发送模板短信 */
        $result = $rest->sendTemplateSMS($to, $datas, $tempId);
    }
    return $result;
}
Exemplo n.º 4
0
 /**
  * 创建子帐号
  * @param friendlyName 子帐号名称
  */
 public function createSubAccount($friendlyName)
 {
     // 初始化REST SDK
     //        global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
     $rest = new \REST($this->serverIP, $this->serverPort, $this->softVersion);
     $rest->setAccount($this->accountSid, $this->accountToken);
     $rest->setAppId($this->appId);
     // 调用云通讯平台的创建子帐号,绑定您的子帐号名称
     $result = $rest->CreateSubAccount($friendlyName);
     if ($result == NULL) {
         return false;
     }
     if ($result->statusCode != 0) {
         $data['status'] = $result->statusCode;
         $data['msg'] = $result->statusMsg;
         //TODO 添加错误处理逻辑
     } else {
         // 获取返回信息
         $subaccount = $result->SubAccount;
         $data['status'] = $result->statusCode;
         $data['subAccountSid'] = $subaccount->subAccountSid;
         $data['subToken'] = $subaccount->subToken;
         $data['dateCreated'] = $subaccount->dateCreated;
         $data['voipAccount'] = $subaccount->voipAccount;
         $data['voipPwd'] = $subaccount->voipPwd;
         $data['msg'] = 'success';
         //TODO 把云平台子帐号信息存储在您的服务器上.
         //TODO 添加成功处理逻辑
     }
     return $data;
 }
/**
 * 发送模板短信
 * @param to 手机号码集合,用英文逗号分开
 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
 * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
 */
function sendTemplateSMS($to, $datas, $tempId)
{
    // 初始化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) {
        return array('sign' => 0, 'msg' => 'result error!');
    }
    if ($result->statusCode != 0) {
        //echo "模板短信发送失败!<br/>";
        //echo "error code :" . $result->statusCode . "<br>";
        //echo "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑
        return array('sign' => 2, 'msg' => "error code :" . $result->statusCode . "-----error msg :" . $result->statusMsg);
    } else {
        //echo "模板短信发送成功!<br/>";
        // 获取返回信息
        //$smsmessage = $result->TemplateSMS;
        //echo "dateCreated:".$smsmessage->dateCreated."<br/>";
        //echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
        //TODO 添加成功处理逻辑
        return array('sign' => 1, 'msg' => "success");
    }
}
Exemplo n.º 6
0
/**
 * 主帐号信息查询
 */
function queryAccountInfo()
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用主帐号信息查询接口
    $result = $rest->queryAccountInfo();
    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 "query AccountInfo success!<br/>";
        // 获取返回信息
        $account = $result->Account;
        echo "friendlyName:" . $account->friendlyName . "<br/>";
        echo "type:" . $account->type . "<br/>";
        echo "status:" . $account->status . "<br/>";
        echo "dateCreated:" . $account->dateCreated . "<br/>";
        echo "dateUpdated:" . $account->dateUpdated . "<br/>";
        echo "balance:" . $account->balance . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 7
0
 /**
  * 发送模板短信
  * @param to 手机号码集合,用英文逗号分开
  * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
  * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
  */
 function sendTemplateSMS($to, $datas, $tempId)
 {
     // 初始化REST SDK
     //global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
     //主帐号,对应开官网发者主账号下的 ACCOUNT SID
     $accountSid = '8a48b5514a51d087014a56d235c4034a';
     //主帐号令牌,对应官网开发者主账号下的 AUTH TOKEN
     $accountToken = '2922e8361b734b64a6a917c110755f4b';
     //应用Id,在官网应用列表中点击应用,对应应用详情中的APP ID
     //在开发调试的时候,可以使用官网自动为您分配的测试Demo的APP ID
     $appId = '8a48b5514a61a814014a7a16517e0ea0';
     //请求地址
     //沙盒环境(用于应用开发调试):sandboxapp.cloopen.com
     //生产环境(用户应用上线使用):app.cloopen.com
     $serverIP = 'app.cloopen.com';
     //请求端口,生产环境和沙盒环境一致
     $serverPort = '8883';
     //REST版本号,在官网文档REST介绍中获得。
     $softVersion = '2013-12-26';
     $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);
     return $result;
 }
Exemplo n.º 8
0
/**
 * 短信模板查询
 * @param templateId     模板ID
 */
function QuerySMSTemplate($templateId)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用短信模板查询接口
    $result = $rest->QuerySMSTemplate($templateId);
    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 {
        $TemplateSMS = $result->TemplateSMS;
        for ($i = 0; $i < count($TemplateSMS); $i++) {
            echo "title:" . $TemplateSMS[$i]->title . "<br/>";
            echo "content:" . $TemplateSMS[$i]->content . "<br/>";
            echo "status:" . $TemplateSMS[$i]->status . "<br/>";
            echo "type:" . $TemplateSMS[$i]->type . "<br/>";
            echo "dateCreated:" . $TemplateSMS[$i]->dateCreated . "<br/>";
            echo "dateUpdated:" . $TemplateSMS[$i]->dateUpdated . "<br/>";
            echo "id:" . $TemplateSMS[$i]->id . "<br/>";
            echo "<br/>";
        }
    }
}
Exemplo n.º 9
0
/**
 * 呼叫状态查询
 * @param callid     呼叫Id 
 * @param action   查询结果通知的回调url地址 
 */
function QueryCallState($callid, $action)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用呼叫状态查询接口
    $result = $rest->QueryCallState($callid, $action);
    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 "QueryCallState success!<br/>";
        // 获取返回信息
        echo "state:" . $result->state . "<br/>";
        echo "callSid:" . $result->callSid . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 10
0
/**
 * 双向回呼
 * @param from 主叫电话号码
 * @param to 被叫电话号码
 * @param customerSerNum 被叫侧显示的客服号码  
 * @param fromSerNum 主叫侧显示的号码
 * @param promptTone 自定义回拨提示音    
 */
function callBack($from, $to, $customerSerNum, $fromSerNum, $promptTone)
{
    // 初始化REST SDK
    global $appId, $subAccountSid, $subAccountToken, $voIPAccount, $voIPPassword, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setSubAccount($subAccountSid, $subAccountToken, $voIPAccount, $voIPPassword);
    $rest->setAppId($appId);
    // 调用回拨接口
    echo "Try to make a callback,called is {$to} <br/>";
    $result = $rest->callBack($from, $to, $customerSerNum, $fromSerNum, $promptTone);
    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 "callback success!<br>";
        // 获取返回信息
        $callback = $result->CallBack;
        echo "callSid:" . $callback->callSid . "<br/>";
        echo "dateCreated:" . $callback->dateCreated . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 11
0
/**
 * 获取子帐号
 * @param startNo 开始的序号,默认从0开始
 * @param offset 一次查询的最大条数,最小是1条,最大是100条
 */
function getSubAccounts($startNo, $offset)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用云通讯平台的获取子帐号接口
    echo "Try to get subaccount list<br/>";
    $result = $rest->getSubAccounts($startNo, $offset);
    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 "get SubbAccount list success<br/>";
        // 获取返回信息
        $subaccount = $result->SubAccount;
        for ($i = 0; $i < count($subaccount); $i++) {
            echo "subAccountid:" . $subaccount[$i]->subAccountSid . "<br/>";
            echo "subToken:" . $subaccount[$i]->subToken . "<br/>";
            echo "dateCreated:" . $subaccount[$i]->dateCreated . "<br/>";
            echo "voipAccount:" . $subaccount[$i]->voipAccount . "<br/>";
            echo "voipPwd:" . $subaccount[$i]->voipPwd . "<br/>";
            echo "friendlyName:" . $subaccount[$i]->friendlyName . "<br/>";
            echo "<br/>";
        }
        //TODO 把云平台子帐号信息存储在您的服务器上.
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 12
0
 public function __construct()
 {
     $rest = new REST($this->serverIP, $this->serverPort, $this->softVersion);
     $rest->setAccount($this->accountSid, $this->accountToken);
     $rest->setAppId($this->appId);
     $this->rest = $rest;
 }
Exemplo n.º 13
0
/**
 * 呼叫结果查询
 * @param callSid     呼叫Id
 */
function CallResult($callSid)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用呼叫结果查询接口
    $result = $rest->CallResult($callSid);
    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 "query CallResult success!<br/>";
        // 获取返回信息
        $callResult = $result->CallResult;
        echo "friendlyName:" . $callResult->callTime . "<br/>";
        echo "type:" . $callResult->state . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 14
0
function voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl, $lang, $userData)
{
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $accountSid = 'aaf98f894d`328b13014d566d3eca1b83';
    $accountToken = '37fbd7a853df4704bd5420f22328fffb';
    $appId = '8a48b5514d32a2a8014d56721def1b2b';
    $appToken = 'd96986e70dae11e5ac73ac853d9f54f2';
    $serverIP = 'sandboxapp.cloopen.com';
    $serverPort = '8883';
    $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 "Try to make a voiceverify,called is $to <br/>";
    $result = $rest->voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl, $lang, $userData);
    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 "voiceverify success!<br>";
        // 获取返回信息
        $voiceVerify = $result->VoiceVerify;
        // echo "callSid:".$voiceVerify->callSid."<br/>";
        // echo "dateCreated:".$voiceVerify->dateCreated."<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 15
0
/**
 * 发送模板短信
 * @param to 手机号码集合,用英文逗号分开
 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
 * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
 */
function sendTemplateSMS($to, $datas, $tempId)
{
    // 初始化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 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 添加成功处理逻辑
    }
}
Exemplo n.º 16
0
/**
 * 语音验证码
 * @param verifyCode 验证码内容,为数字和英文字母,不区分大小写,长度4-8位
 * @param playTimes 播放次数,1-3次
 * @param to 接收号码
 * @param displayNum 显示的主叫号码
 * @param respUrl 语音验证码状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知
 */
function voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    //调用语音验证码接口
    echo "Try to make a voiceverify,called is {$to} <br/>";
    $result = $rest->voiceVerify($verifyCode, $playTimes, $to, $displayNum, $respUrl);
    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 "voiceverify success!<br>";
        // 获取返回信息
        $voiceVerify = $result->VoiceVerify;
        echo "callSid:" . $voiceVerify->callSid . "<br/>";
        echo "dateCreated:" . $voiceVerify->dateCreated . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 17
0
/**
 * 外呼通知
 * @param to 被叫号码
 * @param mediaName 语音文件名称,格式 wav。与mediaTxt不能同时为空。当不为空时mediaTxt属性失效。
 * @param mediaTxt 文本内容
 * @param displayNum 显示的主叫号码
 * @param playTimes 循环播放次数,1-3次,默认播放1次。
 * @param respUrl 外呼通知状态通知回调地址,云通讯平台将向该Url地址发送呼叫结果通知。
 * @param userData 用户私有数据
 * @param maxCallTime 最大通话时长
 * @param speed 发音速度
 * @param volume 音量
 * @param pitch 音调
 * @param bgsound 背景音编号
 */
function landingCall($to, $mediaName, $mediaTxt, $displayNum, $playTimes, $respUrl, $userData, $maxCallTime, $speed, $volume, $pitch, $bgsound)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    //调用外呼通知接口
    echo "Try to make a landingcall,called is {$to} <br/>";
    $result = $rest->landingCall($to, $mediaName, $mediaTxt, $displayNum, $playTimes, $respUrl, $userData, $maxCallTime, $speed, $volume, $pitch, $bgsound);
    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 "landingcall success!<br>";
        // 获取返回信息
        $landingCall = $result->LandingCall;
        echo "callSid:" . $landingCall->callSid . "<br/>";
        echo "dateCreated:" . $landingCall->dateCreated . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 18
0
/**
 * 发送模板短信
 * @param to 手机号码集合,用英文逗号分开
 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
 * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID
 */
function sendTemplateSMS($to, $datas, $tempId)
{
    // 初始化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/>";
    $output = array('return' => 0);
    $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 添加错误处理逻辑
        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;
}
Exemplo n.º 19
0
/**
 * 话单下载
 * @param date     day 代表前一天的数据(从00:00 – 23:59);week代表前一周的数据(周一 到周日);month表示上一个月的数据(上个月表示当前月减1,如果今天是4月10号,则查询结果是3月份的数据)
 * @param keywords   客户的查询条件,由客户自行定义并提供给云通讯平台。默认不填忽略此参数
 */
function billRecords($date, $keywords)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用话单下载接口
    $result = $rest->billRecords($date, $keywords);
    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 "BillRecords success!<br/>";
        // 获取返回信息
        echo "downUrl:" . $result->downUrl . "<br/>";
        echo "token:" . $result->token . "<br/>";
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 20
0
/**
 * 创建子帐号
 * @param friendlyName 子帐号名称
 */
function createSubAccount($friendlyName)
{
    // 初始化REST SDK
    global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);
    // 调用云通讯平台的创建子帐号,绑定您的子帐号名称
    echo "Try to create a subaccount, binding to user {$friendlyName} <br/>";
    $result = $rest->CreateSubAccount($friendlyName);
    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 "create SubbAccount success<br/>";
        // 获取返回信息
        $subaccount = $result->SubAccount;
        echo "subAccountid:" . $subaccount->subAccountSid . "<br/>";
        echo "subToken:" . $subaccount->subToken . "<br/>";
        echo "dateCreated:" . $subaccount->dateCreated . "<br/>";
        echo "voipAccount:" . $subaccount->voipAccount . "<br/>";
        echo "voipPwd:" . $subaccount->voipPwd . "<br/>";
        //TODO 把云平台子帐号信息存储在您的服务器上.
        //TODO 添加成功处理逻辑
    }
}
Exemplo n.º 21
0
Arquivo: CCP.php Projeto: pancke/yyaf
 /**
  * 初始化REST SDK
  * @return Ambigous <NULL, unknown>
  */
 public static function getRest()
 {
     $aConf = Util_Common::getConf('CCP');
     global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion;
     $rest = new REST($aConf['host'], $aConf['port'], $aConf['version']);
     $rest->setAccount($aConf['sid'], $aConf['token']);
     $rest->setAppId($aConf['appid']);
     return $rest;
 }
Exemplo n.º 22
0
 function getVerifyCode()
 {
     $param = json_decode(file_get_contents('php://input'), true);
     $phone = $param['phone'];
     // $phone = '13269627267';
     if (empty($phone)) {
         err_ret(-205, 'lack of param', '手机号码为空');
     }
     $model = new Model('verify_tmp');
     //查询对应手机的最后一条记录
     $sql_max = "SELECT * from verify_tmp where id = (select max(id) from verify_tmp WHERE phone = '" . $phone . "')";
     $result = $model->query($sql_max);
     if (count($result) > 0) {
         $time = time() - $result[0]['gen_time'];
         if ($time < 60) {
             //小于1分钟
             err_ret(-302, 'too many time get verifycode', '请求验证码过于频繁');
         }
     }
     //判断是否注册过
     $model = new Model('user_info');
     $where['username'] = $phone;
     $result_user_info = $model->where($where)->select();
     if (count($result_user_info) > 0) {
         err_ret(-205, 'phone number is already registered', '此手机号码已经注册过');
     }
     //生成验证码和短信模板
     $code = rand(1000, 9999);
     $data = array($code, '5');
     //发送短信验证码
     $serverIP = C('RL_ServerIP');
     $serverPort = C('RL_ServerPort');
     $softVersion = C('RL_SoftVersion');
     $accountSid = C('RL_AccountSID');
     $accountToken = C('RL_AccountToken');
     $appId = C('RL_AppID');
     $SmsId = C('RL_SMS_TEMPLATE_ID');
     $rest = new \REST($serverIP, $serverPort, $softVersion);
     $rest->setAccount($accountSid, $accountToken);
     $rest->setAppId($appId);
     $result = $rest->sendTemplateSMS($phone, $data, $SmsId);
     if ($result->statusCode != 0) {
         err_ret($result->statusCode, $result->statusMsg);
     } else {
         //生成验证码,插入数据库
         $value['phone'] = $phone;
         $value['verifycode'] = $code;
         $value['gen_time'] = time();
         M("verify_tmp")->add($value);
         http_ret(0, 'verify code send success', '验证码发送成功');
     }
 }
Exemplo n.º 23
0
 public function __construct()
 {
     parent::__construct();
     // Init parent contructor
     $this->dbConnect();
     // Initiate Database connection
 }
Exemplo n.º 24
0
 public function __construct()
 {
     parent::__construct();
     // Init parent contructor
     $this->objService = new General_Operation();
     // Init general operation class
 }
Exemplo n.º 25
0
 public static function requireRequestMethod($method)
 {
     if ($_SERVER['REQUEST_METHOD'] == $method) {
         return;
     }
     REST::sendResponse(405);
 }
Exemplo n.º 26
0
 public static function handle($uri_pattern, $action, $method = "ALL")
 {
     if (REST::$consumed) {
         return;
     }
     if ($method != "ALL" && !(is_array($method) && in_array("ALL", $method))) {
         $m = $_SERVER['REQUEST_METHOD'];
         if (is_array($method)) {
             if (!in_array($m, $method)) {
                 return;
             }
         } else {
             if ($m != $method) {
                 return;
             }
         }
     }
     $pattern = $uri_pattern;
     if (strpos($pattern, "/") !== 0 || strrpos($pattern, "/", -1) !== strlen($pattern) - 1) {
         $pattern = str_replace("/", "\\/", $pattern);
         $pattern = "/^" . $pattern . "/";
         $pattern = str_replace("%", "(.*)", $pattern);
     }
     if (preg_match($pattern, $_REQUEST["_url"], $matches)) {
         if ($action($matches) !== false) {
             REST::$consumed = true;
         }
     }
 }
Exemplo n.º 27
0
 private function extractController()
 {
     $mvcParts = explode('/', $this->requestUri);
     $this->controller = $mvcParts[1];
     $this->action = $mvcParts[2];
     $this->params = REST::getParameters();
 }
Exemplo n.º 28
0
 public function __construct()
 {
     parent::__construct();
     // Init parent contructor
     include_once '../database.php';
     $this->db = $db;
 }
Exemplo n.º 29
0
 public function __construct()
 {
     parent::__construct();
     // Iniciar el constructor del padre
     $this->dbConnect();
     // Inicar la coneción a la base de datos
 }
Exemplo n.º 30
0
 public function __construct()
 {
     error_log('method: __construct');
     parent::__construct();
     // Init parent contructor
     $this->dbConnect();
     // Initiate Database connection
 }