<?php
/*
 *  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.
 */

include_once("CCPRestSDK.php");

//主帐号
$accountSid= '主帐号';

//主帐号Token
$accountToken= '主帐号Token';

//应用Id
$appId='应用Id';

//请求地址，格式如下，不需要写https://
$serverIP='sandboxapp.cloopen.com';

//请求端口 
$serverPort='8883';

//REST版本号
$softVersion='2013-12-26';


/**
 * 座席准备就绪
 * @param agentid			座席id，建议四位正整数，例如：8001
 * @param action			就绪失败的回调url，自定义相对地址，当为空则不回调
 * @param state 			true表示状态更新为准备就绪，false表示状态更新为准备中
 * @param priority		是否优先接听客户电话，false表示顺序接听，true表示优先接听，默认值为false，当设置坐席优先接听的时候坐席准备就绪就会排到队首接听
 * @param force				是否强制设置状态，false表示不强制设置，true表示强制设置，默认值为false，当设置强制的时候会把坐席的状态强制修改为设置的状态
 */
function AgentReady($agentid,$action,$state,$priority,$force) {
    // 初始化REST SDK
    global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
    $rest = new REST($serverIP,$serverPort,$softVersion);
    $rest->setAccount($accountSid,$accountToken);
    $rest->setAppId($appId);
    
    $result = $rest->AgentReady($agentid,$action,$state,$priority,$force);
    if($result == NULL ) {
        echo "result error!";
        break;
    }
        echo "error code :" . $result->statusCode . "<br/>";
        echo "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑      
}

//Demo调用     
AgentReady("座席id","就绪失败的回调url","座席状态","是否优先接听客户电话","是否强制设置状态");
?>
