API请求添加用户设备播放器ID或订阅者ID以发送推送通知

请求URL
https://yourwebsiteaddress/api_request/

请求包体

字段 描述/值 必填/可选
api_secret_key 您的 MeiChat API 密钥。对于 API 秘密密钥,点击菜单>选择设置 > 选择“通用设置” > 查找 API 密钥 必填
add push_subscriber 必填
user 用户名/电子邮件地址 必填
device_token Onesignal 玩家 ID 或 WebPushr 订阅者 ID 必填

响应包体

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

PHP 代码示例

<?php

$meichat_web_address = 'https://yourwebsiteaddress'; 

$post_fields=[
  'api_secret_key' => 'Your_MeiChat_API_Secret_Key',
  'add' => 'push_subscriber',
  'user' => 'username/email_address',
  'device_token' => 'PlayerID/SID', 
];

$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->error_message)) {
            echo $response->error_message;
        } else {
            echo "Device Added Successfully";
        }
    }
}
?>