使用 php 客户端使用 Moodle Web 服务

Consuming moodle web service with php client

我需要将成绩从我的 moodle 导出到另一个网站,我在网上搜索你需要在 moodle 上创建一个网络服务(我已经做了),现在我需要一个带有 php 代码的网页为了使用我的网络服务,我在网上搜索了一些示例(我是网络开发的新手),并在这里找到有人在谈论它,有人能解释一下这段代码是如何工作的,我如何使用它来将我的成绩导出到我的其他人网站。

代码:

<?php


$token = 'meutoken';
$domainname = 'http://meumoodle';
$functionname = 'core_user_get_users';


$restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json'
                 //Setting it to 'json' will fail all calls on earlier Moodle version
//////// moodle_user_create_users ////////
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->key = 'username';
$user1->value = 'myvalue';

$users = array($user1);
$params = array('criteria' => $users);



$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token .             
'&wsfunction='.$functionname;
//require_once('./curl.php');
$curl = new cURL();
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle     
< 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->get($serverurl . $restformat, $params);
$json = json_encode($resp);

$obj = json_decode($resp);


?>

您也可以一次性手动导出成绩,或通过 URL 导出成绩,无需任何开发。

要从课程导出成绩,转到课程,然后是课程管理菜单,然后是成绩册,然后导出

要通过 URL 导出,请参阅 https://docs.moodle.org/400/en/Grade_export#Grade_publishing