├── CHANGELOG ├── README ├── TimRestApi.php ├── TimRestApiConfig.json ├── TimRestApiGear.php ├── TimRestInterface.php └── signature ├── linux-signature32 ├── linux-signature64 ├── windows-signature32.exe └── windows-signature64.exe /CHANGELOG: -------------------------------------------------------------------------------- 1 | v1.1 2 | 2015/12/02 3 | 1. 提供上传大图能力。 4 | 2. 优化图片发送速度。 5 | 6 | v1.2 7 | 2015/12/07 8 | 1. 兼容Windows系统。 9 | 10 | v1.3 11 | 1. 增加独立模式帐号同步接口 12 | 13 | v.1.4 14 | 1. 增加转让群组接口 15 | 2. 增加导入群基础资料接口 16 | 3. 增加导入群成员接口 17 | 4. 增加设置成员未读计数接口 18 | 5. 增加托管模式存量帐号导入接口 19 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 工具目录结构: 2 | . 3 | ├── README 4 | ├── signature 5 | │ ├── linux-signature32 6 | │ └── linux-signature64 7 | ├── TimRestApiConfig.json 8 | ├── TimRestApiGear.php 9 | ├── TimRestApi.php 10 | ├── TimRestInterface.php 11 | 12 | signature文件夹 包含获取usrsig的脚本,在使用工具前需要确保该目录中对应文件的权限, 13 | 比如linux64位则需要确保linux-signature64的权限为可执行。 14 | 15 | TimRestApiConfig.json 为该工具所需APP基础配置信息。 16 | 17 | TimRestApiGear.php 为使用接口示例工具 18 | 19 | TimRestApi.php 为接口具体实现。 20 | TimRestInterface.php 为访问rest api示例的接口集合。 21 | 22 | 23 | 使用步骤: 24 | 25 | 独立模式 26 | 1.配置TimRestApiConfig.json文件,其中: 27 | identifier 为APP管理者账户; 28 | private_pem_path 为本地私钥位置; 29 | user_sig 请填""。 30 | 2.查看signature文件夹中对应脚本使用权限,如果无可执行权限,需要修改权限使其可被执行。 31 | 3.执行php TimRestApiGear.php 可看到该工具访问命令(用法)。 32 | 33 | 托管模式 34 | 1.配置TimRestApiConfig.json文件,其中: 35 | identifier 为APP管理者账户; 36 | user_sig 为托管模式用户下载到的用户凭证; 37 | private_pem_path 请填""。 38 | 2.执行php TimRestApiGear.php 可看到该工具访问命令(用法)。 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /TimRestApi.php: -------------------------------------------------------------------------------- 1 | sdkappid = $sdkappid; 28 | $this->identifier = $identifier; 29 | } 30 | 31 | /** 32 | * 构造访问REST服务器的参数,并访问REST接口 33 | * @param string $server_name 服务名 34 | * @param string $cmd_name 命令名 35 | * @param string $identifier 用户名 36 | * @param string $usersig 用来鉴权的usersig 37 | * @param string $req_data 传递的json结构 38 | * $param bool $print_flag 是否打印请求,默认为打印 39 | * @return string $out 返回的签名字符串 40 | */ 41 | public function api($service_name, $cmd_name, $identifier, $usersig, $req_data, $print_flag = true) 42 | { 43 | //$req_tmp用来做格式化输出 44 | $req_tmp = json_decode($req_data, true); 45 | # 构建HTTP请求参数,具体格式请参考 REST API接口文档 (http://avc.qcloud.com/wiki/im/)(即时通信云-数据管理REST接口) 46 | $parameter = "usersig=" . $this->usersig 47 | . "&identifier=" . $this->identifier 48 | . "&sdkappid=" . $this->sdkappid 49 | . "&contenttype=" . $this->contenttype; 50 | $url = $this->http_type . $this->im_yun_url . '/' . $this->version . '/' . $service_name . '/' .$cmd_name . '?' . $parameter; 51 | 52 | if($print_flag) 53 | { 54 | echo "Request Url:\n"; 55 | echo $url; 56 | echo "\n"; 57 | echo "Request Body:\n"; 58 | echo json_format($req_tmp); 59 | echo "\n"; 60 | } 61 | $ret = $this->http_req('https', 'post', $url, $req_data); 62 | return $ret; 63 | 64 | } 65 | 66 | /** 67 | * 构造访问REST服务器参数,并发访问REST服务器 68 | * @param string $server_name 服务名 69 | * @param string $cmd_name 命令名 70 | * @param string $identifier 用户名 71 | * @param string $usersig 用来鉴权的usersig 72 | * @param string $req_data 传递的json结构 73 | * $param bool $print_flag 是否打印请求,默认为打印 74 | * @return string $out 返回的签名字符串 75 | */ 76 | public function multi_api($service_name, $cmd_name, $identifier, $usersig, $req_data, $print_flag = true) 77 | { 78 | 79 | //$req_tmp用来做格式化控制台输出,同时作为多路访问需要的数组结构 80 | $req_tmp = json_decode($req_data, true); 81 | # 构建HTTP请求参数,具体格式请参考 REST API接口文档 (http://avc.qcloud.com/wiki/im/)(即时通信云-数据管理REST接口) 82 | $parameter = "usersig=" . $this->usersig 83 | . "&identifier=" . $this->identifier 84 | . "&sdkappid=" . $this->sdkappid 85 | . "&contenttype=" . $this->contenttype; 86 | 87 | $url = $this->http_type . $this->im_yun_url . '/' . $this->version . '/' . $service_name . '/' .$cmd_name . '?' . $parameter; 88 | 89 | if($print_flag) 90 | { 91 | echo "Request Url:\n"; 92 | echo $url; 93 | echo "\n"; 94 | echo "Request Body:\n"; 95 | echo json_format($req_tmp); 96 | echo "\n"; 97 | } 98 | $ret = $this->http_req_multi('https', 'post', $url, $req_tmp); 99 | return $ret; 100 | 101 | } 102 | 103 | /** 104 | * 独立模式根据Identifier生成UserSig的方法 105 | * @param int $identifier 用户账号 106 | * @param int $expiry_after 过期时间 107 | * @param string $protected_key_path 私钥的存储路径及文件名 108 | * @return string $out 返回的签名字符串 109 | */ 110 | public function generate_user_sig($identifier, $expiry_after, $protected_key_path, $tool_path) 111 | { 112 | 113 | # 这里需要写绝对路径,开发者根据自己的路径进行调整 114 | $command = escapeshellarg($tool_path) 115 | . ' '. escapeshellarg($protected_key_path) 116 | . ' ' . escapeshellarg($this->sdkappid) 117 | . ' ' .escapeshellarg($identifier); 118 | $ret = exec($command, $out, $status); 119 | if( $status == -1) 120 | { 121 | return null; 122 | } 123 | $this->usersig = $out[0]; 124 | return $out; 125 | } 126 | 127 | /** 128 | * 托管模式设置用户凭证 129 | * @param string $protected_key_path 私钥的存储路径及文件名 130 | * @return bool 返回成功与否 131 | */ 132 | public function set_user_sig($usr_sig) 133 | { 134 | $this->usersig = $usr_sig; 135 | return true; 136 | } 137 | 138 | /** 139 | * 向Rest服务器发送请求 140 | * @param string $http_type http类型,比如https 141 | * @param string $method 请求方式,比如POST 142 | * @param string $url 请求的url 143 | * @return string $data 请求的数据 144 | */ 145 | public static function http_req($http_type, $method, $url, $data) 146 | { 147 | $ch = curl_init(); 148 | if (strstr($http_type, 'https')) 149 | { 150 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 151 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 152 | } 153 | 154 | if ($method == 'post') 155 | { 156 | curl_setopt($ch, CURLOPT_POST, 1); 157 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 158 | } else 159 | { 160 | $url = $url . '?' . $data; 161 | } 162 | curl_setopt($ch, CURLOPT_URL, $url); 163 | curl_setopt($ch, CURLOPT_HEADER, 0); 164 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 165 | curl_setopt($ch, CURLOPT_TIMEOUT,100000);//超时时间 166 | 167 | try 168 | { 169 | $ret=curl_exec($ch); 170 | }catch(Exception $e) 171 | { 172 | curl_close($ch); 173 | return json_encode(array('ret'=>0,'msg'=>'failure')); 174 | } 175 | curl_close($ch); 176 | return $ret; 177 | } 178 | 179 | /** 180 | * 向Rest服务器发送多个请求(并发) 181 | * @param string $http_type http类型,比如https 182 | * @param string $method 请求方式,比如POST 183 | * @param string $url 请求的url 184 | * @return bool 是否成功 185 | */ 186 | public static function http_req_multi($http_type, $method, $url, $data) 187 | { 188 | $mh = curl_multi_init(); 189 | $ch_list = array(); 190 | $i = -1; 191 | $req_list = array(); 192 | foreach($data as $req_data) 193 | { 194 | $i++; 195 | $req_data = json_encode($req_data); 196 | $ch = curl_init(); 197 | if ($http_type == 'https://') 198 | { 199 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 200 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); 201 | } 202 | 203 | if ($method == 'post') 204 | { 205 | curl_setopt($ch, CURLOPT_POST, 1); 206 | curl_setopt($ch, CURLOPT_POSTFIELDS, $req_data); 207 | } else 208 | { 209 | $url = $url . '?' . $data; 210 | } 211 | curl_setopt($ch, CURLOPT_URL, $url); 212 | curl_setopt($ch, CURLOPT_HEADER, 0); 213 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 214 | curl_setopt($ch, CURLOPT_TIMEOUT,100000);//超时时间 215 | curl_multi_add_handle($mh, $ch); 216 | $ch_list[] = $ch; 217 | $req_list[] = $req_data; 218 | } 219 | try 220 | { 221 | do{ 222 | $mret = curl_multi_exec($mh, $active); 223 | }while($mret == CURLM_CALL_MULTI_PERFORM); 224 | 225 | while($active and $mret == CURLM_OK){ 226 | if(curl_multi_select($mh) === -1){ 227 | usleep(100); 228 | } 229 | do{ 230 | $mret = curl_multi_exec($mh, $active); 231 | }while($mret == CURLM_CALL_MULTI_PERFORM); 232 | } 233 | }catch(Exception $e) 234 | { 235 | curl_close($ch); 236 | return json_encode(array('ret'=>0,'msg'=>'failure')); 237 | } 238 | for($i = 0; $i < count($ch_list); $i++) 239 | { 240 | $ret = curl_multi_getcontent($ch_list[$i]); 241 | if(strstr($ret, "URL_INFO")) 242 | { 243 | curl_multi_close($mh); 244 | return $ret; 245 | } 246 | $ret = json_decode($ret, true); 247 | echo json_format($ret); 248 | } 249 | curl_multi_close($mh); 250 | return true; 251 | } 252 | 253 | #REST API 访问接口集合 254 | #参数详情见RestInterface 255 | 256 | public function openim_send_msg($account_id, $receiver, $text_content) 257 | { 258 | 259 | #构造高级接口所需参数 260 | $msg_content = array(); 261 | //创建array 所需元素 262 | $msg_content_elem = array( 263 | 'MsgType' => 'TIMTextElem', //文本类型 264 | 'MsgContent' => array( 265 | 'Text' => $text_content, //hello 为文本信息 266 | ) 267 | ); 268 | //将创建的元素$msg_content_elem, 加入array $msg_content 269 | array_push($msg_content, $msg_content_elem); 270 | 271 | $ret = $this->openim_send_msg2($account_id, $receiver, $msg_content); 272 | return $ret; 273 | } 274 | 275 | public function openpic_pic_upload($account_id, $receiver, $pic_path, $busi_type) 276 | { 277 | 278 | #获取长度和md5值 279 | $pic_data = file_get_contents($pic_path); 280 | $md5 = md5($pic_data); 281 | $pic_size = filesize($pic_path); 282 | 283 | #进行base64处理 284 | $fp = fopen($pic_path, "r"); 285 | $pic_data = fread($fp, $pic_size); 286 | 287 | $slice_data = array(); 288 | $slice_size = array(); 289 | $SLICE_SIZE = 32*4096; 290 | 291 | //对文件进行分片 292 | for($i = 0; $i < $pic_size; $i = $i + $SLICE_SIZE) 293 | { 294 | if($i + $SLICE_SIZE > $pic_size) 295 | { 296 | break; 297 | } 298 | $slice_tmp = substr($pic_data, $i, $SLICE_SIZE); 299 | $slice_tmp = chunk_split(base64_encode($slice_tmp)); 300 | $slice_tmp = str_replace("\r\n", '', $slice_tmp); 301 | $slice_size[] = $SLICE_SIZE; 302 | $slice_data[] = $slice_tmp; 303 | } 304 | 305 | //最后一个分片 306 | if($i - $SLICE_SIZE < $pic_size) 307 | { 308 | $slice_size[] = $pic_size-$i; 309 | $tmp = substr($pic_data, $i, $pic_size-$i); 310 | $slice_size[] = strlen($tmp); 311 | $tmp = chunk_split(base64_encode($tmp)); 312 | $tmp = str_replace("\r\n", '', $tmp); 313 | 314 | $slice_data[] = $tmp; 315 | } 316 | 317 | $pic_rand = rand(1, 65535); 318 | $time_stamp = time(); 319 | $req_data_list = array(); 320 | $sentOut = 0; 321 | printf("handle %d segments\n", count($slice_data)-1); 322 | for($i = 0; $i < count($slice_data)-1; $i++) 323 | { 324 | #构造消息 325 | $msg = array( 326 | "From_Account" => $account_id, //发送者 327 | "To_Account" => $receiver, //接收者 328 | "App_Version" => 1.4, //应用版本号 329 | "Seq" => $i+1, //同一个分片需要保持一致 330 | "Timestamp" => $time_stamp, //同一张图片的不同分片需要保持一致 331 | "Random" => $pic_rand, //同一张图片的不同分片需要保持一致 332 | "File_Str_Md5" => $md5, //图片MD5,验证图片的完整性 333 | "File_Size" => $pic_size, //图片原始大小 334 | "Busi_Id" => $busi_type, //群消息:1 c2c消息:2 个人头像:3 群头像:4 335 | "PkgFlag" => 1, //同一张图片要保持一致: 0表示图片数据没有被处理 ;1-表示图片经过base64编码,固定为1 336 | "Slice_Offset" => $i*$SLICE_SIZE, //必须是4K的整数倍 337 | "Slice_Size" => $slice_size[$i], //必须是4K的整数倍,除最后一个分片列外 338 | "Slice_Data" => $slice_data[$i] //PkgFlag=1时,为base64编码 339 | ); 340 | array_push($req_data_list, $msg); 341 | $sentOut = 0; 342 | if ($i != 0 && ($i+1) % 4 == 0) 343 | { 344 | //将消息序列化为json串 345 | $req_data_list = json_encode($req_data_list); 346 | printf("\ni = %d, call multi_api once\n", $i); 347 | $ret = $this->multi_api("openpic", "pic_up", $this->identifier, $this->usersig, $req_data_list, false); 348 | if(gettype($ret) == "string") 349 | { 350 | $ret = json_decode($ret, true); 351 | return $ret; 352 | } 353 | $req_data_list = array(); 354 | $sentOut = 1; 355 | } 356 | } 357 | 358 | if ($sentOut == 0) 359 | { 360 | $req_data_list = json_encode($req_data_list); 361 | printf("\ni = %d, call multi_api once\n", $i); 362 | $this->multi_api("openpic", "pic_up", $this->identifier, $this->usersig, $req_data_list, false); 363 | } 364 | 365 | #最后一个分片 366 | $msg = array( 367 | "From_Account" => $account_id, //发送者 368 | "To_Account" => $receiver, //接收者 369 | "App_Version" => 1.4, //应用版本号 370 | "Seq" => $i+1, //同一个分片需要保持一致 371 | "Timestamp" => $time_stamp, //同一张图片的不同分片需要保持一致 372 | "Random" => $pic_rand, //同一张图片的不同分片需要保持一致 373 | "File_Str_Md5" => $md5, //图片MD5,验证图片的完整性 374 | "File_Size" => $pic_size, //图片原始大小 375 | "Busi_Id" => $busi_type, //群消息:1 c2c消息:2 个人头像:3 群头像:4 376 | "PkgFlag" => 1, //同一张图片要保持一致: 0表示图片数据没有被处理 ;1-表示图片经过base64编码,固定为1 377 | "Slice_Offset" => $i*$SLICE_SIZE, //必须是4K的整数倍 378 | "Slice_Size" => $slice_size[count($slice_data)-1], //必须是4K的整数倍,除最后一个分片列外 379 | "Slice_Data" => $slice_data[count($slice_data)-1] //PkgFlag=1时,为base64编码 380 | ); 381 | 382 | $req_data = json_encode($msg); 383 | $ret = $this->api("openpic", "pic_up", $this->identifier, $this->usersig, $req_data, false); 384 | $ret = json_decode($ret, true); 385 | echo json_format($ret); 386 | return $ret; 387 | } 388 | 389 | public function openim_send_msg_pic($account_id, $receiver, $pic_path) 390 | { 391 | 392 | #构造高级接口所需参数 393 | //上传图片并获取url 394 | $busi_type = 2; //表示C2C消息 395 | $ret = $this->openpic_pic_upload($account_id, $receiver, $pic_path, $busi_type); 396 | $tmp = $ret["URL_INFO"]; 397 | 398 | $uuid = $ret["File_UUID"]; 399 | $pic_url = $tmp[0]["DownUrl"]; 400 | 401 | $img_info = array(); 402 | $img_tmp = $ret["URL_INFO"][0]; 403 | if($img_tmp["PIC_TYPE"] == 4){ 404 | $img_tmp["PIC_TYPE"] = 3; 405 | } 406 | $img_info_elem1 = array( 407 | "URL" => $img_tmp["DownUrl"], 408 | "Height" => $img_tmp["PIC_Height"], 409 | "Size" => $img_tmp["PIC_Size"], 410 | "Type" => $img_tmp["PIC_TYPE"], 411 | "Width" => $img_tmp["PIC_Width"] 412 | ); 413 | 414 | $img_tmp = $ret["URL_INFO"][1]; 415 | if($img_tmp["PIC_TYPE"] == 4){ 416 | $img_tmp["PIC_TYPE"] = 3; 417 | } 418 | $img_info_elem2 = array( 419 | "URL" => $img_tmp["DownUrl"], 420 | "Height" => $img_tmp["PIC_Height"], 421 | "Size" => $img_tmp["PIC_Size"], 422 | "Type" => $img_tmp["PIC_TYPE"], 423 | "Width" => $img_tmp["PIC_Width"] 424 | ); 425 | 426 | $img_tmp = $ret["URL_INFO"][2]; 427 | if($img_tmp["PIC_TYPE"] == 4){ 428 | $img_tmp["PIC_TYPE"] = 3; 429 | } 430 | $img_info_elem3 = array( 431 | "URL" => $img_tmp["DownUrl"], 432 | "Height" => $img_tmp["PIC_Height"], 433 | "Size" => $img_tmp["PIC_Size"], 434 | "Type" => $img_tmp["PIC_TYPE"], 435 | "Width" => $img_tmp["PIC_Width"] 436 | ); 437 | 438 | array_push($img_info, $img_info_elem1); 439 | array_push($img_info, $img_info_elem2); 440 | array_push($img_info, $img_info_elem3); 441 | $msg_content = array(); 442 | //创建array 所需元素 443 | $msg_content_elem = array( 444 | 'MsgType' => 'TIMImageElem', //文本类型 445 | 'MsgContent' => array( 446 | 'UUID' => $uuid, 447 | 'ImageInfoArray' => $img_info, 448 | ) 449 | ); 450 | //将创建的元素$msg_content_elem, 加入array $msg_content 451 | array_push($msg_content, $msg_content_elem); 452 | 453 | $ret = $this->openim_send_msg2($account_id, $receiver, $msg_content); 454 | return $ret; 455 | } 456 | 457 | public function openim_send_msg2($account_id, $receiver, $msg_content) 458 | { 459 | 460 | #构造新消息 461 | $msg = array( 462 | 'To_Account' => $receiver, 463 | 'MsgSeq' => rand(1, 65535), 464 | 'MsgRandom' => rand(1, 65535), 465 | 'MsgTimeStamp' => time(), 466 | 'MsgBody' => $msg_content, 467 | 'From_Account' => $account_id 468 | ); 469 | #将消息序列化为json串 470 | $req_data = json_encode($msg); 471 | 472 | $ret = $this->api("openim", "sendmsg", $this->identifier, $this->usersig, $req_data); 473 | $ret = json_decode($ret, true); 474 | return $ret; 475 | } 476 | 477 | public function openim_batch_sendmsg($account_list, $text_content) 478 | { 479 | 480 | #构造高级接口所需参数 481 | $msg_content = array(); 482 | //创建array 所需元素 483 | $msg_content_elem = array( 484 | 'MsgType' => 'TIMTextElem', //文本类型 485 | 'MsgContent' => array( 486 | 'Text' => $text_content, //hello 为文本信息 487 | ) 488 | ); 489 | //将创建的元素$msg_content_elem, 加入array $msg_content 490 | array_push($msg_content, $msg_content_elem); 491 | 492 | $ret = $this->openim_batch_sendmsg2($account_list, $msg_content); 493 | return $ret; 494 | } 495 | 496 | public function openim_batch_sendmsg_pic($account_list, $pic_path) 497 | { 498 | 499 | #构造高级接口所需参数 500 | //上传图片并获取url 501 | $busi_type = 2; //表示C2C消息 502 | $ret = $this->openpic_pic_upload($this->identifier, $account_list[0], $pic_path, $busi_type); 503 | $tmp = $ret["URL_INFO"]; 504 | 505 | $uuid = $ret["File_UUID"]; 506 | $pic_url = $tmp[0]["DownUrl"]; 507 | 508 | $img_info = array(); 509 | $img_tmp = $ret["URL_INFO"][0]; 510 | if($img_tmp["PIC_TYPE"] == 4){ 511 | $img_tmp["PIC_TYPE"] = 3; 512 | } 513 | $img_info_elem1 = array( 514 | "URL" => $img_tmp["DownUrl"], 515 | "Height" => $img_tmp["PIC_Height"], 516 | "Size" => $img_tmp["PIC_Size"], 517 | "Type" => $img_tmp["PIC_TYPE"], 518 | "Width" => $img_tmp["PIC_Width"] 519 | ); 520 | 521 | $img_tmp = $ret["URL_INFO"][1]; 522 | if($img_tmp["PIC_TYPE"] == 4){ 523 | $img_tmp["PIC_TYPE"] = 3; 524 | } 525 | $img_info_elem2 = array( 526 | "URL" => $img_tmp["DownUrl"], 527 | "Height" => $img_tmp["PIC_Height"], 528 | "Size" => $img_tmp["PIC_Size"], 529 | "Type" => $img_tmp["PIC_TYPE"], 530 | "Width" => $img_tmp["PIC_Width"] 531 | ); 532 | 533 | $img_tmp = $ret["URL_INFO"][2]; 534 | if($img_tmp["PIC_TYPE"] == 4){ 535 | $img_tmp["PIC_TYPE"] = 3; 536 | } 537 | $img_info_elem3 = array( 538 | "URL" => $img_tmp["DownUrl"], 539 | "Height" => $img_tmp["PIC_Height"], 540 | "Size" => $img_tmp["PIC_Size"], 541 | "Type" => $img_tmp["PIC_TYPE"], 542 | "Width" => $img_tmp["PIC_Width"] 543 | ); 544 | 545 | array_push($img_info, $img_info_elem1); 546 | array_push($img_info, $img_info_elem2); 547 | array_push($img_info, $img_info_elem3); 548 | $msg_content = array(); 549 | //创建array 所需元素 550 | $msg_content_elem = array( 551 | 'MsgType' => 'TIMImageElem', //文本类型 552 | 'MsgContent' => array( 553 | 'UUID' => $uuid, 554 | 'ImageInfoArray' => $img_info, 555 | ) 556 | ); 557 | //将创建的元素$msg_content_elem, 加入array $msg_content 558 | array_push($msg_content, $msg_content_elem); 559 | 560 | $ret = $this->openim_batch_sendmsg2($account_list, $msg_content); 561 | return $ret; 562 | } 563 | 564 | public function openim_batch_sendmsg2($account_list, $msg_content) 565 | { 566 | 567 | #构造新消息 568 | $msg = array( 569 | 'To_Account' => $account_list, 570 | 'MsgRandom' => rand(1, 65535), 571 | 'MsgBody' => $msg_content, 572 | ); 573 | #将消息序列化为json串 574 | $req_data = json_encode($msg); 575 | 576 | $ret = $this->api("openim", "batchsendmsg", $this->identifier, $this->usersig, $req_data); 577 | $ret = json_decode($ret, true); 578 | return $ret; 579 | } 580 | 581 | public function account_import($identifier, $nick, $face_url) 582 | { 583 | 584 | #构造新消息 585 | $msg = array( 586 | 'Identifier' => $identifier, 587 | 'Nick' => $nick, 588 | 'FaceUrl' => $face_url, 589 | ); 590 | #将消息序列化为json串 591 | $req_data = json_encode($msg); 592 | 593 | $ret = $this->api("im_open_login_svc", "account_import", $this->identifier, $this->usersig, $req_data); 594 | $ret = json_decode($ret, true); 595 | return $ret; 596 | } 597 | 598 | public function register_account($identifier, $identifierType, $password) 599 | { 600 | 601 | #构造新消息 602 | $msg = array( 603 | 'Identifier' => $identifier, 604 | 'IdentifierType' => $identifierType, 605 | 'Password' => $password, 606 | ); 607 | #将消息序列化为json串 608 | $req_data = json_encode($msg); 609 | 610 | $ret = $this->api("registration_service", "register_account_v1", $this->identifier, $this->usersig, $req_data); 611 | $ret = json_decode($ret, true); 612 | return $ret; 613 | } 614 | 615 | public function profile_portrait_get($account_id) 616 | { 617 | 618 | #构造高级接口所需参数 619 | $account_list = array(); 620 | array_push($account_list, $account_id); 621 | $tag_list = array( 622 | "Tag_Profile_IM_Nick", 623 | "Tag_Profile_IM_AllowType" 624 | ); 625 | 626 | $ret = $this->profile_portrait_get2($account_list, $tag_list); 627 | return $ret; 628 | } 629 | 630 | public function profile_portrait_get2($account_list, $tag_list) 631 | { 632 | 633 | #构造高级接口所需参数 634 | $msg = array( 635 | 'From_Account' => $this->identifier, 636 | 'To_Account' => $account_list, 637 | 'TagList' => $tag_list, 638 | 'LastStandardSequence' => 0 639 | ); 640 | #将消息序列化为json串 641 | $req_data = json_encode($msg); 642 | 643 | $ret = $this->api("profile", "portrait_get", $this->identifier, $this->usersig, $req_data); 644 | $ret = json_decode($ret, true); 645 | return $ret; 646 | } 647 | 648 | public function profile_portrait_set($account_id, $new_name) 649 | { 650 | 651 | #构造高级接口所需参数 652 | $profile_list = array(); 653 | $profile_nick = array( 654 | "Tag" => "Tag_Profile_IM_Nick", 655 | "Value" => $new_name 656 | ); 657 | //加好友验证方式 658 | $profile_allow = array( 659 | "Tag" => "Tag_Profile_IM_AllowType", 660 | "Value" => "NeedPermission" 661 | ); 662 | array_push($profile_list, $profile_nick); 663 | //array_push($profile_list, $profile_allow); 664 | 665 | $ret = $this->profile_portrait_set2($account_id, $profile_list); 666 | return $ret; 667 | } 668 | 669 | public function profile_portrait_set2($account_id, $profile_list) 670 | { 671 | 672 | #构造新消息 673 | $msg = array( 674 | 'From_Account' => $account_id, 675 | 'ProfileItem' => $profile_list 676 | ); 677 | #将消息序列化为json串 678 | $req_data = json_encode($msg); 679 | 680 | $ret = $this->api("profile", "portrait_set", $this->identifier, $this->usersig, $req_data); 681 | $ret = json_decode($ret, true); 682 | return $ret; 683 | } 684 | 685 | public function sns_friend_import($account_id, $receiver) 686 | { 687 | 688 | #构造新消息 689 | $msg = array( 690 | 'From_Account' => $account_id, 691 | 'AddFriendItem' => array() 692 | ); 693 | $receiver_arr = array( 694 | 'To_Account' => $receiver, 695 | 'Remark' => "", 696 | 'AddSource' => "AddSource_Type_Unknow", 697 | 'AddWording' => "" 698 | ); 699 | array_push($msg['AddFriendItem'], $receiver_arr); 700 | #将消息序列化为json串 701 | $req_data = json_encode($msg); 702 | 703 | $ret = $this->api("sns", "friend_import", $this->identifier, $this->usersig, $req_data); 704 | $ret = json_decode($ret, true); 705 | return $ret; 706 | } 707 | 708 | 709 | public function sns_friend_delete($account_id, $frd_id) 710 | { 711 | 712 | #构造新消息 713 | $frd_list = array(); 714 | //要添加的好友用户 715 | array_push($frd_list, $frd_id); 716 | 717 | $msg = array( 718 | 'From_Account' => $account_id, 719 | 'To_Account' => $frd_list, 720 | 'DeleteType' => "Delete_Type_Both" 721 | ); 722 | #将消息序列化为json串 723 | $req_data = json_encode($msg); 724 | 725 | $ret = $this->api("sns", "friend_delete", $this->identifier, $this->usersig, $req_data); 726 | $ret = json_decode($ret, true); 727 | return $ret; 728 | } 729 | 730 | public function sns_friend_delete_all($account_id) 731 | { 732 | 733 | #构造新消息 734 | $msg = array( 735 | 'From_Account' => $account_id, 736 | ); 737 | #将消息序列化为json串 738 | $req_data = json_encode($msg); 739 | 740 | $ret = $this->api("sns", "friend_delete_all", $this->identifier, $this->usersig, $req_data); 741 | $ret = json_decode($ret, true); 742 | return $ret; 743 | } 744 | 745 | public function sns_friend_check($account_id, $to_account) 746 | { 747 | 748 | #构造高级接口所需参数 749 | $to_account_list = array(); 750 | //要添加的好友用户 751 | array_push($to_account_list, $to_account); 752 | 753 | $msg = array( 754 | 'From_Account' => $account_id, 755 | 'To_Account' => $to_account_list, 756 | ); 757 | 758 | $ret = $this->sns_friend_check2($account_id, $to_account_list, "CheckResult_Type_Both"); 759 | return $ret; 760 | } 761 | 762 | public function sns_friend_check2($account_id, $to_account_list, $check_type) 763 | { 764 | 765 | #构造新消息 766 | $msg = array( 767 | 'From_Account' => $account_id, 768 | 'To_Account' => $to_account_list, 769 | 'CheckType' => $check_type 770 | ); 771 | #将消息序列化为json串 772 | $req_data = json_encode($msg); 773 | 774 | $ret = $this->api("sns", "friend_check", $this->identifier, $this->usersig, $req_data); 775 | $ret = json_decode($ret, true); 776 | return $ret; 777 | } 778 | 779 | function sns_friend_get_all($account_id) 780 | { 781 | 782 | #构造高级接口所需参数 783 | $tag_list = array( 784 | "Tag_Profile_IM_Nick", 785 | "Tag_SNS_IM_Remark" 786 | ); 787 | 788 | $ret = $this->sns_friend_get_all2($account_id, $tag_list); 789 | return $ret; 790 | } 791 | 792 | function sns_friend_get_all2($account_id, $tag_list) 793 | { 794 | 795 | #构造新消息 796 | $msg = array( 797 | 'From_Account' => $account_id, 798 | 'TimeStamp' => 0, 799 | 'TagList' => $tag_list, 800 | 'LastStandardSequence' => 1, 801 | ); 802 | #将消息序列化为json串 803 | $req_data = json_encode($msg); 804 | 805 | $ret = $this->api("sns", "friend_get_all", $this->identifier, $this->usersig, $req_data); 806 | $ret = json_decode($ret, true); 807 | return $ret; 808 | } 809 | 810 | function sns_friend_get_list($account_id, $frd_id) 811 | { 812 | 813 | #构造高级接口所需参数 814 | $frd_list = array(); 815 | array_push($frd_list, $frd_id); 816 | $tag_list = array( 817 | "Tag_Profile_IM_Nick", 818 | "Tag_SNS_IM_Remark" 819 | ); 820 | 821 | $ret = $this->sns_friend_get_list2($account_id, $frd_list, $tag_list); 822 | return $ret; 823 | } 824 | 825 | function sns_friend_get_list2($account_id, $frd_list, $tag_list) 826 | { 827 | 828 | #构造新消息 829 | $msg = array( 830 | 'From_Account' => $account_id, 831 | 'To_Account' => $frd_list, 832 | 'TagList' => $tag_list, 833 | ); 834 | #将消息序列化为json串 835 | $req_data = json_encode($msg); 836 | 837 | $ret = $this->api("sns", "friend_get_list", $this->identifier, $this->usersig, $req_data); 838 | $ret = json_decode($ret, true); 839 | return $ret; 840 | } 841 | 842 | function group_get_appid_group_list() 843 | { 844 | 845 | #构造高级接口所需参数 846 | $ret = $this->group_get_appid_group_list2(50, null, null); 847 | return $ret; 848 | } 849 | 850 | function group_get_appid_group_list2($limit, $offset, $group_type) 851 | { 852 | 853 | #构造新消息 854 | $msg = array( 855 | 'Limit' => $limit, 856 | 'Offset' => $offset, 857 | 'GroupType' => $group_type 858 | ); 859 | #将消息序列化为json串 860 | $req_data = json_encode($msg); 861 | 862 | $ret = $this->api("group_open_http_svc", "get_appid_group_list", $this->identifier, $this->usersig, $req_data); 863 | $ret = json_decode($ret, true); 864 | return $ret; 865 | } 866 | 867 | function group_create_group($group_type, $group_name, $owner_id) 868 | { 869 | 870 | #构造高级接口所需参数 871 | $info_set = array( 872 | 'group_id' => null, 873 | 'introduction' => null, 874 | 'notification' => null, 875 | 'face_url' => null, 876 | 'max_member_num' => 500, 877 | ); 878 | $mem_list = array(); 879 | 880 | $ret = $this->group_create_group2($group_type, $group_name, $owner_id, $info_set, $mem_list); 881 | return $ret; 882 | } 883 | 884 | function group_create_group2($group_type, $group_name, $owner_id, $info_set, $mem_list) 885 | { 886 | 887 | #构造新消息 888 | $msg = array( 889 | 'Type' => $group_type, 890 | 'Name' => $group_name, 891 | 'Owner_Account' => $owner_id, 892 | 'GroupId' => $info_set['group_id'], 893 | 'Introduction' => $info_set['introduction'], 894 | 'Notification' => $info_set['notification'], 895 | 'FaceUrl' => $info_set['face_url'], 896 | 'MaxMemberCount' => $info_set['max_member_num'], 897 | // 'ApplyJoinOption' => $info_set['apply_join'], 898 | 'MemberList' => $mem_list 899 | ); 900 | #将消息序列化为json串 901 | $req_data = json_encode($msg); 902 | 903 | $ret = $this->api("group_open_http_svc", "create_group", $this->identifier, $this->usersig, $req_data); 904 | $ret = json_decode($ret, true); 905 | return $ret; 906 | } 907 | 908 | function group_change_group_owner($group_id, $new_owner) 909 | { 910 | 911 | #构造新消息 912 | $msg = array( 913 | 'GroupId' => $group_id, 914 | 'NewOwner_Account' => $new_owner 915 | ); 916 | #将消息序列化为json串 917 | $req_data = json_encode($msg); 918 | 919 | $ret = $this->api("group_open_http_svc", "change_group_owner", $this->identifier, $this->usersig, $req_data); 920 | $ret = json_decode($ret, true); 921 | return $ret; 922 | } 923 | function group_get_group_info($group_id) 924 | { 925 | 926 | #构造高级接口所需参数 927 | $group_list = array(); 928 | array_push($group_list, $group_id); 929 | 930 | $base_info_filter = array( 931 | "Type", //群类型(包括Public(公开群), Private(私密群), ChatRoom(聊天室)) 932 | "Name", //群名称 933 | "Introduction", //群简介 934 | "Notification", //群公告 935 | "FaceUrl", //群头像url地址 936 | "CreateTime", //群组创建时间 937 | "Owner_Account", //群主id 938 | "LastInfoTime", //最后一次系统通知时间 939 | "LastMsgTime", //最后一次消息发送时间 940 | "MemberNum", //群组当前成员数目 941 | "MaxMemberNum", //群组内最大成员数目 942 | "ApplyJoinOption" //加群处理方式(比如FreeAccess 自由加入) 943 | ); 944 | $member_info_filter = array( 945 | "Account", // 成员ID 946 | "Role", // 成员身份 947 | "JoinTime", // 成员加入时间 948 | "LastSendMsgTime", // 该成员最后一次发送消息时间 949 | "ShutUpUntil" // 该成员被禁言直到某时间 950 | ); 951 | $app_define_filter = array( 952 | "GroupTestData1", //自定义数据 953 | ); 954 | 955 | $ret = $this->group_get_group_info2($group_list, $base_info_filter, $member_info_filter, $app_define_filter); 956 | return $ret; 957 | } 958 | 959 | function group_get_group_info2($group_list, $base_info_filter, $member_info_filter, $app_define_filter) 960 | { 961 | 962 | #构造新消息 963 | $filter = new Filter(); 964 | $filter->GroupBaseInfoFilter = $base_info_filter; 965 | $filter->MemberInfoFilter = $member_info_filter; 966 | $filter->AppDefinedDataFilter_Group = $app_define_filter; 967 | $msg = array( 968 | 'GroupIdList' => $group_list, 969 | 'ResponseFilter' => $filter 970 | ); 971 | #将消息序列化为json串 972 | $req_data = json_encode($msg); 973 | 974 | $ret = $this->api("group_open_http_svc", "get_group_info", $this->identifier, $this->usersig, $req_data); 975 | $ret = json_decode($ret, true); 976 | return $ret; 977 | } 978 | 979 | function group_get_group_member_info($group_id, $limit, $offset) 980 | { 981 | 982 | #构造新消息 983 | $msg = array( 984 | "GroupId" => $group_id, 985 | "Limit" => $limit, 986 | "Offset" => $offset 987 | ) 988 | ; 989 | #将消息序列化为json串 990 | $req_data = json_encode($msg); 991 | 992 | $ret = $this->api("group_open_http_svc", "get_group_member_info", $this->identifier, $this->usersig, $req_data); 993 | $ret = json_decode($ret, true); 994 | return $ret; 995 | } 996 | 997 | function group_modify_group_base_info($group_id, $group_name) 998 | { 999 | 1000 | #构造高级接口所需参数 1001 | $info_set = array( 1002 | 'introduction' => null, 1003 | 'notification' => null, 1004 | 'face_url' => null, 1005 | 'max_member_num' => null, 1006 | // 'apply_join' => "NeedPermission" 1007 | ); 1008 | $app_define_list = array(); 1009 | 1010 | $ret = $this->group_modify_group_base_info2($group_id, $group_name, $info_set, $app_define_list); 1011 | return $ret; 1012 | } 1013 | 1014 | function group_modify_group_base_info2($group_id, $group_name, $info_set, $app_define_list) 1015 | { 1016 | 1017 | #构造新消息 1018 | $msg = array( 1019 | "GroupId" => $group_id, 1020 | "Name" => $group_name, 1021 | "Introduction" => $info_set['introduction'], 1022 | "Notification" => $info_set['notification'], 1023 | "FaceUrl" => $info_set['face_url'], 1024 | "MaxMemberNum" => $info_set['max_member_num'], 1025 | // "ApplyJoinOption" => $info_set['apply_join'], 1026 | "AppDefinedData" => $app_define_list 1027 | ); 1028 | #将消息序列化为json串 1029 | $req_data = json_encode($msg); 1030 | 1031 | $ret = $this->api("group_open_http_svc", "modify_group_base_info", $this->identifier, $this->usersig, $req_data); 1032 | $ret = json_decode($ret, true); 1033 | return $ret; 1034 | 1035 | } 1036 | function group_add_group_member($group_id, $member_id, $silence) 1037 | { 1038 | 1039 | #构造新消息 1040 | $mem_list = array(); 1041 | $mem_elem = array( 1042 | "Member_Account" => $member_id 1043 | ); 1044 | array_push($mem_list, $mem_elem); 1045 | $msg = array( 1046 | "GroupId" => $group_id, 1047 | "MemberList" => $mem_list, 1048 | "Silence" => $silence 1049 | ); 1050 | #将消息序列化为json串 1051 | $req_data = json_encode($msg); 1052 | 1053 | $ret = $this->api("group_open_http_svc", "add_group_member", $this->identifier, $this->usersig, $req_data); 1054 | $ret = json_decode($ret, true); 1055 | return $ret; 1056 | } 1057 | 1058 | function group_delete_group_member($group_id, $member_id, $silence) 1059 | { 1060 | 1061 | #构造新消息 1062 | $mem_list = array(); 1063 | array_push($mem_list, $member_id); 1064 | $msg = array( 1065 | "GroupId" => $group_id, 1066 | "MemberToDel_Account" => $mem_list, 1067 | "Silence" => $silence 1068 | ); 1069 | #将消息序列化为json串 1070 | $req_data = json_encode($msg); 1071 | 1072 | $ret = $this->api("group_open_http_svc", "delete_group_member", $this->identifier, $this->usersig, $req_data); 1073 | $ret = json_decode($ret, true); 1074 | return $ret; 1075 | } 1076 | 1077 | function group_modify_group_member_info($group_id, $account_id, $role) 1078 | { 1079 | 1080 | #构造高级接口所需参数 1081 | $ret = $this->group_modify_group_member_info2($group_id, $account_id, $role, "AcceptAndNotify", 0); 1082 | return $ret; 1083 | } 1084 | 1085 | function group_modify_group_member_info2($group_id, $account_id, $role, $msg_flag, $shutup_time) 1086 | { 1087 | 1088 | #构造新消息 1089 | $msg = array( 1090 | "GroupId" => $group_id, 1091 | "Member_Account" => $account_id, 1092 | "Role" => $role 1093 | ) 1094 | ; 1095 | #将消息序列化为json串 1096 | $req_data = json_encode($msg); 1097 | 1098 | $ret = $this->api("group_open_http_svc", "modify_group_member_info", $this->identifier, $this->usersig, $req_data); 1099 | $ret = json_decode($ret, true); 1100 | return $ret; 1101 | } 1102 | 1103 | function group_destroy_group($group_id) 1104 | { 1105 | 1106 | #构造新消息 1107 | $msg = array( 1108 | "GroupId" => $group_id, 1109 | ) 1110 | ; 1111 | #将消息序列化为json串 1112 | $req_data = json_encode($msg); 1113 | 1114 | $ret = $this->api("group_open_http_svc", "destroy_group", $this->identifier, $this->usersig, $req_data); 1115 | $ret = json_decode($ret, true); 1116 | return $ret; 1117 | } 1118 | 1119 | function group_get_joined_group_list($account_id) 1120 | { 1121 | 1122 | #构造高级接口所需参数 1123 | $base_info_filter = array( 1124 | "Type", //群类型(包括Public(公开群), Private(私密群), ChatRoom(聊天室)) 1125 | "Name", //群名称 1126 | "Introduction", //群简介 1127 | "Notification", //群公告 1128 | "FaceUrl", //群头像url地址 1129 | "CreateTime", //群组创建时间 1130 | "Owner_Account", //群主id 1131 | "LastInfoTime", //最后一次系统通知时间 1132 | "LastMsgTime", //最后一次消息发送时间 1133 | "MemberNum", //群组当前成员数目 1134 | "MaxMemberNum", //群组内最大成员数目 1135 | "ApplyJoinOption" //申请加群处理方式(比如FreeAccess 自由加入, NeedPermission 需要同意) 1136 | ); 1137 | 1138 | 1139 | $self_info_filter = array( 1140 | "Role", //群内身份(Amin/Member) 1141 | "JoinTime", //入群时间 1142 | "MsgFlag", //消息屏蔽类型 1143 | "UnreadMsgNum" //未读消息数量 1144 | ); 1145 | 1146 | $ret = $this->group_get_joined_group_list2($account_id, null, $base_info_filter, $self_info_filter); 1147 | return $ret; 1148 | } 1149 | 1150 | function group_get_joined_group_list2($account_id, $group_type, $base_info_filter, $self_info_filter) 1151 | { 1152 | 1153 | #构造新消息 1154 | $filter = new Filter(); 1155 | $filter->GroupBaseInfoFilter = $base_info_filter; 1156 | $filter->SelfInfoFilter = $self_info_filter; 1157 | $msg = array( 1158 | "Member_Account" => $account_id, 1159 | "ResponseFilter" => $filter 1160 | ); 1161 | #将消息序列化为json串 1162 | $req_data = json_encode($msg); 1163 | 1164 | $ret = $this->api("group_open_http_svc", "get_joined_group_list", $this->identifier, $this->usersig, $req_data); 1165 | $ret = json_decode($ret, true); 1166 | return $ret; 1167 | } 1168 | 1169 | function group_get_role_in_group($group_id, $member_id) 1170 | { 1171 | 1172 | #构造新消息 1173 | $mem_list = array(); 1174 | array_push($mem_list, $member_id); 1175 | $msg = array( 1176 | "GroupId" => $group_id, 1177 | "User_Account" => $mem_list, 1178 | ) 1179 | ; 1180 | #将消息序列化为json串 1181 | $req_data = json_encode($msg); 1182 | 1183 | $ret = $this->api("group_open_http_svc", "get_role_in_group", $this->identifier, $this->usersig, $req_data); 1184 | $ret = json_decode($ret, true); 1185 | return $ret; 1186 | } 1187 | 1188 | function group_forbid_send_msg($group_id, $member_id, $second) 1189 | { 1190 | 1191 | #构造新消息 1192 | $mem_list = array(); 1193 | array_push($mem_list, $member_id); 1194 | $msg = array( 1195 | "GroupId" => $group_id, 1196 | "Members_Account" => $mem_list, 1197 | "ShutUpTime" => $second 1198 | ); 1199 | 1200 | #将消息序列化为json串 1201 | $req_data = json_encode($msg); 1202 | 1203 | $ret = $this->api("group_open_http_svc", "forbid_send_msg", $this->identifier, $this->usersig, $req_data); 1204 | $ret = json_decode($ret, true); 1205 | return $ret; 1206 | } 1207 | 1208 | function group_send_group_msg($account_id, $group_id, $text_content) 1209 | { 1210 | 1211 | #构造高级接口所需参数 1212 | $msg_content = array(); 1213 | //创建array 所需元素 1214 | $msg_content_elem = array( 1215 | 'MsgType' => 'TIMTextElem', //文本类型 1216 | 'MsgContent' => array( 1217 | 'Text' => $text_content, //hello 为文本信息 1218 | ) 1219 | ); 1220 | array_push($msg_content, $msg_content_elem); 1221 | $ret = $this->group_send_group_msg2($account_id, $group_id, $msg_content); 1222 | return $ret; 1223 | } 1224 | 1225 | function group_send_group_msg_pic($account_id, $group_id, $pic_path) 1226 | { 1227 | 1228 | #构造高级接口所需参数 1229 | //上传图片并获取url 1230 | $busi_type = 1; //表示群消息 1231 | $ret = $this->openpic_pic_upload($account_id, $group_id, $pic_path, $busi_type); 1232 | $tmp = $ret["URL_INFO"]; 1233 | 1234 | $uuid = $ret["File_UUID"]; 1235 | $pic_url = $tmp[0]["DownUrl"]; 1236 | 1237 | $img_info = array(); 1238 | $img_tmp = $ret["URL_INFO"][0]; 1239 | if($img_tmp["PIC_TYPE"] == 4){ 1240 | $img_tmp["PIC_TYPE"] = 3; 1241 | } 1242 | $img_info_elem1 = array( 1243 | "URL" => $img_tmp["DownUrl"], 1244 | "Height" => $img_tmp["PIC_Height"], 1245 | "Size" => $img_tmp["PIC_Size"], 1246 | "Type" => $img_tmp["PIC_TYPE"], 1247 | "Width" => $img_tmp["PIC_Width"] 1248 | ); 1249 | 1250 | $img_tmp = $ret["URL_INFO"][1]; 1251 | if($img_tmp["PIC_TYPE"] == 4){ 1252 | $img_tmp["PIC_TYPE"] = 3; 1253 | } 1254 | $img_info_elem2 = array( 1255 | "URL" => $img_tmp["DownUrl"], 1256 | "Height" => $img_tmp["PIC_Height"], 1257 | "Size" => $img_tmp["PIC_Size"], 1258 | "Type" => $img_tmp["PIC_TYPE"], 1259 | "Width" => $img_tmp["PIC_Width"] 1260 | ); 1261 | 1262 | $img_tmp = $ret["URL_INFO"][2]; 1263 | if($img_tmp["PIC_TYPE"] == 4){ 1264 | $img_tmp["PIC_TYPE"] = 3; 1265 | } 1266 | $img_info_elem3 = array( 1267 | "URL" => $img_tmp["DownUrl"], 1268 | "Height" => $img_tmp["PIC_Height"], 1269 | "Size" => $img_tmp["PIC_Size"], 1270 | "Type" => $img_tmp["PIC_TYPE"], 1271 | "Width" => $img_tmp["PIC_Width"] 1272 | ); 1273 | 1274 | array_push($img_info, $img_info_elem1); 1275 | array_push($img_info, $img_info_elem2); 1276 | array_push($img_info, $img_info_elem3); 1277 | $msg_content = array(); 1278 | //创建array 所需元素 1279 | $msg_content_elem = array( 1280 | 'MsgType' => 'TIMImageElem', //文本类型 1281 | 'MsgContent' => array( 1282 | 'UUID' => $uuid, 1283 | 'ImageInfoArray' => $img_info, 1284 | ) 1285 | ); 1286 | //将创建的元素$msg_content_elem, 加入array $msg_content 1287 | array_push($msg_content, $msg_content_elem); 1288 | 1289 | $ret = $this->group_send_group_msg2($account_id, $group_id, $msg_content); 1290 | return $ret; 1291 | } 1292 | 1293 | function group_send_group_msg2($account_id, $group_id, $msg_content) 1294 | { 1295 | 1296 | #构造新消息 1297 | $msg = array( 1298 | "GroupId" => $group_id, 1299 | "From_Account" => $account_id, 1300 | "Random" => rand(1, 65535), 1301 | "MsgBody" => $msg_content 1302 | ); 1303 | 1304 | #将消息序列化为json串 1305 | $req_data = json_encode($msg); 1306 | 1307 | $ret = $this->api("group_open_http_svc", "send_group_msg", $this->identifier, $this->usersig, $req_data); 1308 | $ret = json_decode($ret, true); 1309 | return $ret; 1310 | } 1311 | 1312 | function group_send_group_system_notification($group_id, $text_content, $receiver_id) 1313 | { 1314 | 1315 | #构造高级接口所需参数 1316 | $receiver_list = array(); 1317 | if($receiver_id != null){ 1318 | array_push($receiver_list, $receiver_id); 1319 | } 1320 | $ret = $this->group_send_group_system_notification2($group_id, $text_content, $receiver_list); 1321 | return $ret; 1322 | } 1323 | 1324 | function group_send_group_system_notification2($group_id, $content, $receiver_list) 1325 | { 1326 | 1327 | #构造新消息 1328 | $msg = array( 1329 | "GroupId" => $group_id, 1330 | "ToMembers_Account" => $receiver_list, 1331 | "Content" => $content 1332 | ); 1333 | #将消息序列化为json串 1334 | $req_data = json_encode($msg); 1335 | 1336 | $ret = $this->api("group_open_http_svc", "send_group_system_notification", $this->identifier, $this->usersig, $req_data); 1337 | $ret = json_decode($ret, true); 1338 | return $ret; 1339 | } 1340 | 1341 | function comm_rest($server, $command, $req_body) 1342 | { 1343 | 1344 | #将消息序列化为json串 1345 | $req_data = json_encode($req_body); 1346 | 1347 | $ret = $this->api($server, $command, $this->identifier, $this->usersig, $req_data); 1348 | $ret = json_decode($ret, true); 1349 | return $ret; 1350 | } 1351 | 1352 | function group_import_group_member($group_id, $member_id, $role) 1353 | { 1354 | 1355 | #构造高级接口所需参数 1356 | $member_list = array(); 1357 | $member_elem = array( 1358 | "Member_Account" => $member_id, 1359 | "Role" => $role 1360 | ); 1361 | array_push($member_list, $member_elem); 1362 | $ret = $this->group_import_group_member2($group_id, $member_list); 1363 | return $ret; 1364 | } 1365 | 1366 | function group_import_group_member2($group_id, $member_list) 1367 | { 1368 | 1369 | #构造新消息 1370 | $msg = array( 1371 | "GroupId" => $group_id, 1372 | "MemberList" => $member_list, 1373 | ); 1374 | #将消息序列化为json串 1375 | $req_data = json_encode($msg); 1376 | 1377 | $ret = $this->api("group_open_http_svc", "import_group_member", $this->identifier, $this->usersig, $req_data); 1378 | $ret = json_decode($ret, true); 1379 | return $ret; 1380 | } 1381 | 1382 | function group_import_group_msg($group_id, $from_account, $text) 1383 | { 1384 | 1385 | #构造高级接口所需参数 1386 | 1387 | //构造MsgBody 1388 | $msg_content = array( 1389 | "Text" => $text 1390 | ); 1391 | $msg_body_elem = array( 1392 | "MsgType" => "TIMTextElem", 1393 | "MsgContent" => $msg_content, 1394 | ); 1395 | $msg_body_list = array(); 1396 | array_push($msg_body_list, $msg_body_elem); 1397 | 1398 | //构造MsgList的一个元素 1399 | $msg_list_elem = array( 1400 | "From_Account" => $from_account, 1401 | "SendTime" => time(), 1402 | "Random" => rand(1, 65535), 1403 | "MsgBody" => $msg_body_list 1404 | ); 1405 | 1406 | //构造MsgList 1407 | $msg_list = array(); 1408 | array_push($msg_list, $msg_list_elem); 1409 | 1410 | $ret = $this->group_import_group_msg2($group_id, $msg_list); 1411 | return $ret; 1412 | } 1413 | 1414 | function group_import_group_msg2($group_id, $msg_list) 1415 | { 1416 | 1417 | #构造新消息 1418 | $msg = array( 1419 | "GroupId" => $group_id, 1420 | "MsgList" => $msg_list, 1421 | ); 1422 | var_dump($msg); 1423 | #将消息序列化为json串 1424 | $req_data = json_encode($msg); 1425 | 1426 | $ret = $this->api("group_open_http_svc", "import_group_msg", $this->identifier, $this->usersig, $req_data); 1427 | $ret = json_decode($ret, true); 1428 | return $ret; 1429 | } 1430 | function group_set_unread_msg_num($group_id, $member_account, $unread_msg_num) 1431 | { 1432 | 1433 | #构造新消息 1434 | $msg = array( 1435 | "GroupId" => $group_id, 1436 | "Member_Account" => $member_account, 1437 | "UnreadMsgNum" => (int)$unread_msg_num 1438 | ); 1439 | #将消息序列化为json串 1440 | $req_data = json_encode($msg); 1441 | 1442 | $ret = $this->api("group_open_http_svc", "set_unread_msg_num", $this->identifier, $this->usersig, $req_data); 1443 | $ret = json_decode($ret, true); 1444 | return $ret; 1445 | } 1446 | }; 1447 | 1448 | //辅助过滤器类 1449 | class Filter{}; 1450 | 1451 | /** Json数据格式化方法 1452 | * @param array $data 数组数据 1453 | * @param string $indent 缩进字符,默认4个空格 1454 | * @return sting json格式字符串 1455 | */ 1456 | function json_format($data, $indent=null) 1457 | { 1458 | 1459 | // 对数组中每个元素递归进行urlencode操作,保护中文字符 1460 | array_walk_recursive($data, 'json_format_protect'); 1461 | 1462 | // json encode 1463 | $data = json_encode($data); 1464 | 1465 | // 将urlencode的内容进行urldecode 1466 | $data = urldecode($data); 1467 | 1468 | // 缩进处理 1469 | $ret = ''; 1470 | $pos = 0; 1471 | $length = strlen($data); 1472 | $indent = isset($indent)? $indent : ' '; 1473 | $newline = "\n"; 1474 | $prevchar = ''; 1475 | $outofquotes = true; 1476 | for($i=0; $i<=$length; $i++){ 1477 | $char = substr($data, $i, 1); 1478 | if($char=='"' && $prevchar!='\\') 1479 | { 1480 | $outofquotes = !$outofquotes; 1481 | }elseif(($char=='}' || $char==']') && $outofquotes) 1482 | { 1483 | $ret .= $newline; 1484 | $pos --; 1485 | for($j=0; $j<$pos; $j++){ 1486 | $ret .= $indent; 1487 | } 1488 | } 1489 | $ret .= $char; 1490 | if(($char==',' || $char=='{' || $char=='[') && $outofquotes) 1491 | { 1492 | $ret .= $newline; 1493 | if($char=='{' || $char=='['){ 1494 | $pos ++; 1495 | } 1496 | 1497 | for($j=0; $j<$pos; $j++){ 1498 | $ret .= $indent; 1499 | } 1500 | } 1501 | $prevchar = $char; 1502 | } 1503 | return $ret; 1504 | } 1505 | 1506 | /** 1507 | * json_formart辅助函数 1508 | * @param String $val 数组元素 1509 | */ 1510 | function json_format_protect(&$val) 1511 | { 1512 | if($val!==true && $val!==false && $val!==null) 1513 | { 1514 | $val = urlencode($val); 1515 | } 1516 | } 1517 | 1518 | /** 1519 | * 判断操作系统位数 1520 | */ 1521 | function is_64bit() { 1522 | $int = "9223372036854775807"; 1523 | $int = intval($int); 1524 | if ($int == 9223372036854775807) { 1525 | /* 64bit */ 1526 | return true; 1527 | } 1528 | elseif ($int == 2147483647) { 1529 | /* 32bit */ 1530 | return false; 1531 | } 1532 | else { 1533 | /* error */ 1534 | return "error"; 1535 | } 1536 | } 1537 | 1538 | 1539 | -------------------------------------------------------------------------------- /TimRestApiConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkappid":"1400001692", 3 | "identifier":"18602833226", 4 | "private_pem_path":"../private.pem", 5 | "user_sig":"" 6 | } 7 | -------------------------------------------------------------------------------- /TimRestApiGear.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | init($sdkappid, $identifier); 69 | 70 | if($private_pem_path != "") 71 | { 72 | //独立模式 73 | if(!file_exists($private_pem_path)) 74 | { 75 | echo "私钥文件不存在, 请确保TimRestApiConfig.json配置字段private_pem_path正确\n"; 76 | return; 77 | } 78 | 79 | /** 80 | * 获取usersig 81 | * 36000为usersig的保活期 82 | * signature为获取私钥脚本,详情请见 账号登录集成 http://avc.qcloud.com/wiki2.0/im/ 83 | */ 84 | if(is_64bit()){ 85 | if(PATH_SEPARATOR==':'){ 86 | $signature = "signature/linux-signature64"; 87 | }else{ 88 | $signature = "signature\\windows-signature64.exe"; 89 | } 90 | 91 | }else{ 92 | if(PATH_SEPARATOR==':') 93 | { 94 | $signature = "signature/linux-signature32"; 95 | }else{ 96 | $signature = "signature\\windows-signature32.exe"; 97 | } 98 | } 99 | $ret = $api->generate_user_sig($identifier, '36000', $private_pem_path, $signature); 100 | if($ret == null || strstr($ret[0], "failed")){ 101 | echo "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确\n"; 102 | return -1; 103 | } 104 | }else if($user_sig != ""){ 105 | //托管模式 106 | $ret = $api->set_user_sig($user_sig); 107 | if($ret == false){ 108 | echo "设置usrsig失败, 请确保TimRestApiConfig.json配置信息正确\n"; 109 | return -1; 110 | } 111 | }else{ 112 | echo "请填写TimRestApiConfig.json中private_pem_path(独立模式)或者user_sig(托管模式)字段\n"; 113 | return -1; 114 | } 115 | 116 | #构造命令字典 117 | $command_dic = array( 118 | "openim.sendmsg" => 'send_msg', 119 | "openim.sendmsg_pic" => 'send_msg_pic', 120 | "openim.batchsendmsg" => 'batch_sendmsg', 121 | "openim.batchsendmsg_pic" => 'batch_sendmsg_pic', 122 | "im_open_login_svc.account_import" => 'account_import', 123 | "registration_service.register_account" => 'register_account', 124 | "profile.portrait_get" => 'portrait_get', 125 | "profile.portrait_set" => 'portrait_set', 126 | "sns.friend_import" => 'friend_import', 127 | "sns.friend_delete" => 'friend_delete', 128 | "sns.friend_delete_all" => 'friend_delete_all', 129 | "sns.friend_check" => 'friend_check', 130 | "sns.friend_get_all" => 'friend_get_all', 131 | "sns.friend_get_list" => 'friend_get_list', 132 | "group_open_http_svc.get_appid_group_list" => 'get_appid_group_list', 133 | "group_open_http_svc.create_group" => 'create_group', 134 | "group_open_http_svc.change_group_owner" => 'change_group_owner', 135 | "group_open_http_svc.get_group_info" => 'get_group_info', 136 | "group_open_http_svc.get_group_member_info" => 'get_group_member_info', 137 | "group_open_http_svc.modify_group_base_info" => 'modify_group_base_info', 138 | "group_open_http_svc.add_group_member" => 'add_group_member', 139 | "group_open_http_svc.delete_group_member" => 'delete_group_member', 140 | "group_open_http_svc.modify_group_member_info" => 'modify_group_member_info', 141 | "group_open_http_svc.destroy_group" => 'destroy_group', 142 | "group_open_http_svc.get_joined_group_list" => 'get_joined_group_list', 143 | "group_open_http_svc.get_role_in_group" => 'get_role_in_group', 144 | "group_open_http_svc.forbid_send_msg" => 'forbid_send_msg', 145 | "group_open_http_svc.send_group_msg" => 'send_group_msg', 146 | "group_open_http_svc.send_group_msg_pic" => 'send_group_msg_pic', 147 | "group_open_http_svc.send_group_system_notification" => 'send_group_system_notification', 148 | "group_open_http_svc.import_group_member" => 'import_group_member', 149 | "group_open_http_svc.import_group_msg" => 'import_group_msg', 150 | "group_open_http_svc.set_unread_msg_num" => 'set_unread_msg_num' 151 | ); 152 | 153 | #分发命令 154 | $command_key = $server_name . '.' . $command; 155 | $command_value = $command_dic[$command_key]; 156 | $data_list = array(); 157 | for ($i = 3; $i < $argc; $i++){ 158 | array_push($data_list, $argv[$i]); 159 | } 160 | 161 | //访问接口 162 | $ret = $command_value($api, $data_list); 163 | if(gettype($ret) == "string"){ 164 | if(strstr($ret, "not enough")){ 165 | return -1; 166 | } 167 | } 168 | //结果格式化为json,并打印 169 | echo "Response Body:\n"; 170 | echo json_format($ret); 171 | echo "\n"; 172 | $end_time = microtime(true); 173 | echo "Cost Time: ".(round($end_time-$begin_time,3)*1000)."毫秒\n"; 174 | 175 | /** 176 | * 单发信息 177 | **/ 178 | function send_msg($api, $data_list) 179 | { 180 | 181 | if($GLOBALS['argc'] < 6){ 182 | printf("openim.sendmsg 需要三个参数: account_id, receiver, text_content\n"); 183 | return "Fail: not enough paragram for openim.sendmsg"; 184 | } 185 | list($account_id, $receiver, $text_content) = $data_list; 186 | 187 | $ret = $api->openim_send_msg($account_id, $receiver, $text_content); 188 | return $ret; 189 | } 190 | 191 | /** 192 | * 单发图片 193 | **/ 194 | function send_msg_pic($api, $data_list) 195 | { 196 | 197 | if($GLOBALS['argc'] < 6){ 198 | printf("openim.sendmsg_pic 需要三个参数: account_id, receiver, pic_path\n"); 199 | return "Fail: not enough paragram for openim.sendmsg_pic"; 200 | } 201 | list($account_id, $receiver, $pic_path) = $data_list; 202 | 203 | $ret = $api->openim_send_msg_pic($account_id, $receiver, $pic_path); 204 | return $ret; 205 | } 206 | 207 | /** 208 | * 批量发信息 209 | **/ 210 | function batch_sendmsg($api, $data_list) 211 | { 212 | 213 | if($GLOBALS['argc'] < 5){ 214 | printf("openim.batchsendmsg 需要两个参数: account_id, text_content\n"); 215 | return "Fail: not enough paragram for openim.batchsendmsg"; 216 | } 217 | list($account_id_set, $text_content) = $data_list; 218 | $account_list = explode(",", $account_id_set); 219 | $ret = $api->openim_batch_sendmsg($account_list, $text_content); 220 | return $ret; 221 | } 222 | 223 | /** 224 | * 批量发图片 225 | **/ 226 | function batch_sendmsg_pic($api, $data_list) 227 | { 228 | 229 | if($GLOBALS['argc'] < 5){ 230 | printf("openim.batchsendmsg 需要两个参数: account_id, text_content\n"); 231 | return "Fail: not enough paragram for openim.batchsendmsg"; 232 | } 233 | list($account_id_set, $pic_path) = $data_list; 234 | $account_list = explode(",", $account_id_set); 235 | $ret = $api->openim_batch_sendmsg_pic($account_list, $pic_path); 236 | return $ret; 237 | } 238 | 239 | /** 240 | * 独立模式帐号同步 241 | **/ 242 | function account_import($api, $data_list) 243 | { 244 | 245 | if($GLOBALS['argc'] < 6){ 246 | printf("profile.portrait_get 需要三个参数: 帐号id, 用户昵称, 头像url\n"); 247 | return "Fail: not enough paragram for im_open_login_svc.account_import"; 248 | } 249 | list($identifier, $nick, $face_url) = $data_list; 250 | $ret = $api->account_import($identifier, $nick, $face_url); 251 | return $ret; 252 | } 253 | 254 | /** 255 | * 托管模式存量帐号导入 256 | **/ 257 | function register_account($api, $data_list) 258 | { 259 | 260 | if($GLOBALS['argc'] < 6){ 261 | printf("profile.portrait_get 需要三个参数: 帐号id, 帐号类型, 帐号密码\n"); 262 | return "Fail: not enough paragram for registration_service.register_account"; 263 | } 264 | list($identifier, $identifier_type, $password) = $data_list; 265 | $ret = $api->register_account($identifier, $identifier_type, $password); 266 | return $ret; 267 | } 268 | 269 | /** 270 | * 获取用户信息 271 | * account_list 为要拉取的用户id集合 272 | * tag_list 为选项字段,指明要拉取的信息,比如昵称 273 | **/ 274 | function portrait_get($api, $data_list) 275 | { 276 | 277 | if($GLOBALS['argc'] < 4){ 278 | printf("profile.portrait_get 需要一个参数: 帐号id\n"); 279 | return "Fail: not enough paragram for profile.portrait_get"; 280 | } 281 | list($account_id) = $data_list; 282 | $ret = $api->profile_portrait_get($account_id); 283 | return $ret; 284 | } 285 | 286 | /** 287 | * 设置用户信息 288 | **/ 289 | function portrait_set($api, $data_list) 290 | { 291 | 292 | if($GLOBALS['argc'] < 4){ 293 | printf("profile.portrait_set 需要两个参数: 帐号id, 新昵称\n"); 294 | return "Fail: not enough paragram for profile.portrait_set"; 295 | } 296 | list($account_id, $new_name) = $data_list; 297 | $ret = $api->profile_portrait_set($account_id, $new_name); 298 | return $ret; 299 | } 300 | 301 | /** 302 | * 建立好友关系 303 | **/ 304 | function friend_import($api, $data_list) 305 | { 306 | 307 | if($GLOBALS['argc'] < 5){ 308 | printf("sns.friend_import 需要两个参数: 帐号id, 需要添加的好友id\n"); 309 | return "Fail: not enough paragram for sns.friend_import"; 310 | } 311 | list($account_id, $receiver) = $data_list; 312 | $ret = $api->sns_friend_import($account_id, $receiver); 313 | return $ret; 314 | } 315 | 316 | /** 317 | * 解除好友关系 318 | **/ 319 | function friend_delete($api, $data_list) 320 | { 321 | 322 | if($GLOBALS['argc'] < 5){ 323 | printf("sns.friend_delete 需要两个参数: 帐号id, 需要删除的好友id\n"); 324 | return "Fail: not enough paragram for sns.friend_delete"; 325 | } 326 | list($account_id, $frd_id) = $data_list; 327 | $ret = $api->sns_friend_delete($account_id, $frd_id); 328 | return $ret; 329 | } 330 | 331 | /** 332 | * 解除用户所有好友关系 333 | **/ 334 | function friend_delete_all($api, $data_list) 335 | { 336 | 337 | if($GLOBALS['argc'] < 4){ 338 | printf("sns.friend_delete_all 需要一个参数: 帐号id\n"); 339 | return "Fail: not enough paragram for sns.friend_delete_all"; 340 | } 341 | list($account_id) = $data_list; 342 | $ret = $api->sns_friend_delete_all($account_id); 343 | return $ret; 344 | } 345 | 346 | /** 347 | * 校验好友关系 348 | **/ 349 | function friend_check($api, $data_list) 350 | { 351 | 352 | if($GLOBALS['argc'] < 5){ 353 | printf("sns.friend_check 需要两个参数: 帐号id, 校验对象id\n"); 354 | return "Fail: not enough paragram for sns.friend_check"; 355 | } 356 | list($account_id, $to_account) = $data_list; 357 | $ret = $api->sns_friend_check($account_id, $to_account); 358 | return $ret; 359 | } 360 | 361 | /** 362 | * 获取用户全部好友 363 | **/ 364 | function friend_get_all($api, $data_list) 365 | { 366 | 367 | if($GLOBALS['argc'] < 4){ 368 | printf("sns.friend_get_all 需要一个参数: 帐号id\n"); 369 | return "Fail: not enough paragram for sns.friend_get_all"; 370 | } 371 | list($account_id) = $data_list; 372 | $ret = $api->sns_friend_get_all($account_id); 373 | return $ret; 374 | } 375 | 376 | /** 377 | * 获取用户指定好友 378 | **/ 379 | function friend_get_list($api, $data_list) 380 | { 381 | 382 | if($GLOBALS['argc'] < 5){ 383 | printf("sns.friend_get_list 需要两个参数: 帐号id, 需要被拉取的好友id\n"); 384 | return "Fail: not enough paragram for sns.friend_get_list"; 385 | } 386 | list($account_id, $frd_id) = $data_list; 387 | $ret = $api->sns_friend_get_list($account_id, $frd_id); 388 | return $ret; 389 | } 390 | 391 | /** 392 | * 获取app中所有群组(高级接口)a 393 | **/ 394 | function get_appid_group_list($api, $data_list) 395 | { 396 | 397 | $ret = $api->group_get_appid_group_list(); 398 | return $ret; 399 | } 400 | 401 | /** 402 | * 创建群 403 | **/ 404 | function create_group($api, $data_list) 405 | { 406 | 407 | if($GLOBALS['argc'] < 5){ 408 | printf("group_open_http_svc.create_group 至少需要2个参数: 群类型,群名称\n"); 409 | return "Fail: not enough paragram for group_open_http_svc.create_group"; 410 | } 411 | list($group_type, $group_name, $owner_id) = $data_list; 412 | $ret = $api->group_create_group($group_type, $group_name, $owner_id); 413 | return $ret; 414 | } 415 | 416 | /** 417 | * 转让群 418 | **/ 419 | function change_group_owner($api, $data_list) 420 | { 421 | 422 | if($GLOBALS['argc'] < 5){ 423 | printf("group_open_http_svc.create_group 至少需要2个参数: 群id,新群主id\n"); 424 | return "Fail: not enough paragram for group_open_http_svc.change_group_owner?"; 425 | } 426 | list($group_type, $group_name, $owner_id) = $data_list; 427 | $ret = $api->group_change_group_owner($group_type, $group_name, $owner_id); 428 | return $ret; 429 | } 430 | 431 | /** 432 | * 获取群组详细信息 433 | **/ 434 | function get_group_info($api, $data_list) 435 | { 436 | 437 | if($GLOBALS['argc'] < 4){ 438 | printf("group_open_http_svc.get_group_info 需要至少一个参数: 群id\n"); 439 | return "Fail: not enough paragram for group_open_http_svc.get_group_info"; 440 | } 441 | list($group_id) = $data_list; 442 | $ret = $api->group_get_group_info($group_id); 443 | return $ret; 444 | } 445 | 446 | /** 447 | * 获取群组成员详细资料 448 | * limit, offset字段分别表示最大数量和偏移量 449 | **/ 450 | function get_group_member_info($api, $data_list) 451 | { 452 | 453 | if($GLOBALS['argc'] < 4){ 454 | printf("group_open_http_svc.get_group_member_info 需要至少一个参数: 群id\n"); 455 | return "Fail: not enough paragram for group_open_http_svc.get_group_member_info"; 456 | }else{ 457 | list($group_id, $limit, $offset) = $data_list; 458 | $ret = $api->group_get_group_member_info($group_id, $limit, $offset); 459 | } 460 | return $ret; 461 | } 462 | 463 | /** 464 | * 修改群组资料 465 | * 这里只修改群组名字 466 | **/ 467 | function modify_group_base_info($api, $data_list) 468 | { 469 | 470 | if($GLOBALS['argc'] < 4){ 471 | printf("group_open_http_svc.modify_group_base_info 需要至少一个参数: 群id\n"); 472 | return "Fail: not enough paragram for group_open_http_svc.modify_group_base_info"; 473 | } 474 | list($group_id, $group_name) = $data_list; 475 | 476 | $ret = $api->group_modify_group_base_info($group_id, $group_name); 477 | return $ret; 478 | } 479 | 480 | /* 481 | * 增加群组成员 482 | **/ 483 | function add_group_member($api, $data_list) 484 | { 485 | 486 | if($GLOBALS['argc'] < 5){ 487 | printf("group_open_http_svc.add_group_member 需要至少两个参数: 群id, 用户id\n"); 488 | return "Fail: not enough paragram for group_open_http_svc.add_group_member"; 489 | } 490 | list($group_id, $member_id, $silence) = $data_list; 491 | 492 | $ret = $api->group_add_group_member($group_id, $member_id, $silence); 493 | return $ret; 494 | } 495 | 496 | /* 497 | * 删除群组成员 498 | * mem_list为增加用户列表,这里只有一个用户 499 | **/ 500 | function delete_group_member($api, $data_list) 501 | { 502 | 503 | if($GLOBALS['argc'] < 5){ 504 | printf("group_open_http_svc.delete_group_member 需要至少两个参数: 群id, 用户id\n"); 505 | return "Fail: not enough paragram for group_open_http_svc.delete_group_member"; 506 | }else{ 507 | list($group_id, $member_id, $silence) = $data_list; 508 | $ret = $api->group_delete_group_member($group_id, $member_id, $silence); 509 | } 510 | return $ret; 511 | } 512 | 513 | /* 514 | * 修改群组成员身份 515 | **/ 516 | function modify_group_member_info($api, $data_list) 517 | { 518 | 519 | if($GLOBALS['argc'] < 6){ 520 | printf("group_open_http_svc.modify_group_member_info 需要至少两个参数: 群id, 用户id, 身份标识\n"); 521 | return "Fail: not enough paragram for group_open_http_svc.modify_group_member_info"; 522 | }else{ 523 | list($group_id, $account_id, $role) = $data_list; 524 | $ret = $api->group_modify_group_member_info($group_id, $account_id, $role); 525 | } 526 | return $ret; 527 | } 528 | 529 | /* 530 | * 解散群组 531 | **/ 532 | function destroy_group($api, $data_list) 533 | { 534 | 535 | if($GLOBALS['argc'] < 4){ 536 | printf("group_open_http_svc.destroy_group 需要至少一个参数: 群id\n"); 537 | return "Fail: not enough paragram for group_open_http_svc.destroy_group"; 538 | }else{ 539 | list($group_id) = $data_list; 540 | $ret = $api->group_destroy_group($group_id); 541 | } 542 | return $ret; 543 | } 544 | 545 | /* 546 | * 获取某用户加入的群组 547 | **/ 548 | function get_joined_group_list($api, $data_list) 549 | { 550 | 551 | if($GLOBALS['argc'] < 4){ 552 | printf("group_open_http_svc.get_joined_group_list 需要至少一个参数: 用户id\n"); 553 | return "Fail: not enough paragram for group_open_http_svc.get_joined_group_list"; 554 | } 555 | list($account_id) = $data_list; 556 | $ret = $api->group_get_joined_group_list($account_id); 557 | return $ret; 558 | } 559 | 560 | /* 561 | * 查询用户在某个群中身份 562 | **/ 563 | function get_role_in_group($api, $data_list) 564 | { 565 | 566 | if($GLOBALS['argc'] < 5){ 567 | printf("group_open_http_svc.get_role_in_group 需要至少两个参数: 群id, 用户id\n"); 568 | return "Fail: not enough paragram for group_open_http_svc.get_role_in_group"; 569 | }else{ 570 | list($group_id, $member_id) = $data_list; 571 | $ret = $api->group_get_role_in_group($group_id, $member_id); 572 | } 573 | return $ret; 574 | } 575 | 576 | /* 577 | * 批量禁言/取消禁言 578 | **/ 579 | function forbid_send_msg($api, $data_list) 580 | { 581 | 582 | if($GLOBALS['argc'] < 6){ 583 | printf("group_open_http_svc.forbid_send_msg 需要至少两个参数: 群id, 用户id, 禁言时间(秒)\n"); 584 | return "Fail: not enough paragram for group_open_http_svc.forbid_send_msg"; 585 | } 586 | list($group_id, $member_id, $second) = $data_list; 587 | $ret = $api->group_forbid_send_msg($group_id, $member_id, $second); 588 | return $ret; 589 | } 590 | 591 | /** 592 | * 在某一群组里发普通消息 593 | **/ 594 | function send_group_msg($api, $data_list) 595 | { 596 | 597 | if($GLOBALS['argc'] < 5){ 598 | printf("group_open_http_svc.open_send_group_msg 需要至少两个参数: 群组id, 文本内容\n"); 599 | return "Fail: not enough paragram for group_open_http_svc.open_send_group_msg"; 600 | } 601 | list($account_id, $group_id, $text_content) = $data_list; 602 | $ret = $api->group_send_group_msg($account_id, $group_id, $text_content); 603 | return $ret; 604 | } 605 | 606 | /** 607 | * 在某一群组里发送图片 608 | **/ 609 | function send_group_msg_pic($api, $data_list) 610 | { 611 | 612 | if($GLOBALS['argc'] < 6){ 613 | printf("group_open_http_svc.open_send_group_msg_pic 需要至少三个参数: 发送者id, 群组id, 图片本地路径\n"); 614 | return "Fail: not enough paragram for group_open_http_svc.open_send_group_msg_pic"; 615 | } 616 | list($account_id, $group_id, $pic_path) = $data_list; 617 | $ret = $api->group_send_group_msg_pic($account_id, $group_id, $pic_path); 618 | return $ret; 619 | } 620 | 621 | /** 622 | * 在某一群组里发系统消息 623 | **/ 624 | function send_group_system_notification($api, $data_list) 625 | { 626 | 627 | if($GLOBALS['argc'] < 5){ 628 | printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 文本内容\n"); 629 | return "Fail: not enough paragram for group_open_http_svc.send_group_system_notification"; 630 | } 631 | list($group_id, $text_content, $receiver_id) = $data_list; 632 | //默认为空,发送全员 633 | $ret = $api->group_send_group_system_notification($group_id, $text_content, $receiver_id); 634 | return $ret; 635 | } 636 | 637 | /** 638 | * 导入群成员 639 | **/ 640 | function import_group_member($api, $data_list) 641 | { 642 | 643 | if($GLOBALS['argc'] < 5){ 644 | printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 成员id\n"); 645 | return "Fail: not enough paragram for group_open_http_svc.import_group_member"; 646 | } 647 | if($GLOBALS['argc'] == 5) 648 | { 649 | list($group_id, $member_id) = $data_list; 650 | }else 651 | { 652 | list($group_id, $member_id, $role) = $data_list; 653 | } 654 | $role = null; 655 | $ret = $api->group_import_group_member($group_id, $member_id, $role); 656 | return $ret; 657 | } 658 | 659 | /** 660 | * 导入群消息 661 | **/ 662 | function import_group_msg($api, $data_list) 663 | { 664 | 665 | if($GLOBALS['argc'] < 6){ 666 | printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 消息发送者, 文本内容\n"); 667 | return "Fail: not enough paragram for group_open_http_svc.import_group_msg"; 668 | } 669 | list($group_id, $from_account, $text) = $data_list; 670 | 671 | $ret = $api->group_import_group_msg($group_id, $from_account, $text); 672 | return $ret; 673 | } 674 | 675 | /** 676 | * 导入群消息 677 | **/ 678 | function set_unread_msg_num($api, $data_list) 679 | { 680 | 681 | if($GLOBALS['argc'] < 6){ 682 | printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 成员id, 群内身份\n"); 683 | return "Fail: not enough paragram for group_open_http_svc.set_unread_msg_num"; 684 | } 685 | list($group_id, $member_account, $unread_msg_num) = $data_list; 686 | //默认为空,发送全员 687 | $ret = $api->group_set_unread_msg_num($group_id, $member_account, $unread_msg_num); 688 | return $ret; 689 | } 690 | ?> 691 | -------------------------------------------------------------------------------- /TimRestInterface.php: -------------------------------------------------------------------------------- 1 | 'TIMTextElem', //文本类型 69 | * 'MsgContent' => array( 70 | * 'Text' => "hello", //hello 为文本信息 71 | * ) 72 | * ); 73 | * //将创建的元素$msg_content_elem, 加入array $msg_content 74 | * array_push($msg_content, $msg_content_elem); 75 | * 76 | * @return array 通过解析REST接口json返回包得到的关联数组, 其中包含成功与否、及错误提示(如果有错误)等字段 77 | */ 78 | abstract function openim_send_msg2($account_id, $receiver, $msg_content); 79 | 80 | /** 81 | * 批量发文本消息 82 | * @param array $account_list 接收消息的用户id集合 83 | * @param string $text_content 消息内容(这里为文本消息) 84 | * @return array 通过解析REST接口json返回包得到的关联数组, 其中包含成功与否、及错误提示(如果有错误)等字段 85 | */ 86 | abstract function openim_batch_sendmsg($account_list, $text_content); 87 | 88 | /** 89 | * 批量发图片 90 | * @param array $account_list 接收消息的用户id集合 91 | * @param string $pic_path 要发送图片的本地路径 92 | * @return array 通过解析REST接口json返回包得到的关联数组, 其中包含成功与否、及错误提示(如果有错误)等字段 93 | */ 94 | abstract function openim_batch_sendmsg_pic($account_list, $pic_path); 95 | 96 | /** 97 | * 批量发消息(高级接口) 98 | * @param array $account_list 接收消息的用户id集合 99 | * @param array $msg_content 消息内容, php构造示例: 100 | * 101 | * $msg_content = array(); 102 | * //创建array 所需元素 103 | * $msg_content_elem = array( 104 | * 'MsgType' => 'TIMTextElem', //文本??型 105 | * 'MsgContent' => array( 106 | * 'Text' => "hello", //hello 为文本信息 107 | * ) 108 | * ); 109 | * //将创建的元素$msg_content_elem, 加入array $msg_content 110 | * array_push($msg_content, $msg_content_elem); 111 | * 112 | * @return array 通过解析REST接口json返回包得到的关联数组, 其中包含成功与否、及错误提示(如果有错误)等字段 113 | */ 114 | abstract function openim_batch_sendmsg2($account_list, $msg_content); 115 | 116 | ################################ 帐号管理 ################################### 117 | 118 | /** 119 | * 独立模式帐号同步接口 120 | * @param string $identifier 用户名 121 | * @param string $nick 用户昵称 122 | * @param string $face_url 用户头像URL 123 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 124 | */ 125 | abstract function account_import($identifier, $nick, $face_url); 126 | 127 | /** 128 | * 独立模式帐号同步接口 129 | * @param string $Identifier 为用户申请同步的帐号,长度为4-24个字符 130 | * @param string $IdentifierType Identifier的类型,1:手机号(国家码-手机号) 2:邮箱 3:字符串帐号 131 | * @param string $Password Identifier的密码,长度为8-16个字符 132 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 133 | */ 134 | abstract public function register_account($identifier, $identifierType, $password); 135 | 136 | ################################ 资料管理 ################################### 137 | 138 | /** 139 | * 获取用户资料 140 | * @param string $account_id 获取哪个用户的资料 141 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、拉取到的用户信息(如果成功),及错误提示等字段 142 | */ 143 | abstract function profile_portrait_get($account_id); 144 | 145 | /** 146 | * 获取用户资料(高级接口) 147 | * @param array $account_list 需要获取资料的帐号id集合, php构造示例: 148 | * 149 | * $account_list = array(); 150 | * array_push($account_list, $account_id); //$account_id为用户id,需要用户传递 151 | * 152 | * @param array $tag_list 需要拉取的字段,目前可拉取的字段: 153 | * 1.昵称:"Tag_Profile_IM_Nick 154 | * 2.加好友设置"Tag_Profile_IM_AllowType", php构造示例: 155 | * 156 | * $tag_list = array( 157 | * "Tag_Profile_IM_Nick", //昵称 158 | * ); 159 | * 160 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、拉取到的用户信息(如果成功),及错误提示等字段 161 | */ 162 | abstract function profile_portrait_get2($account_list, $tag_list); 163 | 164 | /** 165 | * 设置用户名称 166 | * @param string $account_id 需要设置的用户 167 | * @param string $new_name 要设置为的用户名 168 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 169 | */ 170 | abstract function profile_portrait_set($account_id, $new_name); 171 | 172 | /** 173 | * 设置用户资料(高级接口) 174 | * @param string $account_id 需要设置的用户 175 | * @param array $profile_list 设置选项集合,用户账号设置内容选项, 比如昵称, php构造示例: 176 | * 177 | * //创建array $profile_list 178 | * $profile_list = array(); 179 | * //创建昵称选项 180 | * $profile_nick = array( 181 | * "Tag" => "Tag_Profile_IM_Nick", //用户昵称 182 | * "Value" => "new_name" //"new_name"要设置成的用户名 183 | * ); 184 | * //加好友验证方式 185 | * $profile_allow = array( 186 | * "Tag" => "Tag_Profile_IM_AllowType", 187 | * "Value" => "AllowType_Type_NeedConfirm" 188 | * ); 189 | * array_push($profile_list, $profile_nick); 190 | * array_push($profile_list, $profile_allow); 191 | * 192 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 193 | */ 194 | 195 | abstract function profile_portrait_set2($account_id, $profile_list); 196 | 197 | 198 | ################################ 关系链管理 ################################### 199 | ## 关系链托管方式请详见:关系链系统概述 (http://avc.qcloud.com/wiki2.0/im/) 即时通信云-概述-关系链系统 ## 200 | /** 201 | * 建立双方好友关系 202 | * @param string $account_id 发起者id 203 | * @param string $receiver 添加的用户,完成之后两者互为好友 204 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 205 | */ 206 | abstract function sns_friend_import($accout_id, $receiver); 207 | 208 | /** 209 | * 解除双方好友关系 210 | * @param string $account_id 用户id,即需要删除好友的用户 211 | * @param string $frd_id 需要删除的好友 212 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 213 | */ 214 | abstract function sns_friend_delete($account_id, $frd_id); 215 | 216 | /** 217 | * 解除所有好友关系 218 | * @param string $account_id 用户id,即需要解除所有好友关系的用户 219 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 220 | */ 221 | abstract function sns_friend_delete_all($account_id); 222 | 223 | /** 224 | * 校验好友关系(默认双向严重) 225 | * @param string $account_id 需要校验好友的用户id 226 | * @param string $to_account 校验是否为好友的id 227 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示、验证结果等字段 228 | */ 229 | abstract function sns_friend_check($account_id, $to_account); 230 | 231 | /** 232 | * 校验好友关系 233 | * @param string $account_id 需要校验好友的用户id 234 | * @param array $to_account_list 校验是否为好友的id集合 235 | * @param string $check_type 校验类型,目前支持:单向校验"CheckResult_Type_Singal",双向校验"CheckResult_Type_Both" 236 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示、验证结果等字段 237 | */ 238 | abstract function sns_friend_check2($account_id, $to_account_list, $check_type); 239 | 240 | /** 241 | * 拉取好友 242 | * @param string $account_id 需要获取好友的用户id 243 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的好友信息、成功与否及错误提示等字段 244 | */ 245 | abstract function sns_friend_get_all($account_id); 246 | 247 | /** 248 | * 拉取好友(高级接口) 249 | * @param string $account_id 需要获取好友的用户id 250 | * @param array $tag_list 需要拉取的字段,该拉取协议是一条整合数据的协议,可以指定拉取自己好友的昵称 251 | * 加好友设置以及对用户的备注等字段,如果需要拉取昵称字段,则这里就需要在Json数组中填入Tag_Profile_IM_Nick. 252 | * php构造示例: 253 | * 254 | * $tag_list = array( 255 | * "Tag_Profile_IM_Nick", //昵称选项 256 | * "Tag_SNS_IM_Remark" //备注选项 257 | * ); 258 | * 259 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的好友信息、成功与否及错误提示等字段 260 | */ 261 | abstract function sns_friend_get_all2($account_id, $tag_list); 262 | 263 | /** 264 | * 拉取指定好友的信息 265 | * @param string $account_id 需要拉取好友的帐号 266 | * @param string $frd_id 需要被拉取的好友 267 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的好友信息、成功与否及错误提示等字段 268 | */ 269 | abstract function sns_friend_get_list($account_id, $frd_id); 270 | 271 | /** 272 | * 拉取特定好友(高级接口) 273 | * @param string $account_id 需要拉取好友的帐号 274 | * @param array $frd_list 拉取好友对象, php构造示例: 275 | * 276 | * $frd_list = array(); 277 | * array_push($frd_list, "leckie"); //"leckie" 为需要被拉取的好友id 278 | * 279 | * @param array $tag_list 需要拉取属性的选项字段, 该拉取协议是一条整合数据的协议,可以指定拉取自己好友的昵称 280 | * 、加好友设置以及对用户的备注等字段,如果需要拉取昵称字段,则这里就需要在Json数组中填入Tag_Profile_IM_Nick 281 | * 282 | * $tag_list = array( 283 | * "Tag_Profile_IM_Nick", //昵称选项 284 | * "Tag_SNS_IM_Remark" //备注选项 285 | * ); 286 | * 287 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的好友信息、成功与否及错误提示等字段 288 | */ 289 | abstract function sns_friend_get_list2($account_id, $frd_list, $tag_list); 290 | 291 | ################################ 群组管理 ################################### 292 | 293 | /** 294 | * 获取app中所有群组, 如果APP中的总群数量超过10000个,最多只会返回10000个(如果需要获取完整必须使用高级接口) 295 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的群组信息、成功与否及错误提示等字段 296 | */ 297 | abstract function group_get_appid_group_list(); 298 | 299 | /** 300 | * 获取app中所有群组(高级接口) 301 | * @param int $limit 最多获取多少个群,不得超过10000, 如果不填,获取能获取的最大数量的群. 302 | * @param int $offset 控制从整个群组列表中的第多少个开始读取(从0开始). 对于分页请求(页码数字从1开始),每 303 | * 一页的Offset值应当为:(页码数-1)×每页展示的群组数量, 如果不填从0开始. 304 | * @param string $group_type 如果仅需要返回特定群组形态的群组,可以通过GroupType进行过滤,但此时返回的TotalCount 305 | * 的含义就变成了APP中该群组形态的群组总数. 例如:假设APP旗下总共50000个群组,其中有20000个为公开群组,如 306 | * 果将请求包体中的GroupType设置为Public,那么不论limit和offset怎样设置,应答包体中的TotalCount都为20000, 307 | * 且GroupIdList中的群组全部为公开群组. 308 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的群组信息、成功与否及错误提示等字段 309 | */ 310 | abstract function group_get_appid_group_list2($limit, $offset, $group_type); 311 | 312 | /** 313 | * 创建群 314 | * @param string $group_type 群类型, 包括Public(公开群), Private(私密群), ChatRoom(聊天室) 315 | * @param string $group_name 群名称 316 | * @param string $owner_id 群主id, 自动添加到群成员中.如果不填,则群没有群主 317 | * @return array 通过解析REST接口json返回包得到的关联数组,包含新建的群号、成功与否、错误提示等字段 318 | */ 319 | abstract function group_create_group($group_type, $group_name, $owner_id); 320 | 321 | /** 322 | * 创建群(高级接口) 323 | * @param string $group_type 群类型(包括Public(公开群), Private(私密群), ChatRoom(聊天室)) 324 | * @param string $group_name 群名称 325 | * @param string $owner_id 群主id, 自动添加到群成员中.如果不填,群没有群主 326 | * @param array $info_set 存储群组基本信息的字典,内容包括用introduction 群简介, group_id 自定义群组显示出来的id, 327 | * notification 群公告, face_url 群头像url地址, max_member_num 最大群成员数量, apply_join 申请加群处理方式 328 | * (比如FreeAccess 自由加入). php构造示例: 329 | * 330 | * $info_set = array( 331 | * 'introduction' => "群简介"(string), 332 | * 'group_id' => "自定义群组id"(string), 333 | * 'notificatoin' => "群公告"(string), 334 | * 'face_url' => "群头像url地址"(string), 335 | * 'max_member_num' => 最大群成员数量(int), 336 | * 'apply_join' => "申请加群的处理方式"(string) 337 | * ); 338 | * 339 | * @param array $mem_list 初始群成员列表,最多500个,每个群成员由Member_Account(用户id), Role(角色, 比如管理员Admin, 340 | * 普通成员Member)组成. php构造示例: 341 | * 342 | * $mem_list = array(); 343 | * $mem_account = array()( 344 | * "Member_Account" => "bob", // 成员id 345 | * "Role" => "Admin" // 赋予该成员的身份,目前备选项只有Admin 346 | * ); 347 | * array_push($account_list, $mem_account); //$mem_account为用户id,需要用户传递 348 | * 349 | * @return array 通过解析REST接口json返回包得到的关联数组,包含新建的群号、成功与否、错误提示等字段 350 | */ 351 | abstract function group_create_group2($group_type, $group_name, $owner_id, $info_set, $mem_list); 352 | 353 | /** 354 | * 转让群组 355 | * @param string $group_id 需要转让的群组id 356 | * @param string $new_owner 需要设置的新群主id 357 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 358 | */ 359 | abstract function group_change_group_owner($group_id, $new_owner); 360 | 361 | /** 362 | * 获取群组详细信息 363 | * @param string $group_id 需要获取信息的群组id 364 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的群组信息(如果成功)、成功与否、错误提示等字段 365 | */ 366 | abstract function group_get_group_info($group_id); 367 | 368 | /** 369 | * 获取群组详细信息(高级接口) 370 | * @param array $group_list 群组集合. php构造示例: 371 | * 372 | * $group_list = array(); 373 | * array_push($group_list, "group_id"); //group_id 为群组号码 374 | * 375 | * @param array $base_info_filter 基础信息字段过滤器. php构造示例: 376 | * 377 | * $base_info_filter = array( 378 | * "Type", //群类型(包括Public(公开群), Private(私密群), ChatRoom(聊天室)) 379 | * "Name", //群名称 380 | * "Introduction", //群简介 381 | * "Notification", //群公告 382 | * "FaceUrl", //群头像url地址 383 | * "CreateTime", //群组创建时间 384 | * "Owner_Account", //群主id 385 | * "LastInfoTime", //最后一次系统通知时间 386 | * "LastMsgTime", //最后一次消息发送时间 387 | * "MemberNum", //群组当前成员数目 388 | * "MaxMemberNum", //群组内最大成员数目 389 | * "ApplyJoinOption" //申请加群处理方式(比如FreeAccess 自由加入) 390 | * ); 391 | * 392 | * @param array $member_info_filter 成员信息字段过滤器, php构造示例: 393 | * 394 | * $member_info_filter = array( 395 | * "Account", // 成员ID 396 | * "Role", // 成员身份 397 | * 398 | * "JoinTime", // 成员加入时间 399 | * "LastSendMsgTime", // 该成员最后一次发送消息时间 400 | * "ShutUpUntil" // 该成员被禁言直到某时间 401 | * ); 402 | * 403 | * @param array $app_define_filter 群组维度的自定义字段过滤器, php构造示例: 404 | * 405 | * $app_define_filter = array( 406 | * "GroupTestData1", //自定义数据 407 | * ); 408 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的群组信息(如果成功)、成功与否、错误提示等字段 409 | */ 410 | abstract function group_get_group_info2($group_list, $base_info_filter, $member_info_filter, $app_define_filter); 411 | 412 | /** 413 | * 获取群组成员详细信息 414 | * @param string $group_id 群组id 415 | * @param int $limit 最多获取多少个成员, 如果不填, 获取全部成员 416 | * @param int $offset 从第几个成员开始获取, 如果不填, 从第一个成员开始获取 417 | * @return array 通过解析REST接口json返回包得到的关联数组,包含拉取到的群组成员详细信息(如果成功)、成功与否、错误提示等字段 418 | */ 419 | abstract function group_get_group_member_info($group_id, $limit, $offset); 420 | 421 | /** 422 | * 修改群组名字 423 | * @param string $group_id 群组id 424 | * @param string $group_name 将其作为群组名字 425 | * @return string 返回成功与否,及错误提示(如果有错误) 426 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 427 | */ 428 | abstract function group_modify_group_base_info($group_id, $group_name); 429 | 430 | /** 431 | * 修改群组信息(高级接口) 432 | * @param string $group_id 群组id 433 | * @param string $group_name 群组名字 434 | * @param array $info_set 需要修改的群组基本信息的字典集合, 包括群简介,群公告, 群头像url地址,群成员最大数量, 435 | * 申请加群方式. php构造示例: 436 | * 437 | * $info_set = array( 438 | * 'introduction' => "群简介"(string), 439 | * 'notification' => "群公告"(string), 440 | * 'face_url' => "群头像url地址(string)", 441 | * 'max_member_num' => "群成员最大数量"(string), 442 | * 'apply_join' => "申请加入方式"(string) 443 | * ); 444 | * 445 | * @param array $app_define_list 自定义字段. php构造示例: 446 | * 447 | * $app_define_list = array(); 448 | * //定义自定义字段字典数组 449 | * $app_define_one = array()( 450 | * "Key": "GroupTestData1", // 需要修改的自定义字段key 451 | * "Value": "NewData" // 自定义字段的新值 452 | * ); 453 | * array_push($app_define_list, $app_define_one); 454 | * 455 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 456 | */ 457 | abstract function group_modify_group_base_info2($group_id, $group_name, $info_set, $app_define_list); 458 | 459 | /** 460 | * 增加群组成员 461 | * @param string $group_id 要操作的群组id 462 | * @param string $member_id 要加入的用户id 463 | * @param int $silence 是否静默加入, 0为否, 1为是 464 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 465 | */ 466 | abstract function group_add_group_member($group_id, $member_id, $silence); 467 | 468 | 469 | /** 470 | * 删除群组成员 471 | * @param string $group_id 要操作的群组id 472 | * @param string $member_id 要删除的成员id 473 | * @param int silence 是否静默删除, 0为否,1为是 474 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 475 | */ 476 | abstract function group_delete_group_member($group_id, $member_id, $silence); 477 | 478 | 479 | /** 480 | * 修改群成员身份 481 | * @param string $group_id 要操作的群组id 482 | * @param string $account_id 要操作的用户id 483 | * @param string $role 用户身份(Admin/Member) 484 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 485 | */ 486 | abstract function group_modify_group_member_info($group_id, $account_id, $role); 487 | 488 | /** 489 | * 修改群成员资料(高级接口) 490 | * @param string $group_id 要操作的群组id 491 | * @param string $account_id 用户id 492 | * @param string $role Admin或者Member, 分别为设置/取消管理员, 为null则不改变成员身份 493 | * @param string $msg_flag 消息屏蔽类型,比如AcceptAndNotify(接收并提示), 为null则不改变屏蔽类型 494 | * @param int $shutup_time 禁言时间 495 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 496 | */ 497 | abstract function group_modify_group_member_info2($group_id, $account_id, $role, $msg_flag, $shutup_time); 498 | 499 | /** 500 | * 解散群 501 | * @param string $group_id 群组id 502 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 503 | */ 504 | abstract function group_destroy_group($group_id); 505 | 506 | /** 507 | * 获取某一用户加入的群组 508 | * @param string $account_id 用户id 509 | * @return array 通过解析REST接口json返回包得到的关联数组,包含该用户加入的群的信息(如果成功), 成功与否、错误提示等字段 510 | */ 511 | abstract function group_get_joined_group_list($account_id); 512 | 513 | /** 514 | * 获取某一用户加入的群组(高级接口) 515 | * @param string $account_id 用户id 516 | * @param string $group_type 拉取哪种群组形态(Pulic(公开群)/Private(私密群)/ChatRoom(聊天室)),不填为拉取所有 517 | * @param array $base_info_filter 基础信息字段过滤器. php构造示例: 518 | * 519 | * $base_info_filter = array( 520 | * "Type", //群类型(包括Public(公开群), Private(私密群), ChatRoom(聊天室)) 521 | * "Name", //群名称 522 | * "Introduction", //群简介 523 | * "Notification", //群公告 524 | * "FaceUrl", //群头像url地址 525 | * "CreateTime", //群组创建时间 526 | * "Owner_Account", //群主id 527 | * "LastInfoTime", //最后一次系统通知时间 528 | * "LastMsgTime", //最后一次消息发送时间 529 | * "MemberNum", //群组当前成员数目 530 | * "MaxMemberNum", //群组内最大成员数目 531 | * "ApplyJoinOption" //申请加群处理方式(比如FreeAccess 自由加入, NeedPermission 需要同意) 532 | * ); 533 | * 534 | * @param array $self_info_filter 自身在群内的消息过滤器. php构造示例: 535 | * 536 | * $self_info_filter = array( 537 | * "Role", //群内身份(Amin/Member) 538 | * "JoinTime", //入群时间 539 | * "MsgFlag", //消息屏蔽类型 540 | * "UnreadMsgNum" //未读消息数量 541 | * ); 542 | * @return array 通过解析REST接口json返回包得到的关联数组,包含该用户加入的群的信息(如果成功), 成功与否、错误提示等字段 543 | */ 544 | abstract function group_get_joined_group_list2($account_id, $group_type, $base_info_filter, $self_info_filter); 545 | 546 | /** 547 | * 查询用户在某个群组中的身份 548 | * @param string $group_id 群组id 549 | * @param string $member_id 要查询的用户 550 | * @return array 通过解析REST接口json返回包得到的关联数组,包含该用户在某个群的身份(如果成功), 成功与否、错误提示等字段 551 | */ 552 | abstract function group_get_role_in_group($group_id, $member_id); 553 | 554 | /** 555 | * 批量禁言/取消禁言 556 | * @param string $group_id 群组id 557 | * @param string $member_id 要禁言/取消禁言 的用户 558 | * @param int $second 表示禁言多少秒, 0表示取消禁言 559 | * @return array 通过解析REST接口json返回包得到的关联数组,包含该用户在某个群的身份(如果成功), 成功与否、错误提示等字段 560 | */ 561 | abstract function group_forbid_send_msg($group_id, $member_id, $second); 562 | 563 | /** 564 | * 在某一群组里发普通消息 565 | * @param string $account_id 发送消息的用户 566 | * @param string $group_id 群组id 567 | * @param string $text_content 要发送的信息(均为文本消息) 568 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 569 | */ 570 | abstract function group_send_group_msg($account_id, $group_id, $text_content); 571 | 572 | /** 573 | * 在某一群组里发送图片 574 | * @param string $account_id 发送消息的用户 575 | * @param string $group_id 群组id 576 | * @param string $pic_path 要发送图片的本地路径 577 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 578 | */ 579 | abstract function group_send_group_msg_pic($account_id, $group_id, $pic_path); 580 | 581 | /** 582 | * 在某一群组里发普通消息(高级接口) 583 | * @param string $account_id 发送消息的用户 584 | * @param string $group_id 群组id 585 | * @param array $msg_content 要发送的消息集合,这里包括文本消息和表情消息. php构造示例: 586 | * 587 | * //创建array $msg_content 588 | * $msg_content = array(); 589 | * //创建array 所需元素 590 | * $msg_content_text = array( 591 | * 'MsgType' => 'TIMTextElem', //文本类型 592 | * 'MsgContent' => array( 593 | * 'Text' => "hello", //"hello" 为文本信息 594 | * ) 595 | * 596 | * $msg_content_face = array( 597 | * 'MsgType' => 'TIMTextElem', //表情类型 598 | * 'MsgContent' => array( 599 | * 'Data' => "abc\u0000\u0001", //"abc\u0000\u0001" 为图片信息 600 | * ) 601 | * 602 | * array_push($msg_content, $msg_content_text); 603 | * array_push($msg_content, $msg_content_face); 604 | * ); 605 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 606 | */ 607 | abstract function group_send_group_msg2($account_id, $group_id, $msg_content); 608 | 609 | /** 610 | * 在某一群组发系统消息 611 | * @param string $group_id 群组id 612 | * @param string $content 系统通知内容,支持二进制数组 613 | * @param string $receiver_id 接收者群成员id,为空表示全员下发 614 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 615 | */ 616 | abstract function group_send_group_system_notification($group_id, $content, $receiver_id); 617 | 618 | /** 619 | * 在某一群组发系统消息(高级接口) 620 | * @param string $group_id 群组id 621 | * @param string $content 系统通知内容,支持二进制数组 622 | * @param array $receiver_list 接收此系统提示的用户id集合, 为空表示发送给全员. php构造示例: 623 | * 624 | * $receiver_list = array( 625 | * "peter", 626 | * "leckie" 627 | * ) 628 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 629 | */ 630 | abstract function group_send_group_system_notification2($group_id, $content, $receiver_list); 631 | 632 | /** 633 | * 导入群成员(只导入一个成员, 入群时间默认为当前) 634 | * @param string $group_id 要操作的群组id 635 | * @param string $member_id 要导入的用户id 636 | * @param string $role 要导入的用户的身份(现可填值只有Admin),不填默认为Member 637 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 638 | */ 639 | abstract function group_import_group_member($group_id, $member_id, $role); 640 | 641 | /** 642 | * 导入群成员(批量导入) 643 | * @param string $group_id 要操作的群组id 644 | * @param string $member_list 要导入的用户id集合,构造示例: 645 | * 646 | * $member_list = array(); 647 | * $member_elem = array( 648 | * "Member_Account" => $member_id, 649 | * "Role" => $role 650 | * ); 651 | * array_push($member_list, $member_elem); 652 | * 653 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 654 | */ 655 | abstract function group_import_group_member2($group_id, $member_list); 656 | 657 | /** 658 | * 导入一条群文本消息 659 | * @param string $group_id 要操作的群组id 660 | * @param string $from_account 该消息发送者 661 | * @param int $text 文本消息内容 662 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 663 | */ 664 | abstract function group_import_group_msg($group_id, $from_account, $text); 665 | 666 | /** 667 | * 导入群消息(高级接口, 一次最多导入20条) 668 | * @param string $group_id 要操作的群组id 669 | * @param string $msg_list 消息集合, 构造方式如下: 670 | * 671 | * //构造MsgBody 672 | * $msg_content = array( 673 | * "Text" => $text 674 | * ); 675 | * $msg_body_elem = array( 676 | * "MsgType" => "TIMTextElem", 677 | * "MsgContent" => $msg_content, 678 | * ); 679 | * $msg_body_list = array(); 680 | * array_push($msg_body_list, $msg_body_elem); 681 | * //构造MsgList的一个元素 682 | * $msg_list_elem = array( 683 | * "From_Account" => $from_account, 684 | * "SendTime" => time(), 685 | * "Random" => rand(1, 65535), 686 | * "MsgBody" => $msg_body_list 687 | * ); 688 | * //构造MsgList 689 | * $msg_list = array(); 690 | * array_push($msg_list, $msg_list_elem); 691 | * 692 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 693 | */ 694 | abstract function group_import_group_msg2($group_id, $msg_list); 695 | 696 | /** 697 | * 设置群组成员未读计数 698 | * @param string $group_id 要操作的群组id 699 | * @param string $member_account 要操作的群成员 700 | * @param int $unread_msg_num 该成员的未读计数 701 | * @return array 通过解析REST接口json返回包得到的关联数组,包含成功与否、错误提示等字段 702 | */ 703 | abstract function group_set_unread_msg_num($group_id, $member_account, $unread_msg_num); 704 | 705 | 706 | ################################ 通用接口 ################################### 707 | /** 708 | * 直接访问RestApi 709 | * 建议仅在没有合适接口时才考虑使用 710 | * @param array $req_body 相应RestApi所需要的请求包体内容 711 | * @return array 通过解析REST接口json返回包得到的关联数组, 其中包含成功与否、及错误提示(如果有错误)等字段 712 | */ 713 | abstract function comm_rest($server_name, $command, $req_body); 714 | } 715 | ?> 716 | -------------------------------------------------------------------------------- /signature/linux-signature32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tencentyun/imsdk_restapi-php-sdk/6ab6b6314afda9b8b720af2c4abdbe11aa0c2d8d/signature/linux-signature32 -------------------------------------------------------------------------------- /signature/linux-signature64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tencentyun/imsdk_restapi-php-sdk/6ab6b6314afda9b8b720af2c4abdbe11aa0c2d8d/signature/linux-signature64 -------------------------------------------------------------------------------- /signature/windows-signature32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tencentyun/imsdk_restapi-php-sdk/6ab6b6314afda9b8b720af2c4abdbe11aa0c2d8d/signature/windows-signature32.exe -------------------------------------------------------------------------------- /signature/windows-signature64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tencentyun/imsdk_restapi-php-sdk/6ab6b6314afda9b8b720af2c4abdbe11aa0c2d8d/signature/windows-signature64.exe --------------------------------------------------------------------------------