du16178 2019-05-22 12:06
浏览 83

使用codeigniter集成座位卖家api。错误:ExceptionRequest失败,代码为401:错误:OAUTH验证失败

I have successfully done oauth1.0 authentication for the get methods provided in the api document http://api.seatseller.travel/docs/interface.html
But I am getting issue in blockticket url in the above document URL : http://api.seatseller.travel/blockTicket.
I need to post the parameters along .I have used Oauth1.0 2Leg library in codeigniter.But its giving me the error as :

ExceptionRequest failed with code 401: Error: OAUTH verification failed.

Take reference of this url for Oauth library. https://github.com/jesstelford/OAuth-PHP

In codeigniter/application/helpers I have created a helper in that I coded

 include_once APPPATH . 'libraries/OAuth/OAuthStore.php';
   include_once APPPATH . 'libraries/OAuth/OAuthRequester.php';

   function getbusUrlPost($url,$data) {
    $key = 'key';
    $secret = 'secret'; 
    $options = array('consumer_key' => $key, 'consumer_secret' => $secret);
    OAuthStore::instance("2Leg", $options);
    $method = "POST"; 
    $params =$data;

    //var_dump($params);
    try
    {
         // Obtain a request object for the request we want to make
        $request = new OAuthRequester($url, $method,$params);
        $result = $request->doRequest(0);

        // Sign the request, perform a curl request and return the results, 
        // throws OAuthException2 exception on an error
        // $result is an array of the form: array ('code'=>int, 
        'headers'=>array(), 'body'=>string)
        $result = $request->doRequest();

        $response = $result['body'];

        if ($response != 
        'oauth_token=requestkey&oauth_token_secret=requestsecret') 
        {
                echo $response;
        }
        else 
        {
            ECHO '------';
        }     
    }
    catch(OAuthException2 $e)
    {
            echo "Exception" . $e->getMessage();
    }

   }

in controller:

 <?php
       include_once APPPATH . 'libraries/REST_Controller.php';
       class BusBooking extends Rest_Controller {

    public function get_bus_blockTicket_post() {
         if(isset($_REQUEST['availableTripID']) && 
   isset($_REQUEST['seatname']) 
                 && isset($_REQUEST['fare']) && 
   isset($_REQUEST['ladiesSeat']) 
                 && isset($_REQUEST['name']) && isset($_REQUEST['mobile']) 
   && isset($_REQUEST['title']) 
                 && isset($_REQUEST['email']) && isset($_REQUEST['age']) && 
     isset($_REQUEST['gender'])){

             $url="http://api.seatseller.travel/blockTicket";

       $data=array(
           'availableTripID'=>$_REQUEST['availableTripID'],
                'seatname'=>$_REQUEST['seatname'],
                'fare'=>$_REQUEST['fare'], 
                'ladiesSeat'=>$_REQUEST['ladiesSeat'],             
                   'name'=>$_REQUEST['name'],
                    'mobile'=>$_REQUEST['mobile'],
                     'title'=>$_REQUEST['title'],
                     'email'=>$_REQUEST['email'],
                     'age'=>$_REQUEST['age'],  
                    'gender'=>$_REQUEST['gender']                                    

        );
       $sources= getbusUrlPost($url, $data); 
    }
  }

I have also tried with curl. But getting same error.Check the following code with curl.

function getBusblock($data) {

   $url="http://api.seatseller.travel/blockTicket";
   $header[]= 'Content-Type: application/x-www-form-urlencoded';
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url); 
   curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
   curl_setopt($ch, CURLOPT_POST,true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, 
 array('oauth_consumer_key'=>"key",'oauth_signature_method'=>"HMAC- 
 SHA1",'oauth_timestamp'=>'1557752217','oauth_nonce'=>'5cd969995be23','oauth_version'=>'1.0','oauth_signature'=>'DsMdvOOUI57VTkx5VQokUmi9rvw%3D&'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec($ch);
  if(curl_error($ch))
  {
    echo 'error:' . curl_error($ch);
  }
   echo "<pre>";
   echo json_encode($result);
   echo "</pre>";
   exit;
  }

Please help me.I have tried much but I am getting Oauth verification failed issue.

I am expecting response in json format with all the ticket details .But getting this output : ExceptionRequest failed with code 401: Error: OAUTH verification failed. when hitted webservice with postman.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 CSS实现渐隐虚线框
    • ¥15 有没有帮写代码做实验仿真的
    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?