找回密码
 立即注册

QQ登录

只需一步,快速开始

网易云信IM类 SDK (Thinkphp5)

crx349 于 2017-10-30 23:45 [ThinkPHP 5] 发表在 [复制链接] [显示全部楼层] [打印] [上一主题] [下一主题]

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: CRX349
  5. * 网易云信工具类
  6. */
  7. namespace yunxin;

  8. use Think\Log;

  9. class YxUtils {

  10.     private $AppKey;                //开发者平台分配的AppKey
  11.     private $AppSecret;             //开发者平台分配的AppSecret,可刷新
  12.     private $Nonce;                    //随机数(最大长度128个字符)
  13.     private $CurTime;              //当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
  14.     private $CheckSum;             //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)
  15.     const   HEX_DIGITS = "0123456789abcdef";

  16.     /**
  17.      * 参数初始化
  18.      * @param $AppKey
  19.      * @param $AppSecret
  20.      * @param $RequestType [选择php请求方式,fsockopen或curl,若为curl方式,请检查php配置是否开启]
  21.      */
  22.     public function __construct($AppKey,$AppSecret,$RequestType='curl'){
  23.         $this->AppKey    = $AppKey;
  24.         $this->AppSecret = $AppSecret;
  25.         $this->RequestType = $RequestType;
  26.     }

  27.     /**
  28.      * API checksum校验生成
  29.      * @param  void
  30.      * @return $CheckSum(对象私有属性)
  31.      */
  32.     public function checkSumBuilder(){
  33.         //此部分生成随机字符串
  34.         $hex_digits = self::HEX_DIGITS;
  35.         $this->Nonce;
  36.         for($i=0;$i<128;$i++){          //随机字符串最大128个字符,也可以小于该数
  37.             $this->Nonce.= $hex_digits[rand(0,15)];
  38.         }
  39.         $this->CurTime = (string)(time()); //当前时间戳,以秒为单位

  40.         $join_string = $this->AppSecret.$this->Nonce.$this->CurTime;
  41.         $this->CheckSum = sha1($join_string);
  42.         //print_r($this->CheckSum);
  43.     }
  44.     /**
  45.      * 将json字符串转化成php数组
  46.      * @param  $json_str
  47.      * @return $json_arr
  48.      */
  49.     public function json_to_array($json_str){
  50.         // version 1.6 code ...
  51.         // if(is_null(json_decode($json_str))){
  52.         //     $json_str = $json_str;
  53.         // }else{
  54.         //     $json_str = json_decode($json_str);
  55.         // }
  56.         // $json_arr=array();
  57.         // //print_r($json_str);
  58.         // foreach($json_str as $k=>$w){
  59.         //     if(is_object($w)){
  60.         //         $json_arr[$k]= $this->json_to_array($w); //判断类型是不是object
  61.         //     }else if(is_array($w)){
  62.         //         $json_arr[$k]= $this->json_to_array($w);
  63.         //     }else{
  64.         //         $json_arr[$k]= $w;
  65.         //     }
  66.         // }
  67.         // return $json_arr;

  68.         if(is_array($json_str) || is_object($json_str)){
  69.             $json_str = $json_str;
  70.         }else if(is_null(json_decode($json_str))){
  71.             $json_str = $json_str;
  72.         }else{
  73.             $json_str =  strval($json_str);
  74.             $json_str = json_decode($json_str,true);
  75.         }
  76.         $json_arr=array();
  77.         foreach($json_str as $k=>$w){
  78.             if(is_object($w)){
  79.                 $json_arr[$k]= $this->json_to_array($w); //判断类型是不是object
  80.             }else if(is_array($w)){
  81.                 $json_arr[$k]= $this->json_to_array($w);
  82.             }else{
  83.                 $json_arr[$k]= $w;
  84.             }
  85.         }
  86.         return $json_arr;
  87.     }

  88.     /**
  89.      * 使用CURL方式发送post请求
  90.      * @param  $url    [请求地址]
  91.      * @param  $data    [array格式数据]
  92.      * @return $请求返回结果(array)
  93.      */
  94.     public function postDataCurl($url,$data){
  95.         $this->checkSumBuilder();      //发送请求前需先生成checkSum

  96.         $timeout = 5000;
  97.         $http_header = array(
  98.             'AppKey:'.$this->AppKey,
  99.             'Nonce:'.$this->Nonce,
  100.             'CurTime:'.$this->CurTime,
  101.             'CheckSum:'.$this->CheckSum,
  102.             'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
  103.         );
  104.         //print_r($http_header);
  105.         $postdata = '';
  106.         foreach ($data as $key=>$value){
  107.             $postdata.= ($key.'='.$value.'&');
  108.         }
  109.         $ch = curl_init();
  110.         curl_setopt ($ch, CURLOPT_URL, $url);
  111.         curl_setopt ($ch, CURLOPT_POST, 1);
  112.         curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
  113.         curl_setopt ($ch, CURLOPT_HEADER, false );
  114.         curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
  115.         curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //处理http证书问题
  116.         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  117.         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  118.         $result = curl_exec($ch);
  119.         if (false === $result) {
  120.             $result =  curl_errno($ch);
  121.         }
  122.         curl_close($ch);
  123.         return json_decode($result,true) ;
  124.     }

  125.     /**
  126.      * 使用FSOCKOPEN方式发送post请求
  127.      * @param  $url     [请求地址]
  128.      * @param  $data    [array格式数据]
  129.      * @return $请求返回结果(array)
  130.      */
  131.     public function postDataFsockopen($url,$data){
  132.         $this->checkSumBuilder();       //发送请求前需先生成checkSum

  133.         $postdata = '';
  134.         foreach ($data as $key=>$value){
  135.             $postdata.= ($key.'='.urlencode($value).'&');
  136.         }
  137.         // building POST-request:
  138.         $URL_Info=parse_url($url);
  139.         if(!isset($URL_Info["port"])){
  140.             $URL_Info["port"]=80;
  141.         }
  142.         $request = '';
  143.         $request.="POST ".$URL_Info["path"]." HTTP/1.1\r\n";
  144.         $request.="Host:".$URL_Info["host"]."\r\n";
  145.         $request.="Content-type: application/x-www-form-urlencoded;charset=utf-8\r\n";
  146.         $request.="Content-length: ".strlen($postdata)."\r\n";
  147.         $request.="Connection: close\r\n";
  148.         $request.="AppKey: ".$this->AppKey."\r\n";
  149.         $request.="Nonce: ".$this->Nonce."\r\n";
  150.         $request.="CurTime: ".$this->CurTime."\r\n";
  151.         $request.="CheckSum: ".$this->CheckSum."\r\n";
  152.         $request.="\r\n";
  153.         $request.=$postdata."\r\n";

  154.         //print_r($request);
  155.         $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
  156.         fputs($fp, $request);
  157.         $result = '';
  158.         while(!feof($fp)) {
  159.             $result .= fgets($fp, 128);
  160.         }
  161.         fclose($fp);

  162.         $str_s = strpos($result,'{');
  163.         $str_e = strrpos($result,'}');
  164.         $str = substr($result, $str_s,$str_e-$str_s+1);
  165.         return json_decode($str,true) ;
  166.     }
  167.     /**
  168.      * 使用CURL方式发送post请求(JSON类型)
  169.      * @param  $url         [请求地址]
  170.      * @param  $data    [array格式数据]
  171.      * @return $请求返回结果(array)
  172.      */
  173.     public function postJsonDataCurl($url,$data){
  174.         $this->checkSumBuilder();                //发送请求前需先生成checkSum

  175.         $timeout = 5000;
  176.         $http_header = array(
  177.             'AppKey:'.$this->AppKey,
  178.             'Nonce:'.$this->Nonce,
  179.             'CurTime:'.$this->CurTime,
  180.             'CheckSum:'.$this->CheckSum,
  181.             'Content-Type:application/json;charset=utf-8'
  182.         );
  183.         //print_r($http_header);

  184.         $postdata = json_encode($data);

  185.         $ch = curl_init();
  186.         curl_setopt ($ch, CURLOPT_URL, $url);
  187.         curl_setopt ($ch, CURLOPT_POST, 1);
  188.         curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
  189.         curl_setopt ($ch, CURLOPT_HEADER, false );
  190.         curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);
  191.         curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //处理http证书问题
  192.         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  193.         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  194.         $result = curl_exec($ch);
  195.         if (false === $result) {
  196.             $result =  curl_errno($ch);
  197.         }
  198.         curl_close($ch);
  199.         return $this->json_to_array($result) ;
  200.     }

  201.     /**
  202.      * 使用FSOCKOPEN方式发送post请求(json)
  203.      * @param  $url     [请求地址]
  204.      * @param  $data    [array格式数据]
  205.      * @return $请求返回结果(array)
  206.      */
  207.     public function postJsonDataFsockopen($url, $data){
  208.         $this->checkSumBuilder();       //发送请求前需先生成checkSum

  209.         $postdata = json_encode($data);

  210.         // building POST-request:
  211.         $URL_Info=parse_url($url);
  212.         if(!isset($URL_Info["port"])){
  213.             $URL_Info["port"]=80;
  214.         }
  215.         $request = '';
  216.         $request.="POST ".$URL_Info["path"]." HTTP/1.1\r\n";
  217.         $request.="Host:".$URL_Info["host"]."\r\n";
  218.         $request.="Content-type: application/json;charset=utf-8\r\n";
  219.         $request.="Content-length: ".strlen($postdata)."\r\n";
  220.         $request.="Connection: close\r\n";
  221.         $request.="AppKey: ".$this->AppKey."\r\n";
  222.         $request.="Nonce: ".$this->Nonce."\r\n";
  223.         $request.="CurTime: ".$this->CurTime."\r\n";
  224.         $request.="CheckSum: ".$this->CheckSum."\r\n";
  225.         $request.="\r\n";
  226.         $request.=$postdata."\r\n";

  227.         print_r($request);
  228.         $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
  229.         fputs($fp, $request);
  230.         $result = '';
  231.         while(!feof($fp)) {
  232.             $result .= fgets($fp, 128);
  233.         }
  234.         fclose($fp);

  235.         $str_s = strpos($result,'{');
  236.         $str_e = strrpos($result,'}');
  237.         $str = substr($result, $str_s,$str_e-$str_s+1);
  238.         return $this->json_to_array($str);
  239.     }
  240.     /**
  241.      * 创建云信ID
  242.      * 1.第三方帐号导入到云信平台;
  243.      * 2.注意accid,name长度以及考虑管理秘钥token
  244.      * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  245.      * @param  $name      [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
  246.      * @param  $props     [json属性,第三方可选填,最大长度1024字节]
  247.      * @param  $icon      [云信ID头像URL,第三方可选填,最大长度1024]
  248.      * @param  $token     [云信ID可以指定登录token值,最大长度128字节,并更新,如果未指定,会自动生成token,并在创建成功后返回]
  249.      * @return $result    [返回array数组对象]
  250.      */
  251.     public function createUserId($accid,$name='',$props='{}',$icon='',$token=''){
  252.         $url = 'https://api.netease.im/nimserver/user/create.action';
  253.         $data= array(
  254.             'accid' => $accid,
  255.             'name'  => $name,
  256.             'props' => $props,
  257.             'icon'  => $icon,
  258.             'token' => $token
  259.         );
  260.         if($this->RequestType=='curl'){
  261.             $result = $this->postDataCurl($url,$data);
  262.         }else{
  263.             $result = $this->postDataFsockopen($url,$data);
  264.         }
  265.         return $result;
  266.     }

  267.     /**
  268.      * @Author CR
  269.      * @date 2017/8/5
  270.      * 生成AccId
  271.      * 规则 :当前时间+6位随机码
  272.      */
  273.     public function generateAccId() {
  274.         $ran = rand(10000, 99999);
  275.         return date('YmdHis') . $ran;
  276.     }

  277.     /**
  278.      * 更新云信ID
  279.      * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  280.      * @param  $name      [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
  281.      * @param  $props     [json属性,第三方可选填,最大长度1024字节]
  282.      * @param  $token     [云信ID可以指定登录token值,最大长度128字节,并更新,如果未指定,会自动生成token,并在创建成功后返回]
  283.      * @return $result    [返回array数组对象]
  284.      */
  285.     public function updateUserId($accid,$name='',$props='{}',$token=''){
  286.         $url = 'https://api.netease.im/nimserver/user/update.action';
  287.         $data= array(
  288.             'accid' => $accid,
  289.             'name'  => $name,
  290.             'props' => $props,
  291.             'token' => $token
  292.         );
  293.         if($this->RequestType=='curl'){
  294.             $result = $this->postDataCurl($url,$data);
  295.         }else{
  296.             $result = $this->postDataFsockopen($url,$data);
  297.         }
  298.         return $result;
  299.     }

  300.     /**
  301.      * 更新并获取新token
  302.      * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  303.      * @return $result    [返回array数组对象]
  304.      */
  305.     public function updateUserToken($accid){
  306.         $url = 'https://api.netease.im/nimserver/user/refreshToken.action';
  307.         $data= array(
  308.             'accid' => $accid
  309.         );
  310.         if($this->RequestType=='curl'){
  311.             $result = $this->postDataCurl($url,$data);
  312.         }else{
  313.             $result = $this->postDataFsockopen($url,$data);
  314.         }
  315.         return $result;
  316.     }

  317.     /**
  318.      * 封禁云信ID
  319.      * 第三方禁用某个云信ID的IM功能,封禁云信ID后,此ID将不能登陆云信imserver
  320.      * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  321.      * @return $result    [返回array数组对象]
  322.      */
  323.     public function blockUserId($accid){
  324.         $url = 'https://api.netease.im/nimserver/user/block.action';
  325.         $data= array(
  326.             'accid' => $accid
  327.         );
  328.         if($this->RequestType=='curl'){
  329.             $result = $this->postDataCurl($url,$data);
  330.         }else{
  331.             $result = $this->postDataFsockopen($url,$data);
  332.         }
  333.         return $result;
  334.     }

  335.     /**
  336.      * 解禁云信ID
  337.      * 第三方禁用某个云信ID的IM功能,封禁云信ID后,此ID将不能登陆云信imserver
  338.      * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  339.      * @return $result    [返回array数组对象]
  340.      */
  341.     public function unblockUserId($accid){
  342.         $url = 'https://api.netease.im/nimserver/user/unblock.action';
  343.         $data= array(
  344.             'accid' => $accid
  345.         );
  346.         if($this->RequestType=='curl'){
  347.             $result = $this->postDataCurl($url,$data);
  348.         }else{
  349.             $result = $this->postDataFsockopen($url,$data);
  350.         }
  351.         return $result;
  352.     }


  353.     /**
  354.      * 更新用户名片
  355.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  356.      * @param  $name        [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
  357.      * @param  $icon        [用户icon,最大长度256字节]
  358.      * @param  $sign        [用户签名,最大长度256字节]
  359.      * @param  $email       [用户email,最大长度64字节]
  360.      * @param  $birth       [用户生日,最大长度16字节]
  361.      * @param  $mobile      [用户mobile,最大长度32字节]
  362.      * @param  $ex          [用户名片扩展字段,最大长度1024字节,用户可自行扩展,建议封装成JSON字符串]
  363.      * @param  $gender      [用户性别,0表示未知,1表示男,2女表示女,其它会报参数错误]
  364.      * @return $result      [返回array数组对象]
  365.      */
  366.     public function updateUinfo($accid,$name='',$icon='',$sign='',$email='',$birth='',$mobile='',$gender='0',$ex=''){
  367.         $url = 'https://api.netease.im/nimserver/user/updateUinfo.action';
  368.         $data= array(
  369.             'accid' => $accid,
  370.             'name' => $name,
  371.             'icon' => $icon,
  372.             'sign' => $sign,
  373.             'email' => $email,
  374.             'birth' => $birth,
  375.             'mobile' => $mobile,
  376.             'gender' => $gender,
  377.             'ex' => $ex
  378.         );
  379.         if($this->RequestType=='curl'){
  380.             $result = $this->postDataCurl($url,$data);
  381.         }else{
  382.             $result = $this->postDataFsockopen($url,$data);
  383.         }
  384.         return $result;
  385.     }

  386.     /**
  387.      * 获取用户名片,可批量
  388.      * @param  $accids    [用户帐号(例如:JSONArray对应的accid串,如:"zhangsan",如果解析出错,会报414)(一次查询最多为200)]
  389.      * @return $result    [返回array数组对象]
  390.      */
  391.     public function getUinfos($accids){
  392.         $url = 'https://api.netease.im/nimserver/user/getUinfos.action';
  393.         $data= array(
  394.             'accids' => json_encode($accids)
  395.         );
  396.         if($this->RequestType=='curl'){
  397.             $result = $this->postDataCurl($url,$data);
  398.         }else{
  399.             $result = $this->postDataFsockopen($url,$data);
  400.         }
  401.         return $result;
  402.     }

  403.     /**
  404.      * 好友关系-加好友
  405.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  406.      * @param  $faccid        [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
  407.      * @param  $type        [用户type,最大长度256字节]
  408.      * @param  $msg        [用户签名,最大长度256字节]
  409.      * @return $result      [返回array数组对象]
  410.      */
  411.     public function addFriend($accid,$faccid,$type,$msg=''){
  412.         $url = 'https://api.netease.im/nimserver/friend/add.action';
  413.         $data= array(
  414.             'accid' => $accid,
  415.             'faccid' => $faccid,
  416.             'type' => $type,
  417.             'msg' => $msg
  418.         );
  419.         if($this->RequestType=='curl'){
  420.             $result = $this->postDataCurl($url,$data);
  421.         }else{
  422.             $result = $this->postDataFsockopen($url,$data);
  423.         }
  424.         return $result;
  425.     }

  426.     /**
  427.      * 好友关系-更新好友信息
  428.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  429.      * @param  $faccid        [要修改朋友的accid]
  430.      * @param  $alias        [给好友增加备注名]
  431.      * @return $result      [返回array数组对象]
  432.      */
  433.     public function updateFriend($accid,$faccid,$alias){
  434.         $url = 'https://api.netease.im/nimserver/friend/update.action';
  435.         $data= array(
  436.             'accid' => $accid,
  437.             'faccid' => $faccid,
  438.             'alias' => $alias
  439.         );
  440.         if($this->RequestType=='curl'){
  441.             $result = $this->postDataCurl($url,$data);
  442.         }else{
  443.             $result = $this->postDataFsockopen($url,$data);
  444.         }
  445.         return $result;
  446.     }

  447.     /**
  448.      * 好友关系-获取好友关系
  449.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  450.      * @return $result      [返回array数组对象]
  451.      */
  452.     public function getFriend($accid){
  453.         $url = 'https://api.netease.im/nimserver/friend/get.action';
  454.         $data= array(
  455.             'accid' => $accid,
  456.             'createtime' => (string)(time())
  457.         );
  458.         if($this->RequestType=='curl'){
  459.             $result = $this->postDataCurl($url,$data);
  460.         }else{
  461.             $result = $this->postDataFsockopen($url,$data);
  462.         }
  463.         return $result;
  464.     }

  465.     /**
  466.      * 好友关系-删除好友信息
  467.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  468.      * @param  $faccid        [要修改朋友的accid]
  469.      * @return $result      [返回array数组对象]
  470.      */
  471.     public function deleteFriend($accid,$faccid){
  472.         $url = 'https://api.netease.im/nimserver/friend/delete.action';
  473.         $data= array(
  474.             'accid' => $accid,
  475.             'faccid' => $faccid
  476.         );
  477.         if($this->RequestType=='curl'){
  478.             $result = $this->postDataCurl($url,$data);
  479.         }else{
  480.             $result = $this->postDataFsockopen($url,$data);
  481.         }
  482.         return $result;
  483.     }

  484.     /**
  485.      * 好友关系-设置黑名单
  486.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  487.      * @param  $targetAcc        [被加黑或加静音的帐号]
  488.      * @param  $relationType        [本次操作的关系类型,1:黑名单操作,2:静音列表操作]
  489.      * @param  $value        [操作值,0:取消黑名单或静音;1:加入黑名单或静音]
  490.      * @return $result      [返回array数组对象]
  491.      */
  492.     public function specializeFriend($accid,$targetAcc,$relationType,$value){
  493.         $url = 'https://api.netease.im/nimserver/user/setSpecialRelation.action';
  494.         $data= array(
  495.             'accid' => $accid,
  496.             'targetAcc' => $targetAcc,
  497.             'relationType' => $relationType,
  498.             'value' => $value
  499.         );
  500.         if($this->RequestType=='curl'){
  501.             $result = $this->postDataCurl($url,$data);
  502.         }else{
  503.             $result = $this->postDataFsockopen($url,$data);
  504.         }
  505.         return $result;
  506.     }

  507.     /**
  508.      * 好友关系-查看黑名单列表
  509.      * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
  510.      * @return $result      [返回array数组对象]
  511.      */
  512.     public function listBlackFriend($accid){
  513.         $url = 'https://api.netease.im/nimserver/user/listBlackAndMuteList.action';
  514.         $data= array(
  515.             'accid' => $accid
  516.         );
  517.         if($this->RequestType=='curl'){
  518.             $result = $this->postDataCurl($url,$data);
  519.         }else{
  520.             $result = $this->postDataFsockopen($url,$data);
  521.         }
  522.         return $result;
  523.     }

  524.     /**
  525.      * 消息功能-发送普通消息
  526.      * @param  $from       [发送者accid,用户帐号,最大32字节,APP内唯一]
  527.      * @param  $ope        [0:点对点个人消息,1:群消息,其他返回414]
  528.      * @param  $to        [ope==0是表示accid,ope==1表示tid]
  529.      * @param  $type        [0 表示文本消息,1 表示图片,2 表示语音,3 表示视频,4 表示地理位置信息,6 表示文件,100 自定义消息类型]
  530.      * @param  $body       [请参考下方消息示例说明中对应消息的body字段。最大长度5000字节,为一个json字段。]
  531.      * @param  $option       [发消息时特殊指定的行为选项,Json格式,可用于指定消息的漫游,存云端历史,发送方多端同步,推送,消息抄送等特殊行为;option中字段不填时表示默认值]
  532.      * @param  $pushcontent      [推送内容,发送消息(文本消息除外,type=0),option选项中允许推送(push=true),此字段可以指定推送内容。 最长200字节]
  533.      */
  534.     public function sendMsg($from,$ope,$to,$type,$body,$option='{"push":false,"roam":true,"history":false,"sendersync":true, "route":false}',$pushcontent=''){
  535.         $url = 'https://api.netease.im/nimserver/msg/sendMsg.action';
  536.         $data= array(
  537.             'from' => $from,
  538.             'ope' => $ope,
  539.             'to' => $to,
  540.             'type' => $type,
  541.             'body' => json_encode($body),
  542.             'option' => $option,
  543.             'pushcontent' => $pushcontent
  544.         );
  545.         if($this->RequestType=='curl'){
  546.             $result = $this->postDataCurl($url,$data);
  547.         }else{
  548.             $result = $this->postDataFsockopen($url,$data);
  549.         }
  550.         return $result;
  551.     }

  552.     /**
  553.      * 消息功能-发送自定义系统消息
  554.      * 1.自定义系统通知区别于普通消息,方便开发者进行业务逻辑的通知。
  555.      * 2.目前支持两种类型:点对点类型和群类型(仅限高级群),根据msgType有所区别。
  556.      * @param  $from       [发送者accid,用户帐号,最大32字节,APP内唯一]
  557.      * @param  $msgtype        [0:点对点个人消息,1:群消息,其他返回414]
  558.      * @param  $to        [msgtype==0是表示accid,msgtype==1表示tid]
  559.      * @param  $attach        [自定义通知内容,第三方组装的字符串,建议是JSON串,最大长度1024字节]
  560.      * @param  $pushcontent       [ios推送内容,第三方自己组装的推送内容,如果此属性为空串,自定义通知将不会有推送(pushcontent + payload不能超过200字节)]
  561.      * @param  $payload       [ios 推送对应的payload,必须是JSON(pushcontent + payload不能超过200字节)]
  562.      * @param  $sound      [如果有指定推送,此属性指定为客户端本地的声音文件名,长度不要超过30个字节,如果不指定,会使用默认声音]
  563.      */
  564.     public function sendAttachMsg($from,$msgtype,$to,$attach,$pushcontent='',$payload='{}',$sound=''){
  565.         $url = 'https://api.netease.im/nimserver/msg/sendAttachMsg.action';
  566.         $data= array(
  567.             'from' => $from,
  568.             'msgtype' => $msgtype,
  569.             'to' => $to,
  570.             'attach' => $attach,
  571.             'pushcontent' => $pushcontent,
  572.             'payload' => $payload,
  573.             'sound' => $sound
  574.         );
  575.         if($this->RequestType=='curl'){
  576.             $result = $this->postDataCurl($url,$data);
  577.         }else{
  578.             $result = $this->postDataFsockopen($url,$data);
  579.         }
  580.         return $result;
  581.     }

  582.     /**
  583.      * 消息功能-文件上传
  584.      * @param  $content       [字节流base64串(Base64.encode(bytes)) ,最大15M的字节流]
  585.      * @param  $type        [上传文件类型]
  586.      * @return $result      [返回array数组对象]
  587.      */
  588.     public function uploadMsg($content,$type='0'){
  589.         $url = 'https://api.netease.im/nimserver/msg/upload.action';
  590.         $data= array(
  591.             'content' => $content,
  592.             'type' => $type
  593.         );
  594.         if($this->RequestType=='curl'){
  595.             $result = $this->postDataCurl($url,$data);
  596.         }else{
  597.             $result = $this->postDataFsockopen($url,$data);
  598.         }
  599.         return $result;
  600.     }

  601.     /**
  602.      * 消息功能-文件上传(multipart方式)
  603.      * @param  $content       [字节流base64串(Base64.encode(bytes)) ,最大15M的字节流]
  604.      * @param  $type        [上传文件类型]
  605.      * @return $result      [返回array数组对象]
  606.      */
  607.     public function uploadMultiMsg($content,$type='0'){
  608.         $url = 'https://api.netease.im/nimserver/msg/upload.action';
  609.         $data= array(
  610.             'content' => $content,
  611.             'type' => $type
  612.         );
  613.         if($this->RequestType=='curl'){
  614.             $result = $this->postDataCurl($url,$data);
  615.         }else{
  616.             $result = $this->postDataFsockopen($url,$data);
  617.         }
  618.         return $result;
  619.     }


  620.     /**
  621.      * 群组功能(高级群)-创建群
  622.      * @param  $tname       [群名称,最大长度64字节]
  623.      * @param  $owner       [群主用户帐号,最大长度32字节]
  624.      * @param  $members     [["aaa","bbb"](JsonArray对应的accid,如果解析出错会报414),长度最大1024字节]
  625.      * @param  $announcement [群公告,最大长度1024字节]
  626.      * @param  $intro       [群描述,最大长度512字节]
  627.      * @param  $msg       [邀请发送的文字,最大长度150字节]
  628.      * @param  $magree      [管理后台建群时,0不需要被邀请人同意加入群,1需要被邀请人同意才可以加入群。其它会返回414。]
  629.      * @param  $joinmode    [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414]
  630.      * @param  $custom      [自定义高级群扩展属性,第三方可以跟据此属性自定义扩展自己的群属性。(建议为json),最大长度1024字节.]
  631.      * @return $result      [返回array数组对象]
  632.      */
  633.     public function createGroup($tname,$owner,$members,$announcement='',$intro='',$msg='',$magree='0',$joinmode='0',$custom='0'){
  634.         $url = 'https://api.netease.im/nimserver/team/create.action';
  635.         $data= array(
  636.             'tname' => $tname,
  637.             'owner' => $owner,
  638.             'members' => json_encode($members),
  639.             'announcement' => $announcement,
  640.             'intro' => $intro,
  641.             'msg' => $msg,
  642.             'magree' => $magree,
  643.             'joinmode' => $joinmode,
  644.             'custom' => $custom
  645.         );
  646.         if($this->RequestType=='curl'){
  647.             $result = $this->postDataCurl($url,$data);
  648.         }else{
  649.             $result = $this->postDataFsockopen($url,$data);
  650.         }
  651.         return $result;
  652.     }

  653.     /**
  654.      * 群组功能(高级群)-拉人入群
  655.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  656.      * @param  $owner       [群主用户帐号,最大长度32字节]
  657.      * @param  $members     [["aaa","bbb"](JsonArray对应的accid,如果解析出错会报414),长度最大1024字节]
  658.      * @param  $magree      [管理后台建群时,0不需要被邀请人同意加入群,1需要被邀请人同意才可以加入群。其它会返回414。]
  659.      * @param  $joinmode    [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414]
  660.      * @param  $custom      [自定义高级群扩展属性,第三方可以跟据此属性自定义扩展自己的群属性。(建议为json),最大长度1024字节.]
  661.      * @return $result      [返回array数组对象]
  662.      */
  663.     public function addIntoGroup($tid,$owner,$members,$magree='0',$msg='请您入伙'){
  664.         $url = 'https://api.netease.im/nimserver/team/add.action';
  665.         $data= array(
  666.             'tid' => $tid,
  667.             'owner' => $owner,
  668.             'members' => json_encode($members),
  669.             'magree' => $magree,
  670.             'msg' => $msg
  671.         );
  672.         if($this->RequestType=='curl'){
  673.             $result = $this->postDataCurl($url,$data);
  674.         }else{
  675.             $result = $this->postDataFsockopen($url,$data);
  676.         }
  677.         return $result;
  678.     }

  679.     /**
  680.      * 群组功能(高级群)-踢人出群
  681.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  682.      * @param  $owner       [群主用户帐号,最大长度32字节]
  683.      * @param  $member     [被移除人得accid,用户账号,最大长度字节]
  684.      * @return $result      [返回array数组对象]
  685.      */
  686.     public function kickFromGroup($tid,$owner,$member){
  687.         $url = 'https://api.netease.im/nimserver/team/kick.action';
  688.         $data= array(
  689.             'tid' => $tid,
  690.             'owner' => $owner,
  691.             'member' => $member
  692.         );
  693.         if($this->RequestType=='curl'){
  694.             $result = $this->postDataCurl($url,$data);
  695.         }else{
  696.             $result = $this->postDataFsockopen($url,$data);
  697.         }
  698.         return $result;
  699.     }

  700.     /**
  701.      * 群组功能(高级群)-解散群
  702.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  703.      * @param  $owner       [群主用户帐号,最大长度32字节]
  704.      * @return $result      [返回array数组对象]
  705.      */
  706.     public function removeGroup($tid,$owner){
  707.         $url = 'https://api.netease.im/nimserver/team/remove.action';
  708.         $data= array(
  709.             'tid' => $tid,
  710.             'owner' => $owner
  711.         );
  712.         if($this->RequestType=='curl'){
  713.             $result = $this->postDataCurl($url,$data);
  714.         }else{
  715.             $result = $this->postDataFsockopen($url,$data);
  716.         }
  717.         return $result;
  718.     }

  719.     /**
  720.      * 群组功能(高级群)-更新群资料
  721.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  722.      * @param  $owner       [群主用户帐号,最大长度32字节]
  723.      * @param  $tname     [群主用户帐号,最大长度32字节]
  724.      * @param  $announcement [群公告,最大长度1024字节]
  725.      * @param  $intro       [群描述,最大长度512字节]
  726.      * @param  $joinmode    [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414]
  727.      * @param  $custom      [自定义高级群扩展属性,第三方可以跟据此属性自定义扩展自己的群属性。(建议为json),最大长度1024字节.]
  728.      * @return $result      [返回array数组对象]
  729.      */
  730.     public function updateGroup($tid,$owner,$tname,$announcement='',$intro='',$joinmode='0',$custom=''){
  731.         $url = 'https://api.netease.im/nimserver/team/update.action';
  732.         $data= array(
  733.             'tid' => $tid,
  734.             'owner' => $owner,
  735.             'tname' => $tname,
  736.             'announcement' => $announcement,
  737.             'intro' => $intro,
  738.             'joinmode' => $joinmode,
  739.             'custom' => $custom
  740.         );
  741.         if($this->RequestType=='curl'){
  742.             $result = $this->postDataCurl($url,$data);
  743.         }else{
  744.             $result = $this->postDataFsockopen($url,$data);
  745.         }
  746.         return $result;
  747.     }

  748.     /**
  749.      * 群组功能(高级群)-群信息与成员列表查询
  750.      * @param  $tids       [群tid列表,如["3083","3084"]]
  751.      * @param  $ope       [1表示带上群成员列表,0表示不带群成员列表,只返回群信息]
  752.      * @return $result      [返回array数组对象]
  753.      */
  754.     public function queryGroup($tids,$ope='1'){
  755.         $url = 'https://api.netease.im/nimserver/team/query.action';
  756.         $data= array(
  757.             'tids' => json_encode($tids),
  758.             'ope' => $ope
  759.         );
  760.         if($this->RequestType=='curl'){
  761.             $result = $this->postDataCurl($url,$data);
  762.         }else{
  763.             $result = $this->postDataFsockopen($url,$data);
  764.         }
  765.         return $result;
  766.     }

  767.     /**
  768.      * 群组功能(高级群)-移交群主
  769.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  770.      * @param  $owner       [群主用户帐号,最大长度32字节]
  771.      * @param  $newowner     [新群主帐号,最大长度32字节]
  772.      * @param  $leave       [1:群主解除群主后离开群,2:群主解除群主后成为普通成员。其它414]
  773.      * @return $result      [返回array数组对象]
  774.      */
  775.     public function changeGroupOwner($tid,$owner,$newowner,$leave='2'){
  776.         $url = 'https://api.netease.im/nimserver/team/changeOwner.action';
  777.         $data= array(
  778.             'tid' => $tid,
  779.             'owner' => $owner,
  780.             'newowner' => $newowner,
  781.             'leave' => $leave
  782.         );
  783.         if($this->RequestType=='curl'){
  784.             $result = $this->postDataCurl($url,$data);
  785.         }else{
  786.             $result = $this->postDataFsockopen($url,$data);
  787.         }
  788.         return $result;
  789.     }

  790.     /**
  791.      * 群组功能(高级群)-任命管理员
  792.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  793.      * @param  $owner       [群主用户帐号,最大长度32字节]
  794.      * @param  $members     [["aaa","bbb"](JsonArray对应的accid,如果解析出错会报414),长度最大1024字节(群成员最多10个)]
  795.      * @return $result      [返回array数组对象]
  796.      */
  797.     public function addGroupManager($tid,$owner,$members){
  798.         $url = 'https://api.netease.im/nimserver/team/addManager.action';
  799.         $data= array(
  800.             'tid' => $tid,
  801.             'owner' => $owner,
  802.             'members' => json_encode($members)
  803.         );
  804.         if($this->RequestType=='curl'){
  805.             $result = $this->postDataCurl($url,$data);
  806.         }else{
  807.             $result = $this->postDataFsockopen($url,$data);
  808.         }
  809.         return $result;
  810.     }

  811.     /**
  812.      * 群组功能(高级群)-移除管理员
  813.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  814.      * @param  $owner       [群主用户帐号,最大长度32字节]
  815.      * @param  $members     [["aaa","bbb"](JsonArray对应的accid,如果解析出错会报414),长度最大1024字节(群成员最多10个)]
  816.      * @return $result      [返回array数组对象]
  817.      */
  818.     public function removeGroupManager($tid,$owner,$members){
  819.         $url = 'https://api.netease.im/nimserver/team/removeManager.action';
  820.         $data= array(
  821.             'tid' => $tid,
  822.             'owner' => $owner,
  823.             'members' => json_encode($members)
  824.         );
  825.         if($this->RequestType=='curl'){
  826.             $result = $this->postDataCurl($url,$data);
  827.         }else{
  828.             $result = $this->postDataFsockopen($url,$data);
  829.         }
  830.         return $result;
  831.     }

  832.     /**
  833.      * 群组功能(高级群)-获取某用户所加入的群信息
  834.      * @param  $accid       [要查询用户的accid]
  835.      * @return $result      [返回array数组对象]
  836.      */
  837.     public function joinTeams($accid){
  838.         $url = 'https://api.netease.im/nimserver/team/joinTeams.action';
  839.         $data= array(
  840.             'accid' => $accid
  841.         );
  842.         if($this->RequestType=='curl'){
  843.             $result = $this->postDataCurl($url,$data);
  844.         }else{
  845.             $result = $this->postDataFsockopen($url,$data);
  846.         }
  847.         return $result;
  848.     }


  849.     /**
  850.      * 群组功能(高级群)-修改群昵称
  851.      * @param  $tid       [云信服务器产生,群唯一标识,创建群时会返回,最大长度128字节]
  852.      * @param  $owner       [群主用户帐号,最大长度32字节]
  853.      * @param  $accid     [要修改群昵称对应群成员的accid]
  854.      * @param  $nick     [accid对应的群昵称,最大长度32字节。]
  855.      * @return $result      [返回array数组对象]
  856.      */
  857.     public function updateGroupNick($tid,$owner,$accid,$nick){
  858.         $url = 'https://api.netease.im/nimserver/team/updateTeamNick.action';
  859.         $data= array(
  860.             'tid' => $tid,
  861.             'owner' => $owner,
  862.             'accid' => $accid,
  863.             'nick' => $nick
  864.         );
  865.         if($this->RequestType=='curl'){
  866.             $result = $this->postDataCurl($url,$data);
  867.         }else{
  868.             $result = $this->postDataFsockopen($url,$data);
  869.         }
  870.         return $result;
  871.     }

  872.     /**
  873.      * 历史记录-单聊
  874.      * @param  $from       [发送者accid]
  875.      * @param  $to          [接收者accid]
  876.      * @param  $begintime     [开始时间,ms]
  877.      * @param  $endtime     [截止时间,ms]
  878.      * @param  $limit       [本次查询的消息条数上限(最多100条),小于等于0,或者大于100,会提示参数错误]
  879.      * @param  $reverse    [1按时间正序排列,2按时间降序排列。其它返回参数414.默认是按降序排列。]
  880.      * @return $result      [返回array数组对象]
  881.      */
  882.     public function querySessionMsg($from,$to,$begintime,$endtime='',$limit='100',$reverse='1'){
  883.         $url = 'https://api.netease.im/nimserver/history/querySessionMsg.action';
  884.         $data= array(
  885.             'from' => $from,
  886.             'to' => $to,
  887.             'begintime' => $begintime,
  888.             'endtime' => $endtime,
  889.             'limit' => $limit,
  890.             'reverse' => $reverse
  891.         );
  892.         if($this->RequestType=='curl'){
  893.             $result = $this->postDataCurl($url,$data);
  894.         }else{
  895.             $result = $this->postDataFsockopen($url,$data);
  896.         }
  897.         return $result;
  898.     }

  899.     /**
  900.      * 历史记录
  901.      * @param  $tid       [群id]
  902.      * @param  $accid          [查询用户对应的accid.]
  903.      * @param  $begintime     [开始时间,ms]
  904.      * @param  $endtime     [截止时间,ms]
  905.      * @param  $limit       [本次查询的消息条数上限(最多100条),小于等于0,或者大于100,会提示参数错误]
  906.      * @param  $reverse    [1按时间正序排列,2按时间降序排列。其它返回参数414.默认是按降序排列。]
  907.      * @return $result      [返回array数组对象]
  908.      */
  909.     public function queryGroupMsg($tid,$accid,$begintime,$endtime='',$limit='100',$reverse='1'){
  910.         $url = 'https://api.netease.im/nimserver/history/queryTeamMsg.action';
  911.         $data= array(
  912.             'tid' => $tid,
  913.             'accid' => $accid,
  914.             'begintime' => $begintime,
  915.             'endtime' => $endtime,
  916.             'limit' => $limit,
  917.             'reverse' => $reverse
  918.         );
  919.         if($this->RequestType=='curl'){
  920.             $result = $this->postDataCurl($url,$data);
  921.         }else{
  922.             $result = $this->postDataFsockopen($url,$data);
  923.         }
  924.         return $result;
  925.     }

  926.     /**
  927.      * 发送短信验证码
  928.      * @param  $mobile       [目标手机号]
  929.      * @param  $deviceId     [目标设备号,可选参数]
  930.      * @return $result      [返回array数组对象]
  931.      */
  932.     public function sendSmsCode($mobile,$deviceId=''){
  933.         $url = 'https://api.netease.im/sms/sendcode.action';
  934.         $data= array(
  935.             'mobile' => $mobile,
  936.             'deviceId' => $deviceId
  937.         );
  938.         if($this->RequestType=='curl'){
  939.             $result = $this->postDataCurl($url,$data);
  940.         }else{
  941.             $result = $this->postDataFsockopen($url,$data);
  942.         }
  943.         return $result;
  944.     }

  945.     /**
  946.      * 校验验证码
  947.      * @param  $mobile       [目标手机号]
  948.      * @param  $code          [验证码]
  949.      * @return $result      [返回array数组对象]
  950.      */
  951.     public function verifycode($mobile,$code=''){
  952.         $url = 'https://api.netease.im/sms/verifycode.action';
  953.         $data= array(
  954.             'mobile' => $mobile,
  955.             'code' => $code
  956.         );
  957.         if($this->RequestType=='curl'){
  958.             $result = $this->postDataCurl($url,$data);
  959.         }else{
  960.             $result = $this->postDataFsockopen($url,$data);
  961.         }
  962.         return $result;
  963.     }

  964.     /**
  965.      * 发送模板短信
  966.      * @param  $templateid       [模板编号(由客服配置之后告知开发者)]
  967.      * @param  $mobiles          [验证码]
  968.      * @param  $params          [短信参数列表,用于依次填充模板,JSONArray格式,如["xxx","yyy"];对于不包含变量的模板,不填此参数表示模板即短信全文内容]
  969.      * @return $result      [返回array数组对象]
  970.      */
  971.     public function sendSMSTemplate($templateid,$mobiles=array(),$params=''){
  972.         $url = 'https://api.netease.im/sms/sendtemplate.action';
  973.         $data= array(
  974.             'templateid' => $templateid,
  975.             'mobiles' => json_encode($mobiles),
  976.             'params' => $params
  977.         );
  978.         if($this->RequestType=='curl'){
  979.             $result = $this->postDataCurl($url,$data);
  980.         }else{
  981.             $result = $this->postDataFsockopen($url,$data);
  982.         }
  983.         return $result;
  984.     }

  985.     /**
  986.      * 查询模板短信发送状态
  987.      * @param  $sendid       [发送短信的编号sendid]
  988.      * @return $result      [返回array数组对象]
  989.      */
  990.     public function querySMSStatus($sendid){
  991.         $url = 'https://api.netease.im/sms/querystatus.action';
  992.         $data= array(
  993.             'sendid' => $sendid
  994.         );
  995.         if($this->RequestType=='curl'){
  996.             $result = $this->postDataCurl($url,$data);
  997.         }else{
  998.             $result = $this->postDataFsockopen($url,$data);
  999.         }
  1000.         return $result;
  1001.     }

  1002.     /**
  1003.      * 发起单人专线电话
  1004.      * @param  $callerAcc       [发起本次请求的用户的accid]
  1005.      * @param  $caller          [主叫方电话号码(不带+86这类国家码,下同)]
  1006.      * @param  $callee          [被叫方电话号码]
  1007.      * @param  $maxDur          [本通电话最大可持续时长,单位秒,超过该时长时通话会自动切断]
  1008.      * @return $result      [返回array数组对象]
  1009.      */
  1010.     public function startcall($callerAcc,$caller,$callee,$maxDur){
  1011.         $url = 'https://api.netease.im/call/ecp/startcall.action';
  1012.         $data= array(
  1013.             'callerAcc' => $callerAcc,
  1014.             'caller' => $caller,
  1015.             'callee' => $callee,
  1016.             'maxDur' => $maxDur
  1017.         );
  1018.         if($this->RequestType=='curl'){
  1019.             $result = $this->postDataCurl($url,$data);
  1020.         }else{
  1021.             $result = $this->postDataFsockopen($url,$data);
  1022.         }
  1023.         return $result;
  1024.     }

  1025.     /**
  1026.      * 发起专线会议电话
  1027.      * @param  $callerAcc       [发起本次请求的用户的accid]
  1028.      * @param  $caller          [主叫方电话号码(不带+86这类国家码,下同)]
  1029.      * @param  $callee          [所有被叫方电话号码,必须是json格式的字符串,如["13588888888","13699999999"]]
  1030.      * @param  $maxDur          [本通电话最大可持续时长,单位秒,超过该时长时通话会自动切断]
  1031.      * @return $result      [返回array数组对象]
  1032.      */
  1033.     public function startconf($callerAcc,$caller,$callee,$maxDur){
  1034.         $url = 'https://api.netease.im/call/ecp/startconf.action';
  1035.         $data= array(
  1036.             'callerAcc' => $callerAcc,
  1037.             'caller' => $caller,
  1038.             'callee' => json_encode($callee),
  1039.             'maxDur' => $maxDur
  1040.         );
  1041.         if($this->RequestType=='curl'){
  1042.             $result = $this->postDataCurl($url,$data);
  1043.         }else{
  1044.             $result = $this->postDataFsockopen($url,$data);
  1045.         }
  1046.         return $result;
  1047.     }

  1048.     /**
  1049.      * 查询单通专线电话或会议的详情
  1050.      * @param  $session       [本次通话的id号]
  1051.      * @param  $type          [通话类型,1:专线电话;2:专线会议]
  1052.      * @return $result      [返回array数组对象]
  1053.      */
  1054.     public function queryCallsBySession($session,$type){
  1055.         $url = 'https://api.netease.im/call/ecp/queryBySession.action';
  1056.         $data= array(
  1057.             'session' => $session,
  1058.             'type' => $type
  1059.         );
  1060.         if($this->RequestType=='curl'){
  1061.             $result = $this->postDataCurl($url,$data);
  1062.         }else{
  1063.             $result = $this->postDataFsockopen($url,$data);
  1064.         }
  1065.         return $result;
  1066.     }
  1067.     /**
  1068.      * 获取语音视频安全认证签名
  1069.      * @param  $uid       [用户帐号唯一标识,必须是Long型]
  1070.      */
  1071.     public function getUserSignature($uid){
  1072.         $url = 'https://api.netease.im/nimserver/user/getToken.action';
  1073.         $data= array(
  1074.             'uid' => $uid
  1075.         );
  1076.         if($this->RequestType=='curl'){
  1077.             $result = $this->postDataCurl($url,$data);
  1078.         }else{
  1079.             $result = $this->postDataFsockopen($url,$data);
  1080.         }
  1081.         return $result;
  1082.     }

  1083.     /**
  1084.      * 创建一个直播频道
  1085.      * @param  $name       [频道名称, string]
  1086.      * @param  $type       [频道类型(0:rtmp;1:hls;2:http)]
  1087.      */
  1088.     public function channelCreate($name,$type){
  1089.         $url = 'https://vcloud.163.com/app/channel/create';
  1090.         $data= array(
  1091.             'name' => $name,
  1092.             'type' => $type
  1093.         );
  1094.         if($this->RequestType=='curl'){
  1095.             $result = $this->postJsonDataCurl($url,$data);
  1096.         }else{
  1097.             $result = $this->postJsonDataFsockopen($url,$data);
  1098.         }
  1099.         return $result;
  1100.     }

  1101.     /**
  1102.      * 修改直播频道信息
  1103.      * @param  $name       [频道名称, string]
  1104.      * @param  $cid       [频道ID,32位字符串]
  1105.      * @param  $type       [频道类型(0:rtmp;1:hls;2:http)]
  1106.      */
  1107.     public function channelUpdate($name, $cid, $type){
  1108.         $url = 'https://vcloud.163.com/app/channel/update';
  1109.         $data= array(
  1110.             'name' => $name,
  1111.             'cid' => $cid,
  1112.             'type' => $type
  1113.         );
  1114.         if($this->RequestType=='curl'){
  1115.             $result = $this->postJsonDataCurl($url,$data);
  1116.         }else{
  1117.             $result = $this->postJsonDataFsockopen($url,$data);
  1118.         }
  1119.         return $result;
  1120.     }

  1121.     /**
  1122.      * 删除一个直播频道
  1123.      * @param  $cid       [频道ID,32位字符串]
  1124.      */
  1125.     public function channelDelete($cid){
  1126.         $url = 'https://vcloud.163.com/app/channel/delete';
  1127.         $data= array(
  1128.             'cid' => $cid
  1129.         );
  1130.         if($this->RequestType=='curl'){
  1131.             $result = $this->postJsonDataCurl($url,$data);
  1132.         }else{
  1133.             $result = $this->postJsonDataFsockopen($url,$data);
  1134.         }
  1135.         return $result;
  1136.     }

  1137.     /**
  1138.      * 获取一个直播频道的信息
  1139.      * @param  $cid       [频道ID,32位字符串]
  1140.      */
  1141.     public function channelStats($cid){
  1142.         $url = 'https://vcloud.163.com/app/channelstats';
  1143.         $data= array(
  1144.             'cid' => $cid
  1145.         );
  1146.         if($this->RequestType=='curl'){
  1147.             $result = $this->postJsonDataCurl($url,$data);
  1148.         }else{
  1149.             $result = $this->postJsonDataFsockopen($url,$data);
  1150.         }
  1151.         return $result;
  1152.     }

  1153.     /**
  1154.      * 获取用户直播频道列表
  1155.      * @param  $records       [单页记录数,默认值为10]
  1156.      * @param  $pnum = 1       [要取第几页,默认值为1]
  1157.      * @param  $ofield       [排序的域,支持的排序域为:ctime(默认)]
  1158.      * @param  $sort            [升序还是降序,1升序,0降序,默认为desc]
  1159.      */
  1160.     public function channelList($records = 10, $pnum = 1, $ofield = 'ctime', $sort = 0){
  1161.         $url = 'https://vcloud.163.com/app/channellist';
  1162.         $data= array(
  1163.             'records' => $records,
  1164.             'pnum' => $pnum,
  1165.             'ofield' => $ofield,
  1166.             'sort' => $sort
  1167.         );
  1168.         if($this->RequestType=='curl'){
  1169.             $result = $this->postJsonDataCurl($url,$data);
  1170.         }else{
  1171.             $result = $this->postJsonDataFsockopen($url,$data);
  1172.         }
  1173.         return $result;
  1174.     }

  1175.     /**
  1176.      * 重新获取推流地址
  1177.      * @param  $cid       [频道ID,32位字符串]
  1178.      */
  1179.     public function channelRefreshAddr($cid){
  1180.         $url = 'https://vcloud.163.com/app/address';
  1181.         $data= array(
  1182.             'cid' => $cid
  1183.         );
  1184.         if($this->RequestType=='curl'){
  1185.             $result = $this->postJsonDataCurl($url,$data);
  1186.         }else{
  1187.             $result = $this->postJsonDataFsockopen($url,$data);
  1188.         }
  1189.         return $result;
  1190.     }
  1191. }
复制代码

本教程由无限星辰工作室CRX349独家整理和提供,转载请注明地址,谢谢。本文地址:https://www.xmspace.net/thread-556-1-1.html
无限星辰工作室  好集导航 Discuz全集下载  星辰站长网  集热爱361  一品文学  手机小游戏合集   海外空间网 星辰api  星辰支付二维码管理平台 阿里云服务器 腾讯云服务器
服务Discuz!建站|DiscuzQ配置|二开|小程序|APP|搬家|挂马清理|防护|Win/Linux环境搭建|优化|运维|
服务理念:专业 诚信 友好QQ842062626 服务项目 Q群315524225

发表于 2017-10-30 23:45:29 | 显示全部楼层 |阅读模式

回复 | 使用道具 举报

该帖共收到 0 条回复!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

美图秀

    • fastadmin 后台界面使用字段数组类型
    • Discuz!x3.5 修改标题高亮颜色
    • Discuz!x3.5 应用中心 下载应用一直下载中
    • 帖子定时显示
    • 论坛辅助审核
拖动客服框
Online Service
点击这里给我发消息
点击这里联系我们
微信扫一扫
在线客服
快速回复 返回顶部 返回列表