【App Store Connect API ( 4 ) 】注册设备 UDID

【App Store Connect API ( 4 ) 】注册设备 UDID

Ty
Ty
2022-03-05 / 0 评论 / 52 阅读 / 正在检测是否收录...

前言

App Store Cinnect API

在阅读本文章之前,请确保您已经阅读  【App Store Connect API ( 1 ) 】获取请求 API 的 Token

API请求参数

 - 请求类型:POST
 - 请求URL:https://api.appstoreconnect.apple.com/v1/devices
 - 请求参数:详见 文档

检查提供的参数

if(empty($_GET['token'])){
    $result = array(
        'status' => '409',
        'detail' => '$token is required'
    );
    echo json_encode($result);
    exit();
}elseif(empty($_GET['udid'])){
    $result = array(
        'status' => '409',
        'detail' => '$udid is required'
    );
    echo json_encode($result);
    exit();
}

初始化CURL请求参数

$curl = curl_init();

$data = array(
    'data' => array(
        'attributes' => array(
            'name' => $_GET['udid'],
            'platform' => 'IOS',
            'udid' => $_GET['udid']
        ),
        'type' => 'devices'
    )
);

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.appstoreconnect.apple.com/v1/devices',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode($data),
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer '.$_GET['token']
  ),
));

发送请求并输出结果

$response = curl_exec($curl);

curl_close($curl);

echo $response;

完整代码

<?php

error_reporting(0);

if(empty($_GET['token'])){
    $result = array(
        'status' => '409',
        'detail' => '$token is required'
    );
    echo json_encode($result);
    exit();
}elseif(empty($_GET['udid'])){
    $result = array(
        'status' => '409',
        'detail' => '$udid is required'
    );
    echo json_encode($result);
    exit();
}

$curl = curl_init();

$data = array(
    'data' => array(
        'attributes' => array(
            'name' => $_GET['udid'],
            'platform' => 'IOS',
            'udid' => $_GET['udid']
        ),
        'type' => 'devices'
    )
);

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.appstoreconnect.apple.com/v1/devices',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode($data),
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer '.$_GET['token']
  ),
));

$response = curl_exec($curl);

curl_close($curl);

echo $response;

exit();
3

评论 (0)

取消