0

我想在 php 代码中使用 REST 登录并验证用户数据。任何人都可以帮助我,我试图阅读 Bugzilla API 的文档,但我不明白如何应用它。我正在使用 codeigniter,这是我最后一次测试 url

  function createIssue_get() {

    $client_data = array(
        'application_id' => 1,
        'ios' => "IOS",
        'type' => "dsfs",
        'memory' => "32",
        'storage' => "32",
        'wifi' => "dsfd",
        'carrier' => "erwre",
        'battery_level' => "32423",
        'battery_state' => "erwwer",
        'country' => "ewre",
        'city' => "ewrwre",
        'console_log' => "drewrwer",
        'duration' => "werwere",
        'created_at' => date("Y-m-d H:i:s", now())
    );

    $username = 'xxxxxxx@gmail.com';
    $password = 'xxxxxxxx';
    $curl_handle = curl_init();
    curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json"));
    curl_setopt($curl_handle, CURLOPT_URL, 'https://api-dev.bugzilla.mozilla.org/test/latest/bug?username=xxxxx@gmail.com&password=xxxxxxx');
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0); 

    curl_setopt($curl_handle, CURLOPT_POST, 1);
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, json_encode(array(
                'product' => 'MyOwnBadSelf',
                'summary' => substr('testing', 0, 20),
                'version' => 'unspecified',
                'component' => 'Comp1',
                'op_sys' => "All",
                'platform' => "Macintosh",
                'priority' => "P5",
                'severity' => "Trivial",
                'whiteboard' => implode('', $this->array_map_assoc(function($k, $v) {
                                    return "$k:\n$v\n\n";
                                }, $client_data))
            )));

    curl_setopt($curl_handle, CURLOPT_USERPWD, $username . ':' . $password);  
    $buffer = curl_exec($curl_handle);

    curl_close($curl_handle);

    echo $buffer;

}

它适用于创建错误,但我只需要验证用户名并通过???

4

1 回答 1

0

不确定我是否理解您的问题,但如果您尝试将 REST 与 CI 结合使用,这是 Phil Sturgeon 制作的一个很酷的插件:

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

于 2013-04-09T10:06:24.423 回答