向组发送消息的API请求

请求URL
https://yourwebsiteaddress/api_request/

请求包体

字段 描述/值 必填/可选
api_secret_key 您的 MeiChat API 密钥。对于 API 秘密密钥,点击菜单>选择设置 > 选择“通用设置” > 查找 API 密钥 必填
add 信息 必填
group 群组 ID/群组别名 必填
sender 发件人用户名/邮箱地址 必填
message 信息内容 必填
file_attachments 文件附件 可选
gif_url GIF 图片网址 [tenor.com | gfycat.com | giphy.com] 可选

响应包体

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

PHP 代码示例

<?php

$meichat_web_address = 'https://yourwebsiteaddress'; 

$post_fields=[
  'api_secret_key' => 'Your_MeiChat_API_Secret_Key',
  'add' => 'message',
  'group' => 'Group ID/Group Slug',
  'sender' => 'username/email_address', 
  'message' => 'Message Content', 
  'file_attachments' => 'file_path',
  'gif_url' => '',
];

$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_USERAGENT=>'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0'
));

if (isset($post_fields['file_attachments']) && !empty($post_fields['file_attachments'])) {    
    $post_fields['file_attachments'] = new CURLFILE($post_fields['file_attachments']);
}

curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);

$response = curl_exec($curl);

curl_close($curl);

if (!empty($response)) {
    $response = json_decode($response);
    if (!empty($response)) {
        if (isset($response->error_message)) {
            echo $response->error_message;
        } else {
            echo "Message Sent Successfully";
        }
    }
}
?>