1

我试图通过使用托管 REST 完整 API 来调用身份验证 API。但是,我没有从身份验证 API 获得任何有效响应。

我使用 Codeigniter CURL 方法通过 URL https://stgsecureapi.escrow.com/api/Transaction发布变量, 但它仍然不适合我。

我收到以下回复:身份验证被拒绝

如果有人有解决这个问题的想法,请帮助我。

我正在使用的代码:

    //The JSON data.
    $url = 'https://stgsecureapi.escrow.com/api/Transaction';

    $jsonData = array(
        'username' => '*****@gmail.com',
        'password' => '****',
    'pid' => '***'
    );

    //Encode the array into JSON.
    $jsonDataEncoded = json_encode($jsonData);
    print_r($jsonDataEncoded);
    // Start session (also wipes existing/previous sessions)
    $this->curl->create($url);

    // Option           
    $this->curl->option(CURLOPT_HTTPHEADER, array('Content-type: application/json; Charset=UTF-8'));

    // Post - If you do not use post, it will just run a GET request            
    $this->curl->post($jsonDataEncoded);

    // Execute - returns responce 
    $this->data['curlreturn'] = $this->curl->execute();
    //exit;
    $this->load->view('pay/pay', $this->data);
4

3 回答 3

1

我得到了 Escrow 与 XML 人口的答案。

还要检查用于使用 CURL 调用 API 的函数

$requeste = '<Transaction xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DTO">
<Title>XML GM Broker Transaction (REST Service)</Title>
<Description>XML GM Broker Transaction (REST Service)</Description>
<TransactionType>1</TransactionType>
<Partner>PartnerId>1234</PartnerId></Partner><Buyer>
<Email>aniji@gmail.com</Email><Initiator>false</Initiator>
<CompanyChk>false</CompanyChk><AutoAgree>true</AutoAgree>
<AgreementChecked>true<AgreementChecked></Buyer>
<Seller><Email>shaibi@gmail.com</Email><Initiator>false</Initiator>
<CompanyChk>false</CompanyChk><AutoAgree>true<AutoAgree>
<AgreementChecked>true</AgreementChecked></Seller><Broker>
<Email>rahul@gmail.com</Email><Initiator>true</Initiator>
<CompanyChk>true<CompanyChk><AutoAgree>true</AutoAgree>
<AgreementChecked>true</AgreementChecked></Broker>
<LineItems> 
<LineItem>      
 <ItemName>syam Milestone 1<ItemName>       
 <Description>Description of Milestone 1</Description>      
 <Quantity>1</Quantity>     
 <Price>1670</Price>        
 <Accept>true</Accept>  
 <SellComm>100<SellComm>        
 <BuyComm>50</BuyComm>  
</LineItem> 
<LineItem>      
 <ItemName>syam MIlestone 2</ItemName>      
 <Description>Description of MIlestone 2<Description>
 <Quantity>1</Quantity>     
 <Price>1450</Price>        
 <Accept>true</Accept>
 <SellComm>100</SellComm>       
 <BuyComm>50</BuyComm>
<LineItem>
</LineItems>
<EscrowPayment>0</EscrowPayment><ShipmentFee>0</ShipmentFee>
<ShipmentPayment>0</ShipmentPayment>
<InspectionLength>6</InspectionLength><Currency>USD<Currency>
<Fulfillment>1</Fulfillment><Disclosure>1</Disclosure>
<BrokerCommissionPayee>Buyer</BrokerCommissionPayee>
<BrkCommissionBuyerPortion>18.1<BrkCommissionBuyerPortion>
<BrkCommissionSellerPortion>19.1</BrkCommissionSellerPortion>
<CommissionType>1<CommissionType>
<SettlementAuthorizationToken>9ACA7889-8A9A-4288-8E28-C325ACD953DB<SettlementAuthorizationToken><InitiationDate>2015-05-15<InitiationDate<TransactionLocked>true</TransactionLocked<PartnerTransID>4286<PartnerTransID><TermsLocked>true<TermsLocked>
<AllowReject>true</AllowReject> </Transaction>';

