注册客户互动云账号:创建手机app
环信开发者中心:
APPKey的#号前是org_name,#号后是app_name
其中 文档地址:http://api-docs.easemob.com/#/
获得token:
protected $url = 'http://a1-vip5.easemob.com/1401180313068864/kefuchannelapp53097/token/';
/**
* 获取token
* org_name 企业管理员名称
* app_name 应用程序名称
*/
public function token(){
$data = array(
'grant_type'=>'client_credentials',
'client_id'=>'YXA66T3owCaDEeiPP_ELVHkzpg',
'client_secret'=>'YXA6njmAdGB_qtqaY-9rDpdWuCYVxgg',
);
$rs = $this->curlHttpPostJsonRequest($data);
$this->res_data['data'] = $rs;
$this->apiReply();
}
/**
* curl 模拟http请求
* @param $data
* @return mixed
*/
public function curlHttpPostJsonRequest($data){
$crl = curl_init();
$data = json_encode($data);
curl_setopt($crl, CURLOPT_URL, $this->url);
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$output = curl_exec($crl);
curl_close($crl);
return json_decode($output);
}
用户注册:
protected $url = 'http://a1-vip5.easemob.com/1401180313068864/kefuchannelapp53097/users';
/**
* 注册用户
* org_name
* app_name
* users [{'username':'string','password':'string'}]
*/
public function register(){
$data = array(
'username'=>'heiye5201',
'password'=>'123456',
);
$rs = $this->curlHttpPostJsonRequest($data);
$this->res_data['data'] = $rs;
$this->apiReply();
}
/**
* curl 模拟http请求
* @param $data
* @return mixed
*/
public function curlHttpPostJsonRequest($data){
$crl = curl_init();
$data = json_encode($data);
curl_setopt($crl, CURLOPT_URL, $this->url);
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$output = curl_exec($crl);
curl_close($crl);
return json_decode($output);
}