日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 环信easyui_环信即时通讯---php版

發布時間:2024/3/24 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 环信easyui_环信即时通讯---php版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 <?php2 /**3 * 環信IM4 * Created by PhpStorm.5 * User: chao6 * Date: 2020/12/97 * Time: 4:34 PM8 */

910

11 classHxChat{12 private $app_key = '123456#abcd';

13 private $client_id = 'hhkhkkkhh';14 private $client_secret = 'uiuriwrinncj';15 private $url = "https://a1.easemob.com/123456/abcd"; //要與$app_key值保持一致

16

17 /*

18 * 獲取APP管理員Token19 */

20 function__construct()21 {22 $url = $this->url . "/token";23 $data = array(24 'grant_type' => 'client_credentials',

25 'client_id' => $this->client_id,

26 'client_secret' => $this->client_secret27 );28 $rs = json_decode($this->curl($url, $data), true);29 $this->token = $rs['access_token'];30 }31

32 /**33 * 注冊單個用戶(開放)34 * @param $username35 * @param $password36 * @param string $nickname37 */

38 public function hx_open_register($username, $password, $nickname='')39 {40 $url = $this->url . "/users";41 $data = array(42 'username'=>$username,

43 'password'=>$password,

44 'nickname'=>$nickname,

45 );46 $header = array(47 'Content-Type: application/json',

48 );49

50 return $this->curl($url, $data, $header, 'POST');51 }52

53 /**54 * 注冊單個用戶(授權)55 * @param $username56 * @param $password57 * @param string $nickname58 */

59 public function hx_auth_register($username, $password, $nickname='')60 {61 $url = $this->url . "/users";62 $data = array(63 'username'=>$username,

64 'password'=>$password,

65 'nickname'=>$nickname,

66 );67 $header = array(68 'Content-Type: application/json',

69 'Authorization: Bearer '.$this->token,

70 );71 return $this->curl($url, $data, $header, 'POST');72

73 }74

75 /**76 * 添加好友77 * @param $owner_username 要添加好友的用戶名78 * @param $friend_username 好友用戶名79 * @return mixed80 */

81 public function hx_add_friend($owner_username, $friend_username)82 {83 $url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}";84 $header = array(85 'Content-Type: application/json',

86 'Authorization: Bearer '.$this->token,

87 );88

89 return $this->curl($url, '' , $header, 'POST');90 }91

92 /**93 * 移除好友94 * @param $owner_username95 * @param $friend_username96 * @return mixed97 */

98 public function hx_contacts_delete($owner_username, $friend_username)99 {100 $url = $this->url . "/users/${owner_username}/contacts/users/${friend_username}";101 $header = array(102 'Authorization: Bearer ' . $this->token103 );104 return $this->curl($url, "", $header, "DELETE");105 }106

107 /**108 * 獲取好友列表109 * @param $owner_username110 * @return mixed111 */

112 public function hx_contacts_user($owner_username)113 {114 $url = $this->url . "/users/${owner_username}/contacts/users";115 $header = array(116 'Authorization: Bearer ' . $this->token117 );118 return $this->curl($url, "", $header, "GET");119 }120

121 /**122 * 發送文本消息123 * @param $sender 發送者124 * @param $receiver 接收者125 * @param $msg 消息126 * @return mixed127 */

128 public function hx_send_txt_msg($sender, $receiver, $msg)129 {130 $url = $this->url . "/messages";131 $header = array(132 'Authorization: Bearer ' . $this->token,

133 'Content-Type: application/json'

134 );135 $data = array(136 'target_type'=> 'users',

137 'target'=>[$receiver],

138 'msg'=>['msg'=>$msg, 'type'=>'txt'],

139 'from'=>$sender,

140 );141 return $this->curl($url, $data, $header, "POST");142 }143

144 /**145 * curl146 * @param $url147 * @param $data148 * @param bool $header149 * @param string $method150 * @return mixed151 */

152 private function curl($url, $data, $header = false, $method = "POST")153 {154 $ch = curl_init($url);155 curl_setopt($ch, CURLOPT_URL, $url);156 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);157 if ($header) {158 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);159 }160 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);161 if ($data) {162 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));163 }164 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);165 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);166 $ret = curl_exec($ch);167 return $ret;168 }169 }

總結

以上是生活随笔為你收集整理的php 环信easyui_环信即时通讯---php版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。