API请求:检索私信、网站通知和群组通知的未读计数

请求URL
https://yourwebsiteaddress/api_request/

请求包体

字段 描述/值 必填/可选
api_secret_key 您的 MeiChat API 密钥。对于 API 秘密密钥,点击菜单>选择设置 > 选择“通用设置” > 查找 API 密钥 必填
realtime true 必填
user 用户账户的用户名/邮箱地址 必填

响应包体

描述/值
success 成功时会回应此理,失败时则为false。
error_message 返回相关的错误信息
error_key 该方法返回与错误相关的错误键

PHP 代码示例

<?php

$meichat_web_address = 'https://yourwebsiteaddress'; 

$post_fields=[
  'api_secret_key' => 'Your_MeiChat_API_Secret_Key',
  'realtime' => true,
  'user' => 'username/email_address'
];

$api_request_url = rtrim($meichat_web_address, '/').'/'.'api_request/';

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => $api_request_url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $post_fields,
  CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0'
));

$response = curl_exec($curl);

curl_close($curl);

if (!empty($response)) {
    $response = json_decode($response);
    if (!empty($response)) {
        if (isset($response->unread_private_chat_messages)) {
            echo 'Unread Private Chat Messages : '.$response->unread_private_chat_messages;
        }
        
        if (isset($response->unread_group_messages)) {
            echo 'Unread Group Chat Messages : '.$response->unread_group_messages;
        }
        
        if (isset($response->unread_site_notifications)) {
            echo 'Unread Site Notifications : '.$response->unread_site_notifications;
        }
        
        if (isset($response->unresolved_complaints)) {
            echo 'Unsolved Complaints : '.$response->unresolved_complaints;
        }
        
        if (isset($response->pending_friend_requests)) {
            echo 'Pending Friend Requests : '.$response->pending_friend_requests;
        }
    }
}
?>