• 环信即时通讯——集成客户端


    最近公司在开发一款 APP,需要使用环信即时通讯来做及时聊天和直播,找了好多官方的 REST API 发现并没有把直播集成服务写完,于是自己完善了一下,与大家分享 O (∩_∩) O
    话不多说上代码

    namespace yournamespace
    
    class Easemob{ private $client_id; private $client_secret; private $org_name; private $app_name; private $url; //------------------------------------------------------用户体系 /** * 初始化参数 * * @param array $options * @param $options['client_id'] * @param $options['client_secret'] * @param $options['org_name'] * @param $options['app_name'] */ public function __construct($options) { $this->client_id = 'XXXXXXXXXXXXXX'; $this->client_secret = 'XXXXXXXXXXXXXX'; $this->org_name = 'XXXXXXXXXXXXXX'; $this->app_name = 'XXXXXXXXXXXXXX'; if (! empty ( $this->org_name ) && ! empty ( $this->app_name )) { $this->url = 'https://a1.easemob.com/' . $this->org_name . '/' . $this->app_name . '/'; } } /** *获取token */ function getToken() { $options=array( "grant_type"=>"client_credentials", "client_id"=>$this->client_id, "client_secret"=>$this->client_secret ); //json_encode()函数,可将PHP数组或对象转成json字符串,使用json_decode()函数,可以将json字符串转换为PHP数组或对象 $body=json_encode($options); //使用 $GLOBALS 替代 global $url=$this->url.'token'; //$url=$base_url.'token'; $tokenResult = $this->postCurl($url,$body,$header=array()); //var_dump($tokenResult['expires_in']); //return $tokenResult; return "Authorization:Bearer ".$tokenResult['access_token']; } /** 授权注册 */ function createUser($username,$password){ $url=$this->url.'users'; $options=array( "username"=>$username, "password"=>$password ); $body=json_encode($options); $header=array($this->getToken()); $result=$this->postCurl($url,$body,
  • 相关阅读:
    Python基础检测:20171105
    Python中斐波那契数列的四种写法
    Python中斐波那契数列的四种写法
    学习Python3:20171031
    学习Python3:20171031
    9.3 Trains and Evaluates the MNIST network using a feed dictionary
    9.3 Trains and Evaluates the MNIST network using a feed dictionary
    学习Python3:201701030
    学习Python3:201701030
    周末微光
  • 原文地址:https://www.cnblogs.com/lxwphp/p/15453382.html
Copyright © 2020-2023  润新知