get_uncache_system_config(); // $this->websocket_api_address = $config['websocket_api_address']; // $this->websocket_api_key = $config['websocket_api_key']; // $this->uid = 99999999966; // $this->token = $token; $this->app_id = $config['agora_app_id']; $this->customer_key = $config['agora_app_key']; $this->customer_secret = $config['agora_app_secret']; // $this->app_certificate = $config['agora_app_certificate']; // $this->token = model('agora')->agora_rtm_token_info($this->uid); $this->credentials = $this->customer_key . ':' . $this->customer_secret; // dump($this->customer_key); // dump($this->customer_secret);die; $base64Credentials = base64_encode($this->credentials); $this->header_arr = [ // 'x-agora-uid: ' . $this->uid, // "x-agora-token: " . $this->token, 'Authorization: Basic ' . $base64Credentials, 'Content-Type: application/json' ]; } //发送消息给个人 // public function send_to_one($uid, $content) // { // $post_data = []; // // $post_data['action'] = 'send_to_one'; // // $post_data['key'] = $this->websocket_api_key; // if (is_array($content)) { // $post_data['content'] = json_encode($content); // } else { // $post_data['content'] = $content; // } // $post_data['uid'] = $uid; // $content = $this->curlPost($this->websocket_api_address, $post_data); // return $content; // } //发送消息给个人 public function send_to_one($uid, $content) { $post_data = []; // $post_data['action'] = 'send_to_one'; // $post_data['key'] = $this->websocket_api_key; if (is_array($content)) { // $post_data['content'] = json_encode($content); $post_data['content'] = $content; } else { $post_data['content'] = $content; } // $post_data['uid'] = $uid; // $content = $this->curlPost($this->websocket_api_address, $post_data); $this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/peer_messages'; $data['payload'] = json_encode($post_data); $data['destination'] = strval($uid); $data['enable_historical_messaging'] = false; $data = json_encode($data); $content = $this->curlPost($this->request_url, $data, $this->header_arr); return $content; } //发送消息到指定房间 public function send_to_group($rid, $content) { $post_data = []; // $post_data['action'] = 'send_to_group'; // $post_data['key'] = $this->websocket_api_key; // if (is_array($content)) { // $post_data['content'] = json_encode($content); // } else { // $post_data['content'] = $content; // } $post_data['content'] = $content; $post_data['hid'] = $rid; $data['channel_name'] = strval($rid); $data['payload'] = json_encode($post_data); $data['enable_historical_messaging'] = false; $data = json_encode($data); // $this->request_url = $this->base_url . $this->app_id . '/rtm/users/' . $this->uid . '/channel_messages'; // $this->request_url = $this->base_url; $this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/channel_messages'; // dump($data); $content = $this->curlPost($this->request_url, $data ,$this->header_arr); // dump($content);die; return $content; } //发送群体消息 public function send_to_all($content) { $post_data = []; // $post_data['action'] = 'send_to_group'; // $post_data['key'] = $this->websocket_api_key; // if (is_array($content)) { // $post_data['content'] = json_encode($content); // } else { // $post_data['content'] = $content; // } $post_data['content'] = $content; $data['channel_name'] = $this->channel_name; $data['payload'] = json_encode($post_data); $data['enable_historical_messaging'] = false; $data = json_encode($data); $this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/channel_messages'; // dump($this->request_url);die; $content = $this->curlPost($this->request_url, $data,$this->header_arr); // dump($content);die; return $content; } public function getallclients() { $post_data = []; $post_data['action'] = 'getallclients'; $post_data['key'] = $this->websocket_api_key; $content = $this->curlPost($this->websocket_api_address, $post_data); return $content; } //参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies // public function myCurl($url, $post_data = array(), $header = array(), $cookie = "") // { // // $url = 'http://paysystem.local.com/index/apip/cc'; // // dump($url); // curlPost($url) // } public function curlPost($url, $data = [], $header = []) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_TIMEOUT , 0); curl_setopt($curl, CURLOPT_MAXREDIRS , 10); curl_setopt($curl, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_POST, 1); if (!empty($data)) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } if (!empty($header)) { curl_setopt($curl, CURLOPT_HTTPHEADER, $header); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } }