您可以将 MeiChat 脚本集成到现有网站中,通过单点登录(SSO)实现无缝的用户体验。您可以利用 MeiChat API 来处理单点登录请求。
API 请求帮助您
- 生成自动登录网址
- 创建用户(如果账户不存在)并生成自动登录 URL
请求URL
https://yourwebsiteaddress/api_request/
请求体
| 参数 | 描述/值 | 必填/可选 |
|---|---|---|
| api_secret_key | 您的 MeiChat API 密钥。要查找 API 密钥,点击菜单>选择设置 > 选择“通用设置” > 查找 API 密钥 | 必填 |
| add | login_session | 必填 |
| email_address | 用户的电子邮件地址 | 必填 |
| create_account | 如果账号不存在,是否要创建账户 [yes|no] | 必填 |
| full_name | 用户的全名(可以是真实姓名或昵称) | 必填 |
| username | 用户的用户名 | 必填 |
| password | 用户的密码 | 必填 |
| site_role | 关于站点角色ID:点击菜单>选择模块>选择站点角色>点击您偏好的站点角色>选择编辑>查找“标识符” | 可选 |
| avatarURL | 用户头像图片的URL | 可选 |
| custom_field_[id] |
将[id]替换为自定义字段ID。
自定义字段ID:点击菜单>选择模块>选择自定义字段>点击您偏好添加的自定义字段>选择编辑>查找“标识符”。 |
可选 |
响应体
| 键 | 描述/值 |
|---|---|
| success | 成功时返回 true,失败时返回 false。 |
| error_message | 返回相关的错误信息 |
| error_key | 此方法返回与错误关联的错误键。 |
PHP 代码示例
<?php
//Enter the following values
$meichat_web_address = 'http://yourwebaddress/';
$api_secret_key = 'Your MeiChat API Secret Key';
$email_address = 'The email address of the user';
//Details of the account to be created (If account doesn't exist)
$create_account = 'yes'; // Whether to Create Account if not exists [yes|no]
$full_name = 'The name of the user';
$username = 'Username for the user';
$password = 'Password for the user';
$avatar = 'User profile image URL';
$site_role_id = ''; // Optional
$iframe_embed = true; // Whether to embed Grupo using iFrame [true|false]
$iframe_width = '500px';
$iframe_height = '700px';
//Ignore the rest
$post_fields=[
'api_secret_key' => $api_secret_key,
'add' => 'login_session',
'create_account'=> $create_account,
'email_address' => $email_address,
'full_name' => $full_name,
'username' => $username,
'password' => $password,
'avatarURL' => $avatar,
'site_role' => $site_role_id,
];
$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 ($response->success) {
if ($iframe_embed) {
echo "<iframe src='".$response->auto_login_url."' width='".$iframe_width."' height='".$iframe_height."' allow='camera;microphone' frameborder=0 allowfullscreen></iframe>";
} else {
header("Location: $response->auto_login_url");
die();
}
} else {
echo $response->error_message;
}
}
}