<?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 number			座席号码，呼叫坐席的号码，可以是手机、座机和voip
 * @param agentid			座席ID，建议四位正整数，例如：8001
 * @param agenttype		座席所在队列，正整数，例如：1
 * @param agentstate	座席上班状态，0为准备中不可接电话，1为准备就绪可接电话
 */
function AgentOnWork($number,$agentid,$agenttype,$agentstate) {
    // 初始化REST SDK
    global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
    $rest = new REST($serverIP,$serverPort,$softVersion);
    $rest->setAccount($accountSid,$accountToken);
    $rest->setAppId($appId);
    
	// 调用云通讯平台的座席上班
    $result = $rest->AgentOnWork($number,$agentid,$agenttype,$agentstate);
    if($result == NULL ) {
        echo "result error!";
        break;
    }
        echo "error code :" . $result->statusCode . "<br/>";
        echo "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑      
}

//Demo调用     
AgentOnWork("座席号码","座席ID","座席所在队列","座席状态");
?>
