首页 > 代码库 > 云通讯 添加群组
云通讯 添加群组
群组和双向回呼是一个级别的 应为他们都是属于子账户的操作 所以 他们的子帐号鉴权信息验证是一样
在sdk包里添加
/** 添加组 */ function CreateGroup($Group) { //子帐号鉴权信息验证,对必选参数进行判空。 $auth=$this->subAuth(); if($auth!=""){ return $auth; } // 拼接请求包体 if($this->BodyType=="json"){ $body= "{‘from‘:‘$from‘,‘to‘:‘$to‘,‘customerSerNum‘:‘$customerSerNum‘,‘fromSerNum‘:‘$fromSerNum‘,‘promptTone‘:‘$promptTone‘}"; }else{ $body= "<Request> <name>$Group</name> <type>0</type> <permission>0</permission> <declared>云通讯技术交流</declared></Request> "; } $this->showlog("request body = ".$body); // 大写的sig参数 $sig = strtoupper(md5($this->SubAccountSid . $this->SubAccountToken . $this->Batch)); // 生成请求URL $url="https://$this->ServerIP:$this->ServerPort/$this->SoftVersion/SubAccounts/$this->SubAccountSid/Group/CreateGroup?sig=$sig"; $this->showlog("request url = ".$url); // 生成授权:子帐号Id + 英文冒号 + 时间戳 $authen=base64_encode($this->SubAccountSid . ":" . $this->Batch); // 生成包头 $header = array("Accept:application/$this->BodyType","Content-Type:application/$this->BodyType;charset=utf-8","Authorization:$authen"); // 发请求 $result = $this->curl_post($url,$body,$header); $this->showlog("response body = ".$result); if($this->BodyType=="json"){//JSON格式 $datas=json_decode($result); }else{ //xml格式 $datas = simplexml_load_string(trim($result," \t\n\r")); } // if($datas == FALSE){// $datas = new stdClass();// $datas->statusCode = ‘172003‘;// $datas->statusMsg = ‘返回包体错误‘; // } return $datas; }
再自己新建一个调用文件,我起的名字叫做CreateGroup.php
<?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("../SDK/CCPRestSDK.php");//子帐号$subAccountSid= ‘f8d6accb8da811e4823dac853d9f54f2‘;//子帐号Token$subAccountToken= ‘0b9db4c881d30a5e6c098f735797ec68‘;//VoIP帐号$voIPAccount= ‘84121800000047‘;//VoIP密码$voIPPassword= ‘dWRm3ZE6‘;//应用Id$appId=‘aaf98f894a70a61d014a8413a5790c04‘;//请求地址,格式如下,不需要写https://$serverIP=‘sandboxapp.cloopen.com‘;//请求端口 $serverPort=‘8883‘;//REST版本号$softVersion=‘2013-12-26‘;/** * 双向回呼 * @param from 主叫电话号码 * @param to 被叫电话号码 * @param customerSerNum 被叫侧显示的客服号码 * @param fromSerNum 主叫侧显示的号码 * @param promptTone 自定义回拨提示音 */function CreateGroup($Group){ // 初始化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 create a group , $Group <br/>"; $result = $rest->CreateGroup($Group); 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 $Group success<br/>"; // 获取返回信息 //$subaccount = $result->SubAccount; echo "statusCode:".$result->statusCode."<br/>"; echo "groupId:".$result->groupId."<br/>";//echo "statusCode:".$subaccount->statusCode."<br/>";//echo "groupId:".$subaccount->groupId."<br/>"; //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 添加成功处理逻辑 } }//Demo调用 CreateGroup("123");//createSubAccount("子帐号名称");?>
尽量留下原来例子的语法,便于及时的参考
效果图
重点就是鉴权的验证,子账户当然不能和主账号混为一谈。
云通讯 添加群组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。