print curl_dwonload('https://stgsecureapi.escrow.com/apiTransaction',$xmldataFull);//Function for CURL
function curl_dwonload($Url,$request)
{
 if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
}       
    try {
        $url = $Url;
        $ch = curl_init();                                                        
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_POST, true);    
    curl_setopt($ch, CURLOPT_USERPWD, "brokeremail@gmail.com:broker_password");// Must enter username and password
    curl_setopt($ch, CURLOPT_POSTFIELDS,$request);                
    curl_setopt($ch, CURLOPT_HEADER, 1);                       
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      $header = array();
      $header[]="Content-Type: application/xml";
      $header[] = "POST /transaction HTTP/1.1";                                                                     
      $header[]= "Accept:application/xml";                                   
      $header[] = "Host: api.escrow.com";
      //$header[] = "Authorization: Basic T3BhbmFrOlRlc3QxMjM0";
      $header[] = "Content-Length: ".strlen($request);
      $header[] = "Connection: close";
      curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);     
      //echo $ch;                                            
      $data = curl_exec($ch);       
      return $data;
    }
catch (Exception $e) {
      echo $e->getMessage();
      $responseBody = '';
      return "error";
    }

}

带有身份验证 ID(会话 ID)的成功消息:

HTTP/1.1 100 继续 HTTP/1.1 201 Created Cache-Control: no-cache Pragma: no-cache Content-Length: 271 Content-Type: application/xml; charset=utf-8 过期:-1 服务器:Microsoft-IIS/8.0 X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET 日期:2015 年 5 月 16 日星期六 13:14:09 GMT 连接:关闭成功 646494

此会话 ID 646494用于从托管处获取交易详细信息。

于 2015-05-19T05:03:43.757 回答
1

我已经使用了以下 json 格式的代码

$requeste = '{
"Title": "REST DN test transaction (JSON)",
"Description": "REST DN test transaction (JSON)",
"TransactionType": 0,
"Partner": {
"PartnerId": 1234
},
"Buyer": {
"Email": "escrow.buyer@hotmail.com",
"Initiator": false,
"CompanyChk": false,
"AutoAgree": false,
"AgreementChecked": false
},
"Seller": {
"Email": "escrow.seller@hotmail.com",
"Initiator": true,
"CompanyChk": false,
"AutoAgree": false,
"AgreementChecked": false
},
"LineItems": [
{
"ItemName": "test.com",
"Description": "DN description",
"Quantity": 1,
"Price": 2000,
"Accept": true,
"SellComm": 9.1,
"BuyComm": 10.1,
}],
"EscrowPayment": 0,
"ShipmentFee": 0,
"ShipmentPayment":0,
"DomainNameType": 0,
"InspectionLength": 6,
"Currency": "USD",
"Fulfillment": 2,
"CommissionType": 1,
"InitiationDate": "2014-04-15",
"TermsLocked": true,
"AllowReject": true
}';


print curl_dwonload('https://stgsecureapi.escrow.com/api/Transaction',$requeste);//Function for CURL
function curl_dwonload($Url,$request)
{
 if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
}       
    try {
        $url = $Url;
        $ch = curl_init();                                                        
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_POST, true);    
    curl_setopt($ch, CURLOPT_USERPWD, "emailid:password");// Must enter username and password
    curl_setopt($ch, CURLOPT_POSTFIELDS,$request);                
    curl_setopt($ch, CURLOPT_HEADER, 1);                       

      curl_setopt ($ch, CURLOPT_HTTPHEADER,  array('Content-type: application/json; Charset=UTF-8'));     
      //echo $ch;                                            
      $data = curl_exec($ch);       
      echo $data;
    }
catch (Exception $e) {
      echo $e->getMessage();
      $responseBody = '';
      return "error";
    }

}

也检查下面的 youtube 链接。

https://youtu.be/My8PzXtC6iY

于 2015-09-09T08:01:00.363 回答
0

是的,他们真的应该将身份验证详细信息添加到他们的 rest api 文档中。我使用python请求进行授权:

    response = requests.post(url, data=simplejson.dumps(payload), headers=headers,auth=(username,password))
    print "Response: "+str(response)
    print "Response: "+str(response.headers)
    print "Response: "+str(response.content)
于 2015-07-06T18:55:50.087 回答