PHP code example of oneyun / sdk

1. Go to this page and download the library: Download oneyun/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oneyun / sdk example snippets


composer 



d = ""; //应用标识

$certId = ""; //鉴权Id

$apiUrl = ""; //接口地址

$secreKey = "";//密钥

$oneyun = new Oneyun\Rest\Client($appId, $certId, $apiUrl, $secreKey);

$res = $oneyun->calls->create(
    '17606661993',
    '13611460986',
    array(
        'user_data'=>'',
        'max_dial_duration'=>30
    )
);

var_dump($res); //返回结果




$oneyun = new Oneyun\Rest\Client($appId, $certId, $apiUrl, $secreKey);

$result = $oneyun->calls->cancel(
    'callId'
);

var_dump($result); //返回结果




//动态播放内容
$play_content = array(
      array(date('Y-m-d H:i:s'),4,'')
);

$oneyun->notifyCall->create(
    '17606661993',
    $play_content,
    array(
        'user_data'=>'',
        'max_dial_duration'=>30,
        'play_file'=>'语音通知.wav'
    )
);




$oneyun->verfiyCall->create(
    '17606661993',
    '8888',
    array(
        'user_data'=>'',
        'max_dial_duration'=>30
    )
);




$oneyun->ivrCall->create(
    '17606661993',
    array(
        'user_data'=>'',
        'max_dial_duration'=>30
    )
);


$ivr = new Oneyun\Ivr();
$ivr->playlist(
    array(
        '文件名1.wav',
        '文件名2.wav'
    )
);
$ivr->next('http://localhost/ivr.php?step=hangup');

echo $ivr;

$ivr = new Oneyun\Ivr();
$ivr->record();
$ivr->next('http://localhost/ivr.php?step=hangup');

echo $ivr;

$ivr = new Oneyun\Ivr();
$ivr->get(
  'get.wav'
);
$ivr->next('http://localhost/ivr.php?step=hangup');

echo $ivr;

$ivr = new Oneyun\Ivr();
$ivr->next();


Id = ""; //应用标识

$certId = ""; //鉴权Id

$apiUrl = ""; //接口地址

$secreKey = "";//密钥

$oneyun = new Oneyun\Rest\Client($appId, $certId, $apiUrl, $secreKey);

$options = array(
    'type'=>1,
    'user'=>'10222',
    'password'=>'123456'
);


$options = array(
    'type'=>1, // 分机类型
    'user'=>'test001', // 分机号 6-12位数字
    'password'=>'123456' // 分机密码
);

$res = $oneyun->callcenter->createExt($options);

var_dump($res); //返回结果


$extension_id = '8a2a6a4a59965bab0159968f95840000'; // 分机ID
$res = $oneyun->callcenter->deleteExt($extension_id);

$extension_id = '8a2a6a4a59965bab0159968f95840000'; // 分机ID
$res = $oneyun->callcenter->findExt($extension_id);

$pageNo = 1; // 第几页
$pageSize = 20; // 每页显示数量
$res = $oneyun->callcenter->findAllExt($pageNo,$pageSize);

$agent_name = 'test001'; //坐席名称
$extension = '8a2a6a4a59965bab0159968f95840000'; // 绑定的分机ID
$options = array(
    'num'=>'123456', // 坐席工号
    'state'=>'idle' // 坐席状态 idle 为空闲
);

$res = $oneyun->callcenter->agentLogin($agent_name,$extension,$options);

$agent_name = 'test001'; //坐席名称
$force = true; // true 为强制注销
$res = $oneyun->callcenter->agentLogout($agent_name,$force);

$agent_name = 'test001'; //坐席名称
$res = $oneyun->callcenter->agentKeep($agent_name);

$agent_name = 'test001'; //坐席名称
$res = $oneyun->callcenter->findAgent($agent_name);

$pageNo = 1; // 第几页
$pageSize = 20; // 每页显示数量
$res = $oneyun->callcenter->findAllAgent($pageNo, $pageSize);

$agent_name = 'test001'; //坐席名称
$extension_id = '8a2a6a4a59965bab0159968f95840000'; // 分机ID
$res = $oneyun->callcenter->setAgentExt($agent_name,$extension_id )

$agent_name = 'test001'; //坐席名称
$state = 'idle'; // 坐席状态
$res = $oneyun->callcenter->setAgentState($agent_name,$state);

$agent_name = 'test001'; //坐席名称

