你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
lizg - ……
zhidong10
南城以北花似海、 - 95后IT男
要回复问题请先登录或注册
4 个回复
lizg - ……
zhidong10
获取用户token
private $app_key = 'xxxxx#ddddd';
private $client_id = 'ccccccccc';
private $client_secret = 'dddddddddd';
private $url = "https://a1.easemob.com/xiaoyaosheng/webiminset";
private $token='';
private $header=array();
/*
* 获取APP管理员Token
*/
public function __construct(){
//设置缓存
$cache_temp_file='./cache.json';
if(!file_exists($cache_temp_file)){
touch($cache_temp_file);
}
$this->token=file_get_contents($cache_temp_file);
$time=filemtime($cache_temp_file)+(3600*24);
//判断文件是否超时(缓存24小时)
if( $time < time() || $this->token==''){
$url = $this->url . "/token";
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret
);
$rs=$this->curl($url, $data);
$this->token = $rs['access_token'];
file_put_contents($cache_temp_file,$this->token);
}
//请求头
$this->header = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $this->token
);
}
//通过用户名密码获取用户token
public function getUserToken($username, $password){
$url = $this->url . "/token";
$data = array(
'grant_type' => 'password',
'username' => $username,
'password' => $password
);
return $this->curl($url, $data, array($this->header[0]), "POST");
}
/*
*
* curl请求
*/
private function curl($url, $data, $header = false, $method = "POST"){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if ($data) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$ret = curl_exec($ch);
return json_decode($ret,true);
}
}
lizg - ……
南城以北花似海、 - 95后IT男
at error (websdk-1.4.11.js:10421)
at XMLHttpRequest.xhr.onreadystatechange (websdk-1.4.11.js:2403)
error @ websdk-1.4.11.js:10421
xhr.onreadystatechange @ websdk-1.4.11.js:2403
XMLHttpRequest.send (async)
ajax @ websdk-1.4.11.js:2462
connection.login @ websdk-1.4.11.js:10446
connection.open @ websdk-1.4.11.js:10368
(anonymous) @ index.html:129
j @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
I @ jquery.min.js:2
websdk-1.4.11.js:2462 POST http://a1.easemob.com/1195180614228952/zkyy/users 400 (Bad Request)
自动注册可以的 跪谢各位大佬