English 中文(简体)
要求的答复未能收到
原标题:Curl request response not getting
  • 时间:2012-05-14 05:36:35
  •  标签:
  • php

我正在向虚拟商家付款网发送信息,以便使用曲线付款。 这是我的法典:

$Url= "https://www.myvirtualmerchant.com/VirtualMerchant/process.do";
    // is cURL installed yet?
    if (!function_exists( curl_init )){
        die( Sorry cURL is not installed! );
    }

    // OK cool - then let s create a new cURL resource handle
    $ch = curl_init();

    // Now set some options (most are optional)

    // Set URL to download
    curl_setopt($ch, CURLOPT_URL, $Url);


    // Include header in result? (0 = yes, 1 = no)
   // curl_setopt($ch, CURLOPT_HEADER, 0);

    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);


    $fields = array(
             ssl_card_number =>urlencode($_POST[ ssl_card_number ]),
             ssl_exp_date =>urlencode($_POST[ ssl_exp_date ]),
             ssl_cvv2cvc2 =>urlencode($_POST[ ssl_cvv2cvc2 ]),
             ssl_avs_address =>urlencode($_POST[ ssl_avs_address ]),
             ssl_avs_zip =>urlencode($_POST[ ssl_avs_zip ]),
             ssl_merchant_id =>urlencode($_POST[ ssl_merchant_id ]),
             ssl_user_id =>urlencode($_POST[ ssl_user_id ]),
             ssl_pin =>urlencode($_POST[ ssl_pin ]),
             ssl_transaction_type =>urlencode($_POST[ ssl_transaction_type ]),
             ssl_amount =>urlencode($_POST[ ssl_amount ]),
             ssl_show_form =>urlencode($_POST[ ssl_show_form ]),
             TransactionType =>urlencode($_POST[ TransactionType ])
        );

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key. = .$value. & ; }
    rtrim($fields_string, & );
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    // Download the given URL, and return output
    echo $output = curl_exec($ch);

    // Close the cURL resource, and free system resources
    curl_close($ch);

    print_r($output); 

But in $output i am getting nothing, not any error or message. Am i doing it wrong ? please tell me ?

问题回答

首先,我检查了你的肉类_、pin等。 以下是通过类似问题开展工作后制定的《第一号工作守则》。

<html>
    <body>
        <p>--start--</p>

<?php
//if you have a live account don t use the "demo" post url it won t work
$post_url =  https://www.myvirtualmerchant.com/VirtualMerchant/process.do ;

//replace the xxx s with your proper merchant_id, etc. 
//they will give you these when you activate your account

//I ve set form to not show, and ssl_result_format =>ascii to get a string returned

$fields = array(
     ssl_merchant_id            => xxxxxx ,
     ssl_user_id                => xxx ,
     ssl_pin                => xxxxx ,
     ssl_show_form              => false ,
     ssl_result_format          => ascii ,
     ssl_test_mode              => false ,
     ssl_transaction_type       => ccsale ,
     ssl_amount                 => 1.44 ,
     ssl_card_number            => 5000300020003003 ,
      ssl_exp_date              => 1214 ,
     ssl_avs_address            => Test 3 ,
     ssl_avs_zip                => 123456 ,
     ssl_cvv2cvc2               => 123 ,
);

//build the post string
$fields_string =   ;
foreach($fields as $key=>$value) { $fields_string .=$key. = .$value. & ; }
rtrim($fields_string, "&");

//open curl session
// documentation on curl options at http://www.php.net/curl_setopt

$ch = curl_init();
//begin seting curl options
//set URL
curl_setopt($ch, CURLOPT_URL, $post_url);

//set method
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//set post data string
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

//these two options are frequently necessary to avoid SSL errors with PHP
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$result = curl_exec($ch); 

if($result === FALSE) {
    //post failed
    die(curl_error($ch));

} else {
    //got a response
    //some people seem to get name/value pairs delimited with "&" 
    //but currently mine is 
 
    //support told me there s no way to change it..
    $response_array = explode("
",$result); 

    //make it nice and useful
    foreach( $response_array as $k=>$v ){
        $v=explode("=",$v);
        $a[$v[0]]=$v[1];
    }

    //show the whole array
    print_r($a);

    //use a specific return value
    //returns "APPROVAL" if it went through
    echo( <h1> . $a[ssl_result_message] .  </h1> );
}
?>

       <p>--end--</p>
    </body>
</html>

上面的《法典》应当像你这样把一个屏幕连接起来:

--start--

Array ( [ssl_card_number] => 50**********3003 [ssl_exp_date] => 1214 [ssl_amount] => 1.44 [ssl_customer_code] => [ssl_salestax] => [ssl_invoice_number] => [ssl_description] => [ssl_departure_date] => [ssl_completion_date] => [ssl_company] => [ssl_first_name] => [ssl_last_name] => [ssl_avs_address] => Test 3 [ssl_address2] => [ssl_city] => [ssl_state] => [ssl_avs_zip] => 123456 [ssl_country] => [ssl_phone] => [ssl_email] => [ssl_result] => 0 [ssl_result_message] => APPROVAL [ssl_txn_id] => AA49315-1234567-F78F-468F-AF1A-F5C4ADCFFB1E [ssl_approval_code] => N53032 [ssl_cvv2_response] => [ssl_avs_response] => [ssl_account_balance] => 0.00 [ssl_txn_time] => 01/15/2014 11:53:15 AM )

APPROVAL

--end--

确保你在完成测试时删除所有这些测试采购。 我告诉他们,他们会阻止你真正的购买。

试图找出错误

var_dump(curl_error($ch));

before and calling curl_exec($ch);

1. 发现错误,在曲线关闭之前就给予该守则:-

echo "Curl Error :--" . curl_error($ch);

如果没有发现错误,则:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch); 

当时

print_r($result);
exit;

引证:

$output = curl_exec($ch);
$response = curl_getinfo($ch);
echo "<pre>";
print_r($response);
echo "</pre>";

希望得到答复:





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签