Thinkphp连系网易云IM代码类分享

精简版阿里大鱼短信接口短信SMS发送接口PHP实例

使用网易云IM做APP可以实现私聊、群聊、谈天室等通讯能力功效,网易云IM文档看起来对照庞大,许多新手不知道若何入手,今天跟版网总结一下,分享给人人学习使用。

1.封装的类如下:


<?php 
/** 
 * Created by PhpStorm. 
 * User: www.genban.org 
 */ 
namespace Org\Util; 
 
class YunxinServer{ 
 
    private $AppKey;                //开发者平台分配的AppKey 
    private $AppSecret;             //开发者平台分配的AppSecret,可刷新 
    private $Nonce;                 //随机数(最大长度128个字符) 
    private $CurTime;               //当前UTC时间戳,从1970年1月1日0点0 分0 秒最先到现在的秒数(String) 
    private $CheckSum;              //SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,举行SHA1哈希盘算,转化成16进制字符(String,小写) 
    const   HEX_DIGITS = "0123456789abcdef"; 
 
    /** 
     * 参数初始化 
     * @param $AppKey 
     * @param $AppSecret 
     * @param $RequestType [选择php请求方式,fsockopen或curl,若为curl方式,请检查php设置是否开启] 
     */ 
    public function __construct($AppKey,$AppSecret,$RequestType='curl'){ 
        $this->AppKey    = $AppKey; 
        $this->AppSecret = $AppSecret; 
        $this->RequestType = $RequestType; 
    } 
 
    /** 
     * API checksum校验天生 
     * @param  void 
     * @return $CheckSum(工具私有属性) 
     */ 
    public function checkSumBuilder(){ 
        //此部门天生随机字符串 
        $hex_digits = self::HEX_DIGITS; 
        $this->Nonce; 
        for($i=0;$i<128;$i++){          //随机字符串最大128个字符,也可以小于该数 
            $this->Nonce.= $hex_digits[rand(0,15)]; 
        } 
        $this->CurTime = (string)(time());  //当前时间戳,以秒为单元 
 
        $join_string = $this->AppSecret.$this->Nonce.$this->CurTime; 
        $this->CheckSum = sha1($join_string); 
        //print_r($this->CheckSum); 
    } 
 
    /** 
     * 将json字符串转化成php数组 
     * @param  $json_str 
     * @return $json_arr 
     */ 
    public function json_to_array($json_str){ 
        // version 1.6 code ... 
        // if(is_null(json_decode($json_str))){ 
        //     $json_str = $json_str; 
        // }else{ 
        //     $json_str = json_decode($json_str); 
        // } 
        // $json_arr=array(); 
        // //print_r($json_str); 
        // foreach($json_str as $k=>$w){ 
        //     if(is_object($w)){ 
        //         $json_arr[$k]= $this->json_to_array($w); //判断类型是不是object 
        //     }else if(is_array($w)){ 
        //         $json_arr[$k]= $this->json_to_array($w); 
        //     }else{ 
        //         $json_arr[$k]= $w; 
        //     } 
        // } 
        // return $json_arr; 
 
        if(is_array($json_str) || is_object($json_str)){ 
            $json_str = $json_str; 
        }else if(is_null(json_decode($json_str))){ 
            $json_str = $json_str; 
        }else{ 
            $json_str =  strval($json_str); 
            $json_str = json_decode($json_str,true); 
        } 
        $json_arr=array(); 
        foreach($json_str as $k=>$w){ 
            if(is_object($w)){ 
                $json_arr[$k]= $this->json_to_array($w); //判断类型是不是object 
            }else if(is_array($w)){ 
                $json_arr[$k]= $this->json_to_array($w); 
            }else{ 
                $json_arr[$k]= $w; 
            } 
        } 
        return $json_arr; 
    } 
 
    /** 
     * 使用CURL方式发送post请求 
     * @param  $url     [请求地址] 
     * @param  $data    [array花样数据] 
     * @return $请求返回效果(array) 
     */ 
    public function postDataCurl($url,$data){ 
        $this->checkSumBuilder();       //发送请求前需先天生checkSum 
 
        $timeout = 5000; 
        $http_header = array( 
            'AppKey:'.$this->AppKey, 
            'Nonce:'.$this->Nonce, 
            'CurTime:'.$this->CurTime, 
            'CheckSum:'.$this->CheckSum, 
            'Content-Type:application/x-www-form-urlencoded;charset=utf-8' 
        ); 
        //print_r($http_header); 
 
        // $postdata = ''; 
        $postdataArray = array(); 
        foreach ($data as $key=>$value){ 
            array_push($postdataArray, $key.'='.urlencode($value)); 
            // $postdata.= ($key.'='.urlencode($value).'&'); 
        } 
        $postdata = join('&', $postdataArray); 
 
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, $url); 
        curl_setopt ($ch, CURLOPT_POST, 1); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
        curl_setopt ($ch, CURLOPT_HEADER, false ); 
        curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //处置http证书问题 
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
 
