欢迎各位兄弟 发布技术文章
这里的技术是共享的
<?php
function _my_jamf_get_base64_encode()
{
$name = '11111111';
$pwd = '222222222222';
return base64_encode("$name:$pwd");
}
function get_jamf_token(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://jamf.aaaaaa.com:8080/uapi/auth/tokens");
$headers = array('Authorization:Basic ' . _my_jamf_get_base64_encode(), 'Content-Type: application/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // to resolve your current error
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
if (!empty($data_arr)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, drupal_json_encode($data_arr));
}
$response = curl_exec($ch);
if (curl_error($ch)) {
$response = curl_error($ch);
}
curl_close($ch);
return $response;
}
$token_expires = get_jamf_token();
$token_expires = json_decode($token_expires,true);
var_dump($token_expires);
get_device_id_by_mac_addresss_ok.php
<?php
include_once 'authorization_base_ok.php';
$token = $token_expires['token'];
//这里的mac 应该是以冒号来分隔
function _get_static_group_from_jamf($mac,$token){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://jamf.aaaaaa.com:8080/JSSResource/computers/macaddress/${mac}/subset/groups_accounts");
$headers = array('Authorization:Bearer ' . $token, 'Content-Type: text/xml;charset=utf-8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // to resolve your current error
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
if (!empty($data_arr)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, drupal_json_encode($data_arr));
}
$response = curl_exec($ch);
if (curl_error($ch)) {
$response = curl_error($ch);
}
curl_close($ch);
return $response;
}
//$mac
$mac = "64:C7:53:E5:8A:00";
$static_group_xml = _get_static_group_from_jamf($mac,$token);
$xml = simplexml_load_string($static_group_xml);
print_r($xml->groups_accounts->computer_group_memberships->group); //这里得到的是所有的组