首页
友人帐
留言板
关于
Search
1
IDE Eval Resetter:JetBrains 全家桶无限试用插件
383 阅读
2
影视资源采集站收录大全
309 阅读
3
linux安装或升级protoc
226 阅读
4
VFM 3.7.5 源码 - 一个极简的 PHP 私人云盘!
163 阅读
5
批量采集美女写真等图片做图片站
150 阅读
谈天说地
程序源码
技术教程
成品源码
登录
Search
标签搜索
PHP
linux
源码
go
windows
centos
原创
mysql
微信
激活
采集
宝塔
绿色版
API
解析
SDK
图片
破解
域名
html
云青
累计撰写
150
篇文章
累计收到
82
条评论
首页
栏目
谈天说地
程序源码
技术教程
成品源码
页面
友人帐
留言板
关于
搜索到
1
篇与
的结果
2019-04-03
分享一个PHP环信服务端操作类
之前做直播系统,需要用到通信这一块,由于官方文档没有sdk,博主本人也是google的,顺便修改了一下 <?php namespace hx; class Hx { private $app_key = '1106196338107043#bfzb'; private $client_id = 'YXA68gwqIDr4Eem08DO8sr_xCA'; private $client_secret = 'YXA57if_NzYCtL_96DktWsvILrlcU24'; private $url = "https://a1.easemob.com/1106190228107043/bfzb"; /* * 获取APP管理员Token */ public function __construct() { $url = $this->url . "/token"; $data = array( 'grant_type' => 'client_credentials', 'client_id' => $this->client_id, 'client_secret' => $this->client_secret ); $rs = json_decode($this->curl($url, $data), true); $this->token = $rs['access_token']; } /* * 注册IM用户(授权注册) */ public function hx_register($username, $password, $nickname) { $url = $this->url . "/users"; $data = array( 'username' => $username, 'password' => $password, 'nickname' => $nickname ); $header = array( 'Content-Type: application/json', 'Authorization: Bearer ' . $this->token ); return $this->curl($url, $data, $header, "POST"); } /* * 给IM用户的添加好友 */ public function hx_contacts($owner_username, $friend_username) { $url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "POST"); } /* * 解除IM用户的好友关系 */ public function hx_contacts_delete($owner_username, $friend_username) { $url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "DELETE"); } /* * 查看好友 */ public function hx_contacts_user($owner_username) { $url = $this->url . "/users/${owner_username}/contacts/users"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "GET"); } /* 发送文本消息 */ public function hx_send($sender, $receiver, $msg) { $url = $this->url . "/messages"; $header = array( 'Authorization: Bearer ' . $this->token ); $data = array( 'target_type' => 'users', 'target' => array( '0' => $receiver ), 'msg' => array( 'type' => "txt", 'msg' => $msg ), 'from' => $sender, 'ext' => array( 'attr1' => 'v1', 'attr2' => "v2" ) ); return $this->curl($url, $data, $header, "POST"); } /* 查询离线消息数 获取一个IM用户的离线消息数 */ public function hx_msg_count($owner_username) { $url = $this->url . "/users/${owner_username}/offline_msg_count"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "GET"); } /* * 获取IM用户[单个] */ public function hx_user_info($username) { $url = $this->url . "/users/${username}"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "GET"); } /* * 获取IM用户[批量] */ public function hx_user_infos($limit) { $url = $this->url . "/users?${limit}"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "GET"); } /* * 重置IM用户密码 */ public function hx_user_update_password($username, $newpassword) { $url = $this->url . "/users/${username}/password"; $header = array( 'Authorization: Bearer ' . $this->token ); $data['newpassword'] = $newpassword; return $this->curl($url, $data, $header, "PUT"); } /* * 删除IM用户[单个] */ public function hx_user_delete($username) { $url = $this->url . "/users/${username}"; $header = array( 'Authorization: Bearer ' . $this->token ); return $this->curl($url, "", $header, "DELETE"); } /* * 修改用户昵称 */ public function hx_user_update_nickname($username, $nickname) { $url = $this->url . "/users/${username}"; $header = array( 'Authorization: Bearer ' . $this->token ); $data['nickname'] = $nickname; return $this->curl($url, $data, $header, "PUT"); } /* * * 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 $ret; } } $rs = new Hx(); // 注册的用户 echo $rs->hx_register('qwerasd', 'qazwsx', '福州123'); // 给IM用户的添加好友 // echo $rs->hx_contacts('admin888', 'qwerasd'); /* 发送文本消息 */ // echo $rs->hx_send('213123','admin888','dfadsr214wefaedf'); /* 消息数统计 */ // echo $rs->hx_msg_count('admin888'); /* 获取IM用户[单个] */ // echo $rs->hx_user_info('admin888'); /* 获取IM用户[批量] */ // echo $rs->hx_user_infos('20'); /* 删除IM用户[单个] */ // echo $rs->hx_user_delete('wwwwww'); /* 修改用户昵称 */ // echo $rs->hx_user_update_nickname('asaxcfasdd','网络科技'); /* 重置IM用户密码 */ // echo $rs->hx_user_update_password('asaxcfasdd','asdad'); /* 解除IM用户的好友关系 */ // echo $rs->hx_contacts_delete('admin888', 'qqqqqqqq'); /* 查看好友 */ //echo $rs->hx_contacts_user('admin888');
2019年04月03日
15 阅读
2 评论
0 点赞