search
Homephp教程php手册环信即时通讯

环信即时通讯
地址: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元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.