7

有谁知道如何集成 Sharepoint 和 Php。我正在尝试开发可以连接到 Sharepoint 的 php 应用程序。特别是因为基本上我是网站开发人员,我希望我的所有网站都与 Sharepoint 连接。所以,我只是想创建一个适用于所有网站的 PHP 应用程序。我不知道这是否可能,但我想尝试一下,但不知道如何进行。

欢迎任何想法/建议。

提前致谢。

4

3 回答 3

8

试试这个API

在 SharePoint 中

下载 WSDL。通常在这个位置:<sharepoint.url>/subsite/_vti_bin/Lists.asmx?WSDL

下载 API

确保同时保存SoapClientAuth.phpSharePointAPI.php

在 PHP 中

// 0: include api in your php script.
require_once('SharePointAPI.php');

// 1: connect to SharePoint
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>');

// 2: read a list
$listContents = $sp->read('<list_name>'); 

// 3: now you have a 2-D array to work with in PHP
foreach($listContents as $item)
{
    var_dump($item);
}

使用此API,您还可以查询、更新、创建、删除列表,查询列表元数据

于 2013-11-20T18:47:36.427 回答
1

如果我没看错您的问题,您想使用 PHP 与您的 SharePoint 网站进行交互。您可以使用 SharePoint 的 Web 服务进行大多数交互。例如,您可以使用列表 Web 服务 (http:///_vti_bin/lists.asmx) 读取所有列表项。您可以将文件上传到 SharePoint 文档库。我疯狂地寻找我为实现这一目标所做的事情的例子,但我已经失去了它。我记得使用 Curl 进行上传。

有许多网站讨论使用 PHP 访问 SharePoint 数据。这是我通过简单的谷歌搜索找到的一对:

以及关于此处称为 Camelot PHP 的工具的讨论

于 2013-07-09T16:12:48.407 回答
1

我在 API 中使用它来将我的 PHP Web 应用程序与 SharePoint 连接并将数据从 PHP 传输到 SharePoint,它对我来说 100% 有效:

使用说明

安装

下载要与之交互的 SharePoint 列表的 WSDL 文件。这通常可以在以下位置获得:sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL

如果您正在使用 composer,只需将 thybag/php-sharepoint-lists-api 添加到您的 composer.json 并运行 composer。

    {
    "require": {
        "thybag/php-sharepoint-lists-api": "dev-master"
    }
    }

如果您不使用 composer,您可以手动下载 SharePoint API 文件的副本,并在项目中包含顶部的“SharePointAPI.php”类。

创建 SharePointAPI 对象

为了使用 PHP SharePoint Lists API,您需要一个具有所需列表权限的有效用户/服务帐户。

对于大多数 SharePoint 安装,您可以使用以下方法创建 API 的新实例:

    use Thybag\SharePointAPI;
            $sp = new SharePointAPI('', '', '');

如果您的安装需要 NTLM 身份验证,您可以改为使用:

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', 'NTLM');

SharePoint Online 用户必须使用:

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', 'SPONLINE');

默认情况下,所有方法都返回一个数组。SetReturnType 可用于指定结果应作为对象返回。

从列表中读取。

要返回列表中的所有项目,请使用

    $sp->read('');
or
    $sp->query('')->get();

要仅返回列表中的前 10 个项目,请使用:

    $sp->read('', 10);

或者

    $sp->query('')->limit(10)->get();

要从姓氏为 smith 的列表中返回所有项目,请使用:

    $sp->read('', NULL, array('surname'=>'smith'));

或者

    $sp->query('')->where('surname', '=', 'smith')->get();

查询列表

当您需要指定一个复杂的查询以便使用 read 方法轻松定义时,可以使用 query 方法。查询是使用许多(希望是富有表现力的)伪 SQL 方法构建的。

例如,如果您想查询宠物列表并返回所有 5 岁以下的狗(按年龄排序),您可以使用。


    $sp->query('list of pets')->where('type','=','dog')->and_where('age','sort('age','ASC')->get();

如果您想获得前 10 只猫或仓鼠宠物,您可以使用:

    $sp->query('list of pets')->where('type','=','cat')->or_where('type','=','hamster')->limit(10)->get();

如果需要返回 5 个项目,但包括列表中包含的所有字段,则可以使用。(将 false 传递给 all_fields 以包含隐藏字段)。

    $sp->query('list of pets')->all_fields()->get();

如果您有一组用于要运行的特定高级查询的 CAML,则可以使用以下命令将其传递给查询对象:

    $sp->query('list of pets')->raw_where('Hello World')->limit(10)->get();

添加到列表

要将新项目添加到列表中,您可以使用“write”、“add”或“insert”方法(所有功能都相同)。在包含名字、姓氏、年龄和电话列的列表中创建新记录可能如下所示:

    $sp->write('', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' ));

您还可以使用以下命令一起运行多个写入操作:

    $sp->writeMultiple('', array(array('forename' => 'James'),array('forename' => 'Steve')));

编辑行

要编辑一行,您需要有它的 ID。假设上面一行的 ID 为 5,我们可以将 Bob 的名字改为 James:

    $sp->update('','5', array('forename'=>'James'));/code>

As with the write method you can also run multiple update operations together by using:

    $sp->updateMultiple('', array(    array('ID'=>5,'job'=>'Intern'),array('ID'=>6,'job'=>'Intern')));

When using updateMultiple every item MUST have an ID.

Deleting Rows

In order to delete a row, an ID, as well as list name, is required. To remove the record for James with the ID 5 you would use:

    $sp->delete('', '5');

If you wished to delete a number of records at once, an array of ID's can also be passed to the delete multiple methods

    $sp->deleteMultiple('', array('6','7','8'));

Helper methods

The PHP SharePoint API contains a number of helper methods to make it easier to ensure certain values are in the correct format for some of SharePoint special data types.

dateTime The DateTime method can either be passed a text-based date

    $date = \Thybag\SharepointApi::dateTime("2012-12-21");

Or a unix timestamp

    $date = \Thybag\SharepointApi::dateTime(time(), true);

Troubleshooting

Unable to find the wrapper "https"

If you are getting this error it normally means that php_openssl (needed to curl https URLs) is not enabled on your web server. With many local web servers (such as XAMPP) you can simply open your php.ini file and uncomment the php_openssl line (ie. remove the; before it).

Note: If you are using SharePoint Online and having SSL errors, please pull the latest version which has changed from SSL v3 to TLS for SharePoint online connections.

Add this line to your composer.json file

    thybag/php-sharepoint-lists-api: dev-develop

您可以使用上述 SharePoint API 执行 CRUD(创建/读取/更新/删除)操作。

参考网址链接:https ://github.com/thybag/PHP-SharePoint-Lists-API

于 2018-06-04T16:07:38.647 回答