使用 PHP API 创建 office 365 用户
Create office 365 user with PHP API
我关注了this tutorial to set up a laravel enviroment to work with the Microsoft Graph API. I want to do CRUD operations on Office 365 users, but in the documentation,没有提供PHP示例代码。
请求正文应如下所示:
POST https://graph.microsoft.com/v1.0/users
Content-type: application/json
{
"accountEnabled": true,
"displayName": "displayName-value",
"mailNickname": "mailNickname-value",
"userPrincipalName": "upn-value@tenant-value.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
}
但是,如何将其转换为 PHP 调用?
您需要 post 作为 PHP Curl 请求。
这是让您入门的基本思路。
$jsonStr = json_encode(Array(
"param1"=>"val1",
"param2"=>"val2",
"param3"=>Array(
"param1"=>"val1",
"param2"=>"val2"
)
));
$headers = Array("Content-Type: application/json","Content-Length:".strlen($jsonStr));
$ch = curl_init("https://graph.microsoft.com/v1.0/users");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
我关注了this tutorial to set up a laravel enviroment to work with the Microsoft Graph API. I want to do CRUD operations on Office 365 users, but in the documentation,没有提供PHP示例代码。
请求正文应如下所示:
POST https://graph.microsoft.com/v1.0/users
Content-type: application/json
{
"accountEnabled": true,
"displayName": "displayName-value",
"mailNickname": "mailNickname-value",
"userPrincipalName": "upn-value@tenant-value.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
}
但是,如何将其转换为 PHP 调用?
您需要 post 作为 PHP Curl 请求。 这是让您入门的基本思路。
$jsonStr = json_encode(Array(
"param1"=>"val1",
"param2"=>"val2",
"param3"=>Array(
"param1"=>"val1",
"param2"=>"val2"
)
));
$headers = Array("Content-Type: application/json","Content-Length:".strlen($jsonStr));
$ch = curl_init("https://graph.microsoft.com/v1.0/users");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);