// 坐席技能
$opts = array( 
    array(
        'opt'=>1,
        'name'=>'test', // 坐席名称
        'score'=>80, // 坐席技能分
        'enabled'=>true // 是否启用技能
    )
); 
$res = $oneyun->callcenter->setAgentSkills($agent_name,$opts);


// public function createCondition($where = '', $queue_timeout = 0,$options = array())
$where = 'get('test')>60;'; // 条件表达式  必须;号结尾
$queue_timeout = 30; // 排队等待超时时间 (0-1000)
$options = array(
    'fetch_timeout'=>30, // 坐席分机接听超时时间(秒)(0-60)
    'priority'=>99, // 数值大的优先级高 (0-99)
    'remark'=>'', // 备注
);

$res = $oneyun->callcenter->createCondition($where,$queue_timeout,$options);

$condition_id = ''; // 排队条件
$res = $oneyun->callcenter->deleteCondition($condition_id);

$condition_id = ''; //排队条件ID
$where = 'get('test')>60;'; // 条件表达式  必须;号结尾
$options = array(
    'fetch_timeout'=>30, // 坐席分机接听超时时间(秒)(0-60)
    'priority'=>99, // 数值大的优先级高 (0-99)
    'remark'=>'', // 备注
);
$res = $oneyun->callcenter->editCondition($condition_id,$where,$options);

$condition_id = ''; //排队条件ID
$res = $oneyun->callcenter->findCondition($condition_id);

$res = $oneyun->callcenter->findAllCondition();

$conversation_id = ''; // 交谈ID
$res = $oneyun->callcenter->deleteConversation($conversation_id);

$conversation_id = '';  // 交谈ID
$agent_name = ''; // 坐席名称
$mode = 1; // 设置坐席听说模式 (1-4)
$res = $oneyun->callcenter->setConversationMode($conversation_id,$agent_name,$mode);

$conversation_id = '';  // 交谈ID
$enqueue = '<enqueue wait_voice="wait.wav" ring_mode="1" play_num="true" user_data="test">
                <route><agent name="test001" priority="11" queue_timeout="60" fetch_timeout="50"></agent></route>
            </enqueue>'; // 目标坐席选择条件
$mode = 1; // 设置坐席听说模式 (1-4)
$res = $oneyun->callcenter->setConversationInviteAgent($conversation_id,$enqueue,$mode);

$conversation_id = '';  // 交谈ID
$to = '17606661993'; // 被叫号码
$max_answer_seconds = 180; // 最大通话时间
$options = array(
    'from'=>'', // 主叫号码
    'max_dial_seconds' => 60, // 最大拨号等待时间
    'mode'=>1 // 加入后的听/说模式
);
$res = $oneyun->callcenter->setConversationInviteOut($conversation_id,$to,$max_answer_seconds,$options);

$conversation_id = '';  // 交谈ID
$res = $oneyun->callcenter->findConversation($conversation_id);

$res = $oneyun->callcenter->findAllConversation();

$agent_name = 'test001'; // 坐席名称
$queue_id = ''; // 排队任务ID
$data =  'user_data'; // 自定义数据
$res = $oneyun->callcenter->setAgentRejectTask($agent_name,$queue_id,$data);

$agent_name = 'test001'; // 坐席名称
$to = '17606661993'; // 被叫号码
$max_answer_seconds = 180; // 最大通话时间
$options = array(
    'from'=>'', // 主叫号码
    'max_dial_seconds' => 60, // 最大拨号等待时间
    'user_data'=>'自定义数据' 
);
$res = $oneyun->callcenter->setAgentCallOut($agent_name,$to,$max_answer_seconds,$options);

$agent_name = 'test001'; // 坐席名称
$enqueue = '<enqueue wait_voice="wait.wav" ring_mode="1" play_num="true" user_data="test">
                <route><agent name="test001" priority="11" queue_timeout="60" fetch_timeout="50"></agent></route>
            </enqueue>'; // 目标坐席选择条件
            
$res = $oneyun->callcenter->setAgentCallAgent($agent_name,$enqueue);

$agent_name = 'test001'; // 坐席名称
$queue_task_id = '';
$enqueue = '<enqueue wait_voice="wait.wav" ring_mode="1" play_num="true" user_data="test">
                <route><agent name="test001" priority="11" queue_timeout="60" fetch_timeout="50"></agent></route>
            </enqueue>'; // 目标坐席选择条件
$res = $oneyun->callcenter->setAgentFwdAgent($agent_name,$queue_task_id,$enqueue);

