1

我正在使用以下代码将用户注册到网络研讨会:

   $headers = array(
 'HTTP/1.1',
  'Accept: application/json',
  'Accept: application/vnd.citrix.g2wapi-v1.1+json',
  'Content-Type: application/json',
  'Authorization: OAuth oauth_token='.$access_token,
  'Name_First:test',
  'Name_Last:ank',
  'Email:ankinfo@yahoo.com',
   );

 $gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/{organizerkey}/webinars/{webinarkey}/registrants";
 $curl = @curl_init();
 @curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
     @curl_setopt($curl, CURLOPT_URL, $gtw_url);
      @curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     @curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     @curl_exec($curl);
     @curl_close($curl);

我已通过网络研讨会密钥和组织者密钥。我应该得到如下输出:

HTTP/1.1 201 OK Content-Type: application/json
{
    "registrantKey":5678,
    "joinUrl":"https://www1.gotomeeting.com/join/123456789/5678"
}

问题是当我运行文件时我得到了输出

[
    {
        "registrantKey":106660361,
        "firstName":"test",
        "lastName":"1",
        "email":"rohankapoor99@yahoo.com",
        "status":"WAITING",
        "registrationDate":"2012-06-29T21:07:10Z",
        "joinUrl":"https://www1.gotomeeting.com/join/141654337/106660361",
        "timeZone":"America/Denver"
    }
]

我正在使用创建网络研讨会 URL,那么为什么我会获取已注册用户的信息?

4

1 回答 1

0

这个问题已经存在 3 年了,但考虑到 CITRIX(现为 LogMeIn)API 文档目前的惨淡状态,我提供以下代码段作为可能的解决方案:

显然,我们需要帐户的管理器密钥和访问令牌数据......

    $organizer_key= '10000000000XXXXXXX';
    $access_token = 'GwsiiPWaJbHIiaIiocxxxxxxxxxx';

获取网络研讨会所需的最少字段(例如从 HTML 表单中)并 JSON 对数据进行编码...

    $newRegFields = (object) array(
        'firstName' => $_POST[ 'FirstName' ],
        'lastName'  => $_POST[ 'LastName'  ],
        'email'     => $_POST[ 'Email'     ],
    );

    $newRegistrantFields = json_encode( $newRegFields );

    //echo '<br><br>' . $newRegistrantFields;

获取网络研讨会...

    $webinarID = preg_replace( "/[^0-9]/", "", $_POST[ "WebinarKey" ] );

将 URL 设置为 LogMeIn API(不需要 resendConfirmation选项)...

    $gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/" . $organizer_key . "/webinars/" . $webinarID . "/registrants?resendConfirmation=false";

格式化我们的 POST 标头...

    $headers = array(
        "HTTP/1.1",
        "Accept: application/json",
        "Content-Type: application/json",
        "Authorization: OAuth oauth_token=$access_token",
        "Content-Length: " . strlen( $newRegistrantFields )
    );

设置我们的 cURL 选项,确保我们使用CURLOPT_POST, 1 ...指定一个 POST

    $curl = curl_init();

    curl_setopt( $curl, CURLOPT_URL, $gtw_url                       );
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers                );
    curl_setopt( $curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0                   );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1                   );
    curl_setopt( $curl, CURLOPT_POST, 1                             );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, $newRegistrantFields    );

    $newRegistrants = curl_exec( $curl );
    curl_close( $curl );

我们的 cURL 调用返回了 JSON 编码数据,无论是服务器错误消息还是注册确认。现在让我们把回复变成一个方便的关联数组......

    $newRegistrantsArray = json_decode( $newRegistrants, true );

    //echo '<br><br>' . $newRegistrants . '<br><br>';
    //echo '<pre>'; print_r( $newRegistrantsArray ); echo '</pre>';

如果返回了errorCode键,则注册被炸毁。我在这里所做的只是从服务器获取实际的错误描述并加载它以返回到我的调用 HTML 页面,但这完全是可选的......

    if( array_key_exists( 'errorCode', $newRegistrantsArray )) {
        $form_data[ 'status' ] = false;
        $form_data[ 'code'   ] = $newRegistrantsArray[ 'description' ];
        $form_data[ 'error'  ] = 'E200';
        //echo json_encode( $form_data );
        //exit;
    }

现在,如果注册成功,服务器将返回类似...

(
  [registrantKey] => 2.5022062212198E+18
  [joinUrl] => https://global.gotowebinar.com/join/6552167171182613761/103193261
) 

...所以我只是检查这些密钥是否被退回,如果是,我知道注册是好的。

    if( array_key_exists( 'registrantKey', $newRegistrantsArray ) && array_key_exists( 'joinUrl', $newRegistrantsArray ) ) {
        $form_data[ 'status' ] = true;
        $form_data[ 'code'   ] = $_POST[ 'Email' ] . ' successfully registered with webinar';
        $form_data[ 'error'  ] = 'E300';
        //echo json_encode( $form_data );
        //exit;
    }
于 2015-03-16T17:37:36.730 回答