        $result = curl_exec($ch); 
        if (false === $result) { 
            $result =  curl_errno($ch); 
        } 
        curl_close($ch); 
        return $this->json_to_array($result) ; 
    } 
 
    /** 
     * 使用FSOCKOPEN方式发送post请求 
     * @param  $url     [请求地址] 
     * @param  $data    [array花样数据] 
     * @return $请求返回效果(array) 
     */ 
    public function postDataFsockopen($url,$data){ 
        $this->checkSumBuilder();       //发送请求前需先天生checkSum 
 
        // $postdata = ''; 
        $postdataArray = array(); 
        foreach ($data as $key=>$value){ 
            array_push($postdataArray, $key.'='.urlencode($value)); 
            // $postdata.= ($key.'='.urlencode($value).'&'); 
        } 
        $postdata = join('&', $postdataArray); 
        // building POST-request: 
        $URL_Info=parse_url($url); 
        if(!isset($URL_Info["port"])){ 
            $URL_Info["port"]=80; 
        } 
        $request = ''; 
        $request.="POST ".$URL_Info["path"]." HTTP/1.1\r\n"; 
        $request.="Host:".$URL_Info["host"]."\r\n"; 
        $request.="Content-type: application/x-www-form-urlencoded;charset=utf-8\r\n"; 
        $request.="Content-length: ".strlen($postdata)."\r\n"; 
        $request.="Connection: close\r\n"; 
        $request.="AppKey: ".$this->AppKey."\r\n"; 
        $request.="Nonce: ".$this->Nonce."\r\n"; 
        $request.="CurTime: ".$this->CurTime."\r\n"; 
        $request.="CheckSum: ".$this->CheckSum."\r\n"; 
        $request.="\r\n"; 
        $request.=$postdata."\r\n"; 
 
        // print_r($request); 
        $fp = fsockopen($URL_Info["host"],$URL_Info["port"]); 
        fputs($fp, $request); 
        $result = ''; 
        while(!feof($fp)) { 
            $result .= fgets($fp, 128); 
        } 
        fclose($fp); 
 
        $str_s = strpos($result,'{'); 
        $str_e = strrpos($result,'}'); 
        $str = substr($result, $str_s,$str_e-$str_s+1); 
        return $this->json_to_array($str); 
    } 
 
    /** 
     * 使用CURL方式发送post请求(JSON类型) 
     * @param  $url     [请求地址] 
     * @param  $data    [array花样数据] 
     * @return $请求返回效果(array) 
     */ 
    public function postJsonDataCurl($url,$data){ 
        $this->checkSumBuilder();       //发送请求前需先天生checkSum 
 
        $timeout = 5000; 
        $http_header = array( 
            'AppKey:'.$this->AppKey, 
            'Nonce:'.$this->Nonce, 
            'CurTime:'.$this->CurTime, 
            'CheckSum:'.$this->CheckSum, 
            'Content-Type:application/json;charset=utf-8' 
        ); 
        //print_r($http_header); 
 
        $postdata = json_encode($data); 
 
        $ch = curl_init(); 
        curl_setopt ($ch, CURLOPT_URL, $url); 
        curl_setopt ($ch, CURLOPT_POST, 1); 
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
        curl_setopt ($ch, CURLOPT_HEADER, false ); 
        curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header); 
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false); //处置http证书问题 
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
 
        $result = curl_exec($ch); 
        if (false === $result) { 
            $result =  curl_errno($ch); 
        } 
        curl_close($ch); 
        return $this->json_to_array($result) ; 
    } 
 
    /** 
     * 使用FSOCKOPEN方式发送post请求(json) 
     * @param  $url     [请求地址] 
     * @param  $data    [array花样数据] 
     * @return $请求返回效果(array) 
     */ 
    public function postJsonDataFsockopen($url, $data){ 
        $this->checkSumBuilder();       //发送请求前需先天生checkSum 
 
        $postdata = json_encode($data); 
 
        // building POST-request: 
        $URL_Info=parse_url($url); 
        if(!isset($URL_Info["port"])){ 
            $URL_Info["port"]=80; 
        } 
        $request = ''; 
        $request.="POST ".$URL_Info["path"]." HTTP/1.1\r\n"; 
        $request.="Host:".$URL_Info["host"]."\r\n"; 
        $request.="Content-type: application/json;charset=utf-8\r\n"; 
        $request.="Content-length: ".strlen($postdata)."\r\n"; 
        $request.="Connection: close\r\n"; 
        $request.="AppKey: ".$this->AppKey."\r\n"; 
        $request.="Nonce: ".$this->Nonce."\r\n"; 
        $request.="CurTime: ".$this->CurTime."\r\n"; 
        $request.="CheckSum: ".$this->CheckSum."\r\n"; 
        $request.="\r\n"; 
        $request.=$postdata."\r\n"; 
 
        print_r($request); 
        $fp = fsockopen($URL_Info["host"],$URL_Info["port"]); 
        fputs($fp, $request); 
        $result = ''; 
        while(!feof($fp)) { 
            $result .= fgets($fp, 128); 
        } 
        fclose($fp); 
 
        $str_s = strpos($result,'{'); 
        $str_e = strrpos($result,'}'); 
        $str = substr($result, $str_s,$str_e-$str_s+1); 
        return $this->json_to_array($str); 
    } 
 
    /** 
     * 确立云信ID 
     * 1.第三方帐号导入到云信平台; 
     * 2.注重accid,name长度以及思量治理秘钥token 
     * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $name      [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称] 
     * @param  $props     [json属性,第三方可选填,最大长度1024字节] 
     * @param  $icon      [云信ID头像URL,第三方可选填,最大长度1024] 
     * @param  $token     [云信ID可以指定登录token值,最大长度128字节,并更新,若是未指定,会自动天生token,并在确立乐成后返回] 
     * @return $result    [返回array数组工具] 
     */ 
    public function createUserIds($accid,$name='',$props='{}',$icon='',$token=''){ 
        $url = 'https://api.netease.im/nimserver/user/create.action'; 
        $data= array( 
            'accid' => $accid, 
            'name'  => $name, 
            'props' => $props, 
            'icon'  => $icon, 
            'token' => $token 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
 
    /** 
     * 更新云信ID 
     * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $name      [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称] 
     * @param  $props     [json属性,第三方可选填,最大长度1024字节] 
     * @param  $token     [云信ID可以指定登录token值,最大长度128字节,并更新,若是未指定,会自动天生token,并在确立乐成后返回] 
     * @return $result    [返回array数组工具] 
     */ 
    public function updateUserId($accid,$name='',$props='{}',$token=''){ 
        $url = 'https://api.netease.im/nimserver/user/update.action'; 
        $data= array( 
            'accid' => $accid, 
            'name'  => $name, 
            'props' => $props, 
            'token' => $token 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 更新并获取新token 
     * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @return $result    [返回array数组工具] 
     */ 
    public function updateUserToken($accid){ 
        $url = 'https://api.netease.im/nimserver/user/refreshToken.action'; 
        $data= array( 
            'accid' => $accid 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 封禁云信ID 
     * 第三方禁用某个云信ID的IM功效,封禁云信ID后,此ID将不能上岸云信imserver 
     * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @return $result    [返回array数组工具] 
     */ 
    public function blockUserId($accid){ 
        $url = 'https://api.netease.im/nimserver/user/block.action'; 
        $data= array( 
            'accid' => $accid 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 解禁云信ID 
     * 第三方禁用某个云信ID的IM功效,封禁云信ID后,此ID将不能上岸云信imserver 
     * @param  $accid     [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @return $result    [返回array数组工具] 
     */ 
    public function unblockUserId($accid){ 
        $url = 'https://api.netease.im/nimserver/user/unblock.action'; 
        $data= array( 
            'accid' => $accid 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
 
    /** 
     * 更新用户手刺 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $name        [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称] 
     * @param  $icon        [用户icon,最大长度256字节] 
     * @param  $sign        [用户署名,最大长度256字节] 
     * @param  $email       [用户email,最大长度64字节] 
     * @param  $birth       [用户生日,最大长度16字节] 
     * @param  $mobile      [用户mobile,最大长度32字节] 
     * @param  $ex          [用户手刺扩展字段,最大长度1024字节,用户可自行扩展,建议封装成JSON字符串] 
     * @param  $gender      [用户性别,0示意未知,1示意男,2女示意女,其它会报参数错误] 
     * @return $result      [返回array数组工具] 
     */ 
    public function updateUinfo($accid,$name='',$icon='',$sign='',$email='',$birth='',$mobile='',$gender='0',$ex=''){ 
        $url = 'https://api.netease.im/nimserver/user/updateUinfo.action'; 
        $data= array( 
            'accid' => $accid, 
            'name' => $name, 
            'icon' => $icon, 
            'sign' => $sign, 
            'email' => $email, 
            'birth' => $birth, 
            'mobile' => $mobile, 
            'gender' => $gender, 
            'ex' => $ex 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 获取用户手刺,可批量 
     * @param  $accids    [用户帐号(例如:JSONArray对应的accid串,如:"zhangsan",若是剖析失足,会报414)(一次查询最多为200)] 
     * @return $result    [返回array数组工具] 
     */ 
    public function getUinfoss($accids){ 
        $url = 'https://api.netease.im/nimserver/user/getUinfos.action'; 
        $data= array( 
            'accids' => json_encode($accids) 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-加密友 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $faccid        [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称] 
     * @param  $type        [用户type,最大长度256字节] 
     * @param  $msg        [用户署名,最大长度256字节] 
     * @return $result      [返回array数组工具] 
     */ 
    public function addFriend($accid,$faccid,$type='1',$msg=''){ 
        $url = 'https://api.netease.im/nimserver/friend/add.action'; 
        $data= array( 
            'accid' => $accid, 
            'faccid' => $faccid, 
            'type' => $type, 
            'msg' => $msg 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-更新密友信息 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $faccid        [要修改同伙的accid] 
     * @param  $alias        [给密友增添备注名] 
     * @return $result      [返回array数组工具] 
     */ 
    public function updateFriend($accid,$faccid,$alias){ 
        $url = 'https://api.netease.im/nimserver/friend/update.action'; 
        $data= array( 
            'accid' => $accid, 
            'faccid' => $faccid, 
            'alias' => $alias 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-获取密友关系 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @return $result      [返回array数组工具] 
     */ 
    public function getFriend($accid){ 
        $url = 'https://api.netease.im/nimserver/friend/get.action'; 
        $data= array( 
            'accid' => $accid, 
            'createtime' => (string)(time()*1000) 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-删除密友信息 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $faccid        [要修改同伙的accid] 
     * @return $result      [返回array数组工具] 
     */ 
    public function deleteFriend($accid,$faccid){ 
        $url = 'https://api.netease.im/nimserver/friend/delete.action'; 
        $data= array( 
            'accid' => $accid, 
            'faccid' => $faccid 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-设置黑名单 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @param  $targetAcc        [被加黑或加静音的帐号] 
     * @param  $relationType        [本次操作的关系类型,1:黑名单操作,2:静音列表操作] 
     * @param  $value        [操作值,0:作废黑名单或静音;1:加入黑名单或静音] 
     * @return $result      [返回array数组工具] 
     */ 
    public function specializeFriend($accid,$targetAcc,$relationType='1',$value='1'){ 
        $url = 'https://api.netease.im/nimserver/user/setSpecialRelation.action'; 
        $data= array( 
            'accid' => $accid, 
            'targetAcc' => $targetAcc, 
            'relationType' => $relationType, 
            'value' => $value 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 密友关系-查看黑名单列表 
     * @param  $accid       [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分巨细写,会统一小写处置)] 
     * @return $result      [返回array数组工具] 
     */ 
    public function listBlackFriend($accid){ 
        $url = 'https://api.netease.im/nimserver/user/listBlackAndMuteList.action'; 
        $data= array( 
            'accid' => $accid 
        ); 
        if($this->RequestType=='curl'){ 
            $result = $this->postDataCurl($url,$data); 
        }else{ 
            $result = $this->postDataFsockopen($url,$data); 
        } 
        return $result; 
    } 
 
    /** 
     * 新闻功效-发送通俗新闻 
     * @param  $from       [发送者accid,用户帐号,最大32字节,APP内唯一] 
     * @param  $ope        [0:点对点小我私人新闻,1:群新闻,其他返回414] 
     * @param  $to        [ope==0是示意accid,ope==1示意tid] 
     * @param  $type        [0 示意文本新闻,1 示意图片,2 示意语音,3 示意视频,4 示意地理位置信息,6 示意文件,100 自界说新闻类型] 
     * @param  $body       [请参考下方新闻示例说明中对应新闻的body字段。最大长度5000字节,为一个json字段。] 
     * @param  $option       [发新闻时特殊指定的行为选项,Json花样,可用于指定新闻的周游,存云端历史,发送方多端同步,推送,新闻抄送等特殊行为;option中字段不填时示意默认值] 
     * @param  $pushcontent      [推送内容,发送新闻(文本新闻除外,type=0),

php发送短信(调用网易云信实现)

调用网易云信,实现短信发送

//网易云信发送短信 //http://dev.netease.im/docs?doc=server&#发送模板短信 function yx_sendsms($mobile='',$para

option选项中允许推送(push=true),此字段可以指定推送内容。 最长200字节] * @return $result [返回array数组工具] */ public function sendMsg($from,$ope,$to,$type,$body,$option=array("push"=>false,"roam"=>true,"history"=>false,"sendersync"=>true, "route"=>false),$pushcontent=''){ $url = 'https://api.netease.im/nimserver/msg/sendMsg.action'; $data= array( 'from' => $from, 'ope' => $ope, 'to' => $to, 'type' => $type, 'body' => json_encode($body), 'option' => json_encode($option), 'pushcontent' => $pushcontent ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 新闻功效-发送自界说系统新闻 * 1.自界说系统通知区别于通俗新闻,利便开发者举行营业逻辑的通知。 * 2.现在支持两种类型:点对点类型和群类型(仅限高级群),凭证msgType有所区别。 * @param $from [发送者accid,用户帐号,最大32字节,APP内唯一] * @param $msgtype [0:点对点小我私人新闻,1:群新闻,其他返回414] * @param $to [msgtype==0是示意accid,msgtype==1示意tid] * @param $attach [自界说通知内容,第三方组装的字符串,建议是JSON串,最大长度1024字节] * @param $pushcontent [ios推送内容,第三方自己组装的推送内容,若是此属性为空串,自界说通知将不会有推送(pushcontent + payload不能跨越200字节)] * @param $payload [ios 推送对应的payload,必须是JSON(pushcontent + payload不能跨越200字节)] * @param $sound [若是有指定推送,此属性指定为客户端内陆的声音文件名,长度不要跨越30个字节,若是不指定,会使用默认声音] * @return $result [返回array数组工具] */ public function sendAttachMsg($from,$msgtype,$to,$attach,$pushcontent='',$payload=array(),$sound=''){ $url = 'https://api.netease.im/nimserver/msg/sendAttachMsg.action'; $data= array( 'from' => $from, 'msgtype' => $msgtype, 'to' => $to, 'attach' => $attach, 'pushcontent' => $pushcontent, 'payload' => json_encode($payload), 'sound' => $sound ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 新闻功效-文件上传 * @param $content [字节省base64串(Base64.encode(bytes)) ,最大15M的字节省] * @param $type [上传文件类型] * @return $result [返回array数组工具] */ public function uploadMsg($content,$type='0'){ $url = 'https://api.netease.im/nimserver/msg/upload.action'; $data= array( 'content' => $content, 'type' => $type ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 新闻功效-文件上传(multipart方式) * @param $content [字节省base64串(Base64.encode(bytes)) ,最大15M的字节省] * @param $type [上传文件类型] * @return $result [返回array数组工具] */ public function uploadMultiMsg($content,$type='0'){ $url = 'https://api.netease.im/nimserver/msg/fileUpload.action'; $data= array( 'content' => $content, 'type' => $type ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-确立群 * @param $tname [群名称,最大长度64字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $members [["aaa","bbb"](JsonArray对应的accid,若是剖析失足会报414),长度最大1024字节] * @param $announcement [群通告,最大长度1024字节] * @param $intro [群形貌,最大长度512字节] * @param $msg [约请发送的文字,最大长度150字节] * @param $magree [治理后台建群时,0不需要被约请人赞成加入群,1需要被约请人赞成才可以加入群。其它会返回414。] * @param $joinmode [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414] * @param $custom [自界说高级群扩展属性,第三方可以跟据此属性自界说扩展自己的群属性。(建议为json),最大长度1024字节.] * @return $result [返回array数组工具] */ public function createGroup($tname,$owner,$members,$announcement='',$intro='',$msg='',$magree='0',$joinmode='0',$custom='0'){ $url = 'https://api.netease.im/nimserver/team/create.action'; $data= array( 'tname' => $tname, 'owner' => $owner, 'members' => json_encode($members), 'announcement' => $announcement, 'intro' => $intro, 'msg' => $msg, 'magree' => $magree, 'joinmode' => $joinmode, 'custom' => $custom ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-拉人入群 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $members [["aaa","bbb"](JsonArray对应的accid,若是剖析失足会报414),长度最大1024字节] * @param $magree [治理后台建群时,0不需要被约请人赞成加入群,1需要被约请人赞成才可以加入群。其它会返回414。] * @param $joinmode [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414] * @param $custom [自界说高级群扩展属性,第三方可以跟据此属性自界说扩展自己的群属性。(建议为json),最大长度1024字节.] * @return $result [返回array数组工具] */ public function addIntoGroup($tid,$owner,$members,$magree='0',$msg='请您入伙'){ $url = 'https://api.netease.im/nimserver/team/add.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'members' => json_encode($members), 'magree' => $magree, 'msg' => $msg ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-踢人出群 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $member [被移除人得accid,用户账号,最大长度字节] * @return $result [返回array数组工具] */ public function kickFromGroup($tid,$owner,$member){ $url = 'https://api.netease.im/nimserver/team/kick.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'member' => $member ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-遣散群 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @return $result [返回array数组工具] */ public function removeGroup($tid,$owner){ $url = 'https://api.netease.im/nimserver/team/remove.action'; $data= array( 'tid' => $tid, 'owner' => $owner ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-更新群资料 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $tname [群主用户帐号,最大长度32字节] * @param $announcement [群通告,最大长度1024字节] * @param $intro [群形貌,最大长度512字节] * @param $joinmode [群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414] * @param $custom [自界说高级群扩展属性,第三方可以跟据此属性自界说扩展自己的群属性。(建议为json),最大长度1024字节.] * @return $result [返回array数组工具] */ public function updateGroup($tid,$owner,$tname,$announcement='',$intro='',$joinmode='0',$custom=''){ $url = 'https://api.netease.im/nimserver/team/update.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'tname' => $tname, 'announcement' => $announcement, 'intro' => $intro, 'joinmode' => $joinmode, 'custom' => $custom ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-群信息与成员列表查询 * @param $tids [群tid列表,如[\&;3083\&;,\&;3084"]] * @param $ope [1示意带上群成员列表,0示意不带群成员列表,只返回群信息] * @return $result [返回array数组工具] */ public function queryGroup($tids,$ope='1'){ $url = 'https://api.netease.im/nimserver/team/query.action'; $data= array( 'tids' => json_encode($tids), 'ope' => $ope ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-移交群主 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $newowner [新群主帐号,最大长度32字节] * @param $leave [1:群主排除群主后脱离群,2:群主排除群主后成为通俗成员。其它414] * @return $result [返回array数组工具] */ public function changeGroupOwner($tid,$owner,$newowner,$leave='2'){ $url = 'https://api.netease.im/nimserver/team/changeOwner.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'newowner' => $newowner, 'leave' => $leave ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-任命治理员 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $members [["aaa","bbb"](JsonArray对应的accid,若是剖析失足会报414),长度最大1024字节(群成员最多10个)] * @return $result [返回array数组工具] */ public function addGroupManager($tid,$owner,$members){ $url = 'https://api.netease.im/nimserver/team/addManager.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'members' => json_encode($members) ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-移除治理员 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $members [["aaa","bbb"](JsonArray对应的accid,若是剖析失足会报414),长度最大1024字节(群成员最多10个)] * @return $result [返回array数组工具] */ public function removeGroupManager($tid,$owner,$members){ $url = 'https://api.netease.im/nimserver/team/removeManager.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'members' => json_encode($members) ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-获取某用户所加入的群信息 * @param $accid [要查询用户的accid] * @return $result [返回array数组工具] */ public function joinTeams($accid){ $url = 'https://api.netease.im/nimserver/team/joinTeams.action'; $data= array( 'accid' => $accid ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 群组功效(高级群)-修改群昵称 * @param $tid [云信服务器发生,群唯一标识,确立群时会返回,最大长度128字节] * @param $owner [群主用户帐号,最大长度32字节] * @param $accid [要修改群昵称对应群成员的accid] * @param $nick [accid对应的群昵称,最大长度32字节。] * @return $result [返回array数组工具] */ public function updateGroupNick($tid,$owner,$accid,$nick){ $url = 'https://api.netease.im/nimserver/team/updateTeamNick.action'; $data= array( 'tid' => $tid, 'owner' => $owner, 'accid' => $accid, 'nick' => $nick ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 历史纪录-单聊 * @param $from [发送者accid] * @param $to [吸收者accid] * @param $begintime [最先时间,ms] * @param $endtime [停止时间,ms] * @param $limit [本次查询的新闻条数上限(最多100条),小于即是0,或者大于100,会提醒参数错误] * @param $reverse [1准时间正序排列,2准时间降序排列。其它返回参数414.默认是按降序排列。] * @return $result [返回array数组工具] */ public function querySessionMsg($from,$to,$begintime,$endtime='',$limit='100',$reverse='1'){ $url = 'https://api.netease.im/nimserver/history/querySessionMsg.action'; $data= array( 'from' => $from, 'to' => $to, 'begintime' => $begintime, 'endtime' => $endtime, 'limit' => $limit, 'reverse' => $reverse ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 历史纪录-群聊 * @param $tid [群id] * @param $accid [查询用户对应的accid.] * @param $begintime [最先时间,ms] * @param $endtime [停止时间,ms] * @param $limit [本次查询的新闻条数上限(最多100条),小于即是0,或者大于100,会提醒参数错误] * @param $reverse [1准时间正序排列,2准时间降序排列。其它返回参数414.默认是按降序排列。] * @return $result [返回array数组工具] */ public function queryGroupMsg($tid,$accid,$begintime,$endtime='',$limit='100',$reverse='1'){ $url = 'https://api.netease.im/nimserver/history/queryTeamMsg.action'; $data= array( 'tid' => $tid, 'accid' => $accid, 'begintime' => $begintime, 'endtime' => $endtime, 'limit' => $limit, 'reverse' => $reverse ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 发送短信验证码 * @param $mobile [目的手机号] * @param $deviceId [目的装备号,可选参数] * @return $result [返回array数组工具] */ public function sendSmsCode($mobile,$deviceId=''){ $url = 'https://api.netease.im/sms/sendcode.action'; $data= array( 'mobile' => $mobile, 'deviceId' => $deviceId ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 校验验证码 * @param $mobile [目的手机号] * @param $code [验证码] * @return $result [返回array数组工具] */ public function verifycode($mobile,$code=''){ $url = 'https://api.netease.im/sms/verifycode.action'; $data= array( 'mobile' => $mobile, 'code' => $code ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 发送模板短信 * @param $templateid [模板编号(由客服设置之后见告开发者)] * @param $mobiles [验证码] * @param $params [短信参数列表,用于依次填充模板,JSONArray花样,如["xxx","yyy"];对于不包罗变量的模板,不填此参数示意模板即短信全文内容] * @return $result [返回array数组工具] */ public function sendSMSTemplate($templateid,$mobiles=array(),$params=array()){ $url = 'https://api.netease.im/sms/sendtemplate.action'; $data= array( 'templateid' => $templateid, 'mobiles' => json_encode($mobiles), 'params' => json_encode($params) ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 查询模板短信发送状态 * @param $sendid [发送短信的编号sendid] * @return $result [返回array数组工具] */ public function querySMSStatus($sendid){ $url = 'https://api.netease.im/sms/querystatus.action'; $data= array( 'sendid' => $sendid ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 提议单人专线电话 * @param $callerAcc [提议本次请求的用户的accid] * @param $caller [主叫方电话号码(不带+86这类国家码,下同)] * @param $callee [被叫方电话号码] * @param $maxDur [本通电话最大可连续时长,单元秒,跨越该时长时通话会自动切断] * @return $result [返回array数组工具] */ public function startcall($callerAcc,$caller,$callee,$maxDur='60'){ $url = 'https://api.netease.im/call/ecp/startcall.action'; $data= array( 'callerAcc' => $callerAcc, 'caller' => $caller, 'callee' => $callee, 'maxDur' => $maxDur ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 提议专线集会电话 * @param $callerAcc [提议本次请求的用户的accid] * @param $caller [主叫方电话号码(不带+86这类国家码,下同)] * @param $callee [所有被叫方电话号码,必须是json花样的字符串,如["13588888888","13699999999"]] * @param $maxDur [本通电话最大可连续时长,单元秒,跨越该时长时通话会自动切断] * @return $result [返回array数组工具] */ public function startconf($callerAcc,$caller,$callee,$maxDur='60'){ $url = 'https://api.netease.im/call/ecp/startconf.action'; $data= array( 'callerAcc' => $callerAcc, 'caller' => $caller, 'callee' => json_encode($callee), 'maxDur' => $maxDur ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 查询单通专线电话或集会的详情 * @param $session [本次通话的id号] * @param $type [通话类型,1:专线电话;2:专线集会] * @return $result [返回array数组工具] */ public function queryCallsBySession($session,$type){ $url = 'https://api.netease.im/call/ecp/queryBySession.action'; $data= array( 'session' => $session, 'type' => $type ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /* 2016-06-15 新增php挪用直播接口示例 */ /** * 获取语音视频平安认证署名 * @param $uid [用户帐号唯一标识,必须是Long型] */ public function getUserSignature($uid){ $url = 'https://api.netease.im/nimserver/user/getToken.action'; $data= array( 'uid' => $uid ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 确立一个直播频道 * @param $name [频道名称, string] * @param $type [频道类型(0:rtmp;1:hls;2:http)] */ public function channelCreate($name,$type){ $url = 'https://vcloud.163.com/app/channel/create'; $data= array( 'name' => $name, 'type' => $type ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } /** * 修改直播频道信息 * @param $name [频道名称, string] * @param $cid [频道ID,32位字符串] * @param $type [频道类型(0:rtmp;1:hls;2:http)] */ public function channelUpdate($name, $cid, $type){ $url = 'https://vcloud.163.com/app/channel/update'; $data= array( 'name' => $name, 'cid' => $cid, 'type' => $type ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } /** * 删除一个直播频道 * @param $cid [频道ID,32位字符串] */ public function channelDelete($cid){ $url = 'https://vcloud.163.com/app/channel/delete'; $data= array( 'cid' => $cid ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } /** * 获取一个直播频道的信息 * @param $cid [频道ID,32位字符串] */ public function channelStats($cid){ $url = 'https://vcloud.163.com/app/channelstats'; $data= array( 'cid' => $cid ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } /** * 获取用户直播频道列表 * @param $records [单页纪录数,默认值为10] * @param $pnum = 1 [要取第几页,默认值为1] * @param $ofield [排序的域,支持的排序域为:ctime(默认)] * @param $sort [升序照样降序,1升序,0降序,默以为desc] */ public function channelList($records = 10, $pnum = 1, $ofield = 'ctime', $sort = 0){ $url = 'https://vcloud.163.com/app/channellist'; $data= array( 'records' => $records, 'pnum' => $pnum, 'ofield' => $ofield, 'sort' => $sort ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } /** * 重新获取推流地址 * @param $cid [频道ID,32位字符串] */ public function channelRefreshAddr($cid){ $url = 'https://vcloud.163.com/app/address'; $data= array( 'cid' => $cid ); if($this->RequestType=='curl'){ $result = $this->postJsonDataCurl($url,$data); }else{ $result = $this->postJsonDataFsockopen($url,$data); } return $result; } // 2015-07-04 谈天室功效开发 gm /** * 确立谈天室 * @param $accid 谈天室属主的账号accid * @param $name 谈天室名称,长度限制128个字符 */ public function chatroomCreates($accid,$name){ $url = 'https://api.netease.im/nimserver/chatroom/create.action'; $data = array( 'creator'=>$accid, 'name'=>$name ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 更新谈天室 * @param $roomid 谈天室ID * @param $name 谈天室名称 * @return array */ public function chatroomUpdates($roomid,$name){ $url = 'https://api.netease.im/nimserver/chatroom/update.action'; $data = array( 'roomid'=>$roomid, 'name'=>$name ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** * 修改谈天室开启或关闭谈天室 * @param $roomid 谈天室ID * @param $operator 确立者ID * @param string $status 修改照样关闭 false => 关闭 */ public function chatroomToggleCloses($roomid,$operator) { $url = 'https://api.netease.im/nimserver/chatroom/toggleCloseStat.action'; $data = array( 'roomid'=>$roomid, 'operator'=>$operator, 'valid'=>'false' ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } public function chatroomToggleStats($roomid,$operator) { $url = 'https://api.netease.im/nimserver/chatroom/toggleCloseStat.action'; $data = array( 'roomid'=>$roomid, 'operator'=>$operator, 'valid'=>'true' ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } /** *设置谈天室内用户角色 * @param $roomid // 谈天室ID * @param $operator // 操作者账号accid operator必须是确立者 * @param $target // 被操作者账号accid * @param $opt * 1: 设置为治理员,operator必须是确立者 2:设置通俗品级用户,operator必须是确立者或治理员 -1:设为黑名单用户,operator必须是确立者或治理员 -2:设为禁言用户,operator必须是确立者或治理员 * @param string $optvalue // true:设置;false:作废设置 */ public function chatroomSetMemberRoles($roomid,$operator,$target,$opt,$optvalue) { $url = 'https://api.netease.im/nimserver/chatroom/setMemberRole.action'; $data = array( 'roomid'=>$roomid, 'operator'=>$operator, 'target'=>$target, 'opt'=>$opt, 'optvalue'=>$optvalue, ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } // 获取谈天室的信息 public function chatroomgets($roomid) { $url = 'https://api.netease.im/nimserver/chatroom/get.action'; $data = array( 'roomid'=>$roomid, 'needOnlineUserCount'=>'true' ); if($this->RequestType=='curl'){ $result = $this->postDataCurl($url,$data); }else{ $result = $this->postDataFsockopen($url,$data); } return $result; } }


2.控制器代码

<?php 
/** 
 * Created by PhpStorm. 
 * User: www.genban.org 
 */ 
namespace Api\Controller; 
use Think\Controller; 
 
class YunxinController extends Controller{ 
 
    private $model; 
    private $AppKey = '';     // key 
    private $AppSecret = '';  // secret 
 
    public function _initialize(){ 
        // 实例云信的库 
        $this->model = new \Org\Util\YunxinServer($this->AppKey,$this->AppSecret,'curl'); 
    } 
 
    /** 
     * 确立云信ID 
     *  
    */ 
    public function createUserId($userid) 
    { 
        $data = M('user')->field('id accid,username,nickname name,headimgurl icon')->where('is_del = 0 AND id='.$userid)->find(); 
        $token = md5($data['accid'].'abc'); 
        // 写入到云信服务器 
        $accid = 'abc'.$data['accid']; 
        $name = $data['name']; 
        $icon = $data['icon']; 
        $info = $this->model->createUserIds($accid,$name,'{}',$icon,$token); 
        return $info; 
    } 
 
    public function updateUinfos($accid,$name,$icon,$sign,$email,$birth,$mobile,$gender,$ex){ 
        $info = $this->model->updateUinfo($accid,$name,$icon,$sign,$email,$birth,$mobile,$gender,$ex); 
        return $info; 
    } 
 
    // 获取指定用户的云信ID 
    public function getUinfos(){ 
        $accid = I('request.id'); 
        $accid = array($accid); 
        $info = $this->model->getUinfoss($accid); 
        print_r($info); 
        return $info; 
    } 
 
    // 确立谈天室 
    /** 
     * @param $accid 谈天室的ID 
     * @param $name  谈天室的名称 
     */ 
    public function chatroomCreate($accid,$name){ 
        $info = $this->model->chatroomCreates($accid,$name); 
        return $info; 
    } 
 
    // 查询谈天室 
    public function chatroomget(){ 
        $roomid = I('request.id'); 
        $info = $this->model->chatroomgets($roomid); 
        print_r($info); 
        return $info; 
    } 
 
    /** 
     * 更新谈天室 
     * @param $roomid  谈天室ID 
     * @param $name    谈天室名称 
     * @return array 
     */ 
    public function chatroomUpdate($roomid,$name){ 
        $info = $this->model->chatroomUpdates($roomid,$name); 
        return $info; 
    } 
 
    /** 
     * 修改谈天室开启或关闭谈天室 
     * @param $roomid        谈天室ID 
     * @param $operator      确立者ID 
     * @param string $status 修改照样关闭  false => 修改 
     */ 
    public function chatroomToggleClose($roomid,$operator){ 
        $info = $this->model->chatroomToggleCloses($roomid,$operator); 
        return $info; 
    } 
 
    public function chatroomToggleStat($roomid,$operator){ 
        $info = $this->model->chatroomToggleStats($roomid,$operator); 
        return $info; 
    } 
 
    /** 
     *设置谈天室内用户角色 
     * @param $roomid            // 谈天室ID 
     * @param $operator          // 操作者账号accid   operator必须是确立者 
     * @param $target            // 被操作者账号accid 
     * @param $opt 
     *      1: 设置为治理员,operator必须是确立者 
            2:设置通俗品级用户,operator必须是确立者或治理员 
            -1:设为黑名单用户,operator必须是确立者或治理员 
            -2:设为禁言用户,operator必须是确立者或治理员 
     * @param string $optvalue   // true:设置;false:作废设置 
     */ 
    public function chatroomSetMemberRole($roomid,$operator,$target,$opt,$optvalue){ 
        $info = $this->model->chatroomSetMemberRoles($roomid,$operator,$target,$opt,$optvalue); 
        return $info; 
    } 
 
    /** 
     * 云信新闻抄送接口 
     */ 
    public function receiveMsg() 
    { 
        $body = @file_get_contents('php://input'); 
        $data = json_decode($body,true); 
        //file_put_contents('/data/server/work_justeasy_cn/debug.txt',$body); 
        if($data){ 
            $d['eventType']       = $data['eventType']; 
            $d['attach']          = $data['attach']; 
            $d['ext']             = $data['ext']; 
            $d['fromAccount']     = $data['fromAccount']; 
            $d['fromAvator']      = $data['fromAvator']; 
            $d['fromClientType']  = $data['fromClientType']; 
            $d['fromExt']         = $data['fromExt']; 
            $d['fromNick']        = $data['fromNick']; 
            $d['msgTimestamp']    = $data['msgTimestamp']; 
            $d['msgType']         = $data['msgType']; 
            $d['msgidClient']     = $data['msgidClient']; 
            $d['resendFlag']      = $data['resendFlag']; 
            $d['roleInfoTimetag'] = $data['roleInfoTimetag']; 
            $d['roomId']          = $data['roomId']; 
            $d['antispam']        = $data['antispam']; 
            $info = M('receivemsg')->add($d); 
            if($info){ 
                echo 200; 
            } 
        }else{ 
            echo 500; 
        } 
    } 
 
 
} 


linux 查看磁盘空间大小的命令和方法

1.Ubuntu 查看磁盘空间大小命令 df -h Df命令是linux系统以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息, 命令格式: df -hl 显示格式为: 文件系统 容

转载请说明出处内容投诉
八爷源码网 » Thinkphp连系网易云IM代码类分享