$agent_name = 'test001'; // 坐席名称
$conversation_id = ''; // 交谈ID
$enqueue = '<enqueue wait_voice="wait.wav" ring_mode="1" play_num="true" user_data="test">
                <route><agent name="test001" priority="11" queue_timeout="60" fetch_timeout="50"></agent></route>
            </enqueue>'; // 目标坐席选择条件

$res = $oneyun->callcenter->setAgentXferAgent($agent_name,$conversation_id,$enqueue);

$agent_name = 'test001'; // 坐席名称
$conversation_id = ''; // 交谈ID
$max_answer_seconds = 180; // 最大通话时间
$options = array(
    'from'=>'', // 主叫号码
 );
$res = $oneyun->callcenter->setAgentXferOut($agent_name,$conversation_id,$to,$max_answer_seconds,$options);

$agent_name = 'test001'; // 坐席名称
$conversation_id = ''; // 交谈ID
$mode = 1; // 设置坐席听说模式 (1-4)
$res = $oneyun->callcenter->setAgentMode($agent_name,$conversation_id,$mode);

$agent_name = 'test001'; // 坐席名称
$conversation_id = ''; // 交谈ID
$mode = 1; // 设置坐席听说模式 (1-4)
$holding = true; 
$res = $oneyun->callcenter->setAgentEnter($agent_name,$conversation_id,$mode,$holding);

$agent_name = 'test001'; // 坐席名称
$conversation_id = ''; // 交谈ID
$res = $oneyun->callcenter->setAgentOut($agent_name,$conversation_id);

$agent_name = 'test001'; // 坐席名称
$src_conversation_id = ''; // 交谈ID1
$dst_conversation_id = ''; // 交谈ID2
$mode = 1; // 设置坐席听说模式 (1-4)
$res = $oneyun->callcenter->setAgentMerge($agent_name,$src_conversation_id,$dst_conversation_id,$mode);

$agent_name = 'test001'; // 坐席名称
$res = $oneyun->callcenter->findAgentConversation($agent_name);


Id = ""; //应用标识

$certId = ""; //鉴权Id

$apiUrl = ""; //接口地址

$secreKey = "";//密钥

$oneyun = new Oneyun\Rest\Client($appId, $certId, $apiUrl, $secreKey);

$options = [
    'callbackUrl' => 'http://101.200.135.23:8088/callback/1',
    'remark'=>'test3',
    'quotas' =>[]
];

$res = $oneyun->management->createSubAccount($options);

var_dump($res); //返回结果


$id = ''; // 子账号ID
$options = array(
    'callbackUrl'=>'http://...', // 回调url
    'remark'=> '', // 备注
    'enabled'=>1 // 是否启用
);
$res = $oneyun->callcenter->editSubAccount($id,$options);

$id = ''; // 子账号ID
$res = $oneyun->callcenter->deleteSubAccount($id);

$pageNo = 1;
$pageSize = 20;
$res = $oneyun->callcenter->findAllSubAccount($pageNo,$pageSize);

$id = ''; // 子账号ID
$res = $oneyun->callcenter->findSubAccount($id);

$id = ''; // 子账号ID
$quotas = array(
    array(
        'type'=>'AgentQuota', // 呼叫中心坐席配额
        'value'=>1000
    ),
    array(
        'type'=>'CallQuota', // 通话时长配额
        'value'=>1000
    ),
    array(
         'type'=>'ussdQuota', // 闪印配额
         'value'=>1000
    ),
    array(
          'type'=>'smsQuota', // 短信配额
          'value'=>1000
    )
);
$res = $oneyun->callcenter->setSubAccountQuotas($id,$quotas);

 $pageNo = 1;
 $pageSize = 20;
 $res = $oneyun->callcenter->findAllTelNum($pageNo,$pageSize);
 

  $pageNo = 1;
  $pageSize = 20;
  $res = $oneyun->callcenter->findAllTelNum($pageNo,$pageSize);
  

  $id = ''; // 号码资源ID
  $subaccountId = ''; // 子账号ID
  $res = $oneyun->callcenter->bindTelNum($id,$subaccountId);
  

  $id = ''; // 号码资源ID
  $subaccountId = ''; // 子账号ID
  $res = $oneyun->callcenter->unBindTelNum($id,$subaccountId);
  


 = new Oneyun\Ivr();
$ivr->play('文件名.wav');
$ivr->next('http://localhost/ivr.php?step=hangup');
//输出
echo $ivr;

$ivr = new Oneyun\Ivr();
$ivr->hangup();

echo $ivr;

$ivr = new Oneyun\Ivr();

$ivr->dial('17606661993');
$ivr->next('http://localhost/ivr.php?step=hangup');

echo $ivr;