环信即时通讯
地址:http://www.easemob.com/ 可以做一个聊天系统
根据接口文档 我整理了下!分享出来<?php <br />
<br>
class Hxcall<br>
{<br>
<br>
<br>
private $app_key = 'qqqqqq#aaaaaa';<br>
<br>
private $client_id = 'sdasdasdasd';<br>
<br>
private $client_secret = 'sdsdsdsdsd';<br>
<br>
private $url = "https://a1.easemob.com/qqqqqq/aaaaaa";<br>
/*<br>
* 获取APP管理员Token<br>
*/<br>
function __construct()<br>
{<br>
$url = $this->url . "/token";<br>
$data = array(<br>
'grant_type' => 'client_credentials',<br>
'client_id' => $this->client_id,<br>
'client_secret' => $this->client_secret<br>
);<br>
$rs = json_decode($this->curl($url, $data), true);<br>
$this->token = $rs['access_token'];<br>
}<br>
/*<br>
* 注册IM用户(授权注册)<br>
*/<br>
public function hx_register($username, $password, $nickname)<br>
{<br>
$url = $this->url . "/users";<br>
$data = array(<br>
'username' => $username,<br>
'password' => $password,<br>
'nickname' => $nickname<br>
);<br>
$header = array(<br>
'Content-Type: application/json',<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, $data, $header, "POST");<br>
}<br>
/*<br>
* 给IM用户的添加好友<br>
*/<br>
public function hx_contacts($owner_username, $friend_username)<br>
{<br>
$url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "POST");<br>
}<br>
/*<br>
* 解除IM用户的好友关系<br>
*/<br>
public function hx_contacts_delete($owner_username, $friend_username)<br>
{<br>
$url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "DELETE");<br>
}<br>
/*<br>
* 查看好友<br>
*/<br>
public function hx_contacts_user($owner_username)<br>
{<br>
$url = $this->url . "/users/${owner_username}/contacts/users";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "GET");<br>
}<br>
<br>
/* 发送文本消息 */<br>
public function hx_send($sender, $receiver, $msg)<br>
{<br>
$url = $this->url . "/messages";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
$data = array(<br>
'target_type' => 'users',<br>
'target' => array(<br>
'0' => $receiver<br>
),<br>
'msg' => array(<br>
'type' => "txt",<br>
'msg' => $msg<br>
),<br>
'from' => $sender,<br>
'ext' => array(<br>
'attr1' => 'v1',<br>
'attr2' => "v2"<br>
)<br>
);<br>
return $this->curl($url, $data, $header, "POST");<br>
}<br>
/* 查询离线消息数 获取一个IM用户的离线消息数 */<br>
public function hx_msg_count($owner_username)<br>
{<br>
$url = $this->url . "/users/${owner_username}/offline_msg_count";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "GET");<br>
}<br>
<br>
/*<br>
* 获取IM用户[单个]<br>
*/<br>
public function hx_user_info($username)<br>
{<br>
$url = $this->url . "/users/${username}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "GET");<br>
}<br>
/*<br>
* 获取IM用户[批量]<br>
*/<br>
public function hx_user_infos($limit)<br>
{<br>
$url = $this->url . "/users?${limit}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "GET");<br>
}<br>
/*<br>
* 重置IM用户密码<br>
*/<br>
public function hx_user_update_password($username, $newpassword)<br>
{<br>
$url = $this->url . "/users/${username}/password";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
$data['newpassword'] = $newpassword;<br>
return $this->curl($url, $data, $header, "PUT");<br>
}<br>
<br>
/*<br>
* 删除IM用户[单个]<br>
*/<br>
public function hx_user_delete($username)<br>
{<br>
$url = $this->url . "/users/${username}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
return $this->curl($url, "", $header, "DELETE");<br>
}<br>
/*<br>
* 修改用户昵称<br>
*/<br>
public function hx_user_update_nickname($username, $nickname)<br>
{<br>
$url = $this->url . "/users/${username}";<br>
$header = array(<br>
'Authorization: Bearer ' . $this->token<br>
);<br>
$data['nickname'] = $nickname;<br>
return $this->curl($url, $data, $header, "PUT");<br>
}<br>
/*<br>
*<br>
* curl<br>
*/<br>
private function curl($url, $data, $header = false, $method = "POST")<br>
{<br>
$ch = curl_init($url);<br>
curl_setopt($ch, CURLOPT_URL, $url);<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br>
if ($header) {<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br>
}<br>
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);<br>
if ($data) {<br>
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));<br>
}<br>
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<br>
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);<br>
$ret = curl_exec($ch);<br>
return $ret;<br>
}<br>
}<br>
<br>
$rs = new Hxcall();<br>
// 注册的用户<br>
//echo $rs->hx_register('qwerasd', 'qazwsx', '福州123' );<br>
// 给IM用户的添加好友<br>
// echo $rs->hx_contacts('admin888', 'qwerasd');<br>
/* 发送文本消息 */<br>
// echo $rs->hx_send('213123','admin888','dfadsr214wefaedf');<br>
/* 消息数统计 */<br>
// echo $rs->hx_msg_count('admin888');<br>
/* 获取IM用户[单个] */<br>
// echo $rs->hx_user_info('admin888');<br>
/* 获取IM用户[批量] */<br>
echo $rs->hx_user_infos('20');<br>
/* 删除IM用户[单个] */<br>
// echo $rs->hx_user_delete('wwwwww');<br>
/* 修改用户昵称 */<br>
// echo $rs->hx_user_update_nickname('asaxcfasdd','网络科技');<br>
/* 重置IM用户密码 */<br>
// echo $rs->hx_user_update_password('asaxcfasdd','asdad');<br>
/* 解除IM用户的好友关系 */<br>
// echo $rs->hx_contacts_delete('admin888', 'qqqqqqqq');<br>
/* 查看好友 */<br>
//echo $rs->hx_contacts_user('admin888');
AD:真正免费,域名+虚机+企业邮箱=0元