使用 Web 服务 API 函数暂停 Moodle 用户

Suspend a Moodle user by using Web service API functions

我正试图在 PHP 中使用 Moodle 的 Web service API functions 暂停 Moodle 中的用户。 我可以更改名字等用户字段,但我无法暂停用户。

总是returns"null"。

这是我的代码:

<?php
$serverurl = "http://localhost/web/moodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&wsfunction=core_user_update_users&moodlewsrestformat=json";
$params = "users[0][id]=4&users[0][preferences][0][type]=suspended&users[0][preferences][0][value]=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $serverurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);

print_r($response);

curl_close($ch);
?>

暂停用户已添加到 MDL-31465 中的 Web 服务,使其成为 3.2 版。如果您使用的是旧版本并且不想升级,可以使用 core_user_update_users 功能并将 auth 设置为 nologin.

返回 null 的 API 并不表示错误 - 如果出现问题,您将收到更详细的错误。

with moodle 3.7 应该可以工作,但不能像上面的例子那样使用"preferences" 但是 使用以下模板:

wsfunction=core_user_update_users&users[0][id]=1234&users[0][suspended]=1