douxu2467 2013-11-20 11:41
浏览 80
已采纳

为什么这个php语句不起作用? 无法使用网址发送数据

<?php

function generateToken($encrypted_data)
{
    $_id = "7639945321063574";
    $api_key = "0za2fOfdWU5OKYwMBnTH";
    // CC data to tokenize..

    //Payload to be sent to
    $data = array(
        'ID' => _id,
        'APIKey' => $api_key,
        'EcryptedData' => $encrypted_data,
        'TokenScheme' => 4 
    );
    //convert to JSON
    $json = json_encode($data);
    //curl config
       $ch = curl_init("https://test-api..com:8081/TokenServices.svc/REST/TokenizeFromEncryptedValue");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                    'Content-Type: application/json', //we are using json in this example, you could use xml as well
                                    'Content-Length: '.strlen($json),
                                    'Accept: application/json')       //we are using json in this example, you could use xml as well
                                    );
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

       $outputjson = curl_exec($ch);       

       //echo "URL error: ",curl_error($ch),PHP_EOL; 
       if(curl_errno($ch)){
        $output = curl_error($ch);
       } else {
        $outputobj = json_decode($outputjson);
        $output = $outputobj->{'Token'};
       }           

       curl_close($ch);
       return $output; 
}

function encryptText_3des($plainText, $key) {
    $key = hash("md5", $key, TRUE); 
    for ($x=0;$x<8;$x++) {
        $key = $key.substr($key, $x, 1);
    }
    $padded = pkcs5_pad($plainText,
        mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
    $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
    return $encrypted;
}

function makePayment() {
    $checksum = $_POST['merchantId']."|".$_POST['amount']."|".$_POST['customerReferenceNo'];    
    echo "<b>Checksum </b>".$checksum."<br>";
    $checksum = hash('sha256', $checksum);  
    echo "<b>Hash Checksum </b>".$checksum."<br>";
    $data = http_build_query(array('cardProvider' => $_POST['cardProvider'],'cardType' => $_POST['cardType'],'cardNumber' => $_POST['cardNumber'],'securityCode' => $_POST['securityCode'],'cardExpiryMonth' => $_POST['cardExpiryMonth'],'cardExpiryYear' => $_POST['cardExpiryYear'],'cardHolderName' => $_POST['cardHolderName'],'currencyCode' => $_POST['currencyCode'],'customerReferenceNo' => $_POST['customerReferenceNo'],'name' => $_POST['name'],'mobileNo' => $_POST['mobileNo'],'email' => $_POST['email'],'password' => $_POST['password'],'remoteIP' => $_POST['remoteIP'],'checkSum' => $checksum));
    echo "<b>Data </b>".$data."<br>";
    $encryption_key = "HG58YZ3CR9";
    $desEncryptedData = encryptText_3des($data, $encryption_key);
    $desEncryptedData = urlencode($desEncryptedData);
    echo "<b>3DES Encrypted Data </b>".$desEncryptedData."<br>";

/*  $ch = curl_init("https://cellpay.essecom.com/PGCCDCToken/TokenPayment.jsp");
    //$ch = curl_init("http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_body_onload");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('merchantId' => $_POST['merchantId'],'data' => $desEncryptedData)));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $output = curl_exec($ch);       
    echo "<b>URL error: </b>",curl_error($ch)."<br>"; 
    curl_close($ch);
    //echo "<b>Output: </b>",$output."<br>"; */
       $merchantid=$_POST['merchantId'];
       $url='https://cellpay.essecom.com/PGCCDCToken/TokenPayment.jsp?merchantId='.$merchantid.'&data='.$desEncryptedData;    //$encrypted_data;

guys everything is working perfect,until this line below,the echo statement.All I want is to pass two values to the url above by using the code below,in the same window.But its not getting redirected.Why does this happen?

    echo "<script type='text/javascript'> window.open('$url');</script>";




}

    $strHeading = "<h1>Hello </h1>";

    if(empty($_POST['name'])){
          $name = 'Anonymous';
        }      
    else $name = $_POST['name'];
    if(empty($_POST[_cipherText'])){
          $encrypted = 'none';
        $token = 'no token';    
        }      
    else  {_cipherText'];
        $token = generateToken($encrypted); 
    }
    if(empty($_POST['cardNumber'])){
        }      
    else  {
        makePayment();  
    }

?>
<html>
<head>
<script type="text/javascript" src="https://test-api..com:8081/inpage/js-client-2.1.2.min.js"></script>
</head>
<body>
<!--
<input type="text" name="name" value="<?php echo htmlentities($username); ?>" />
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
CipherText is: <?php echo $_POST["_cipherText"]; ?>
    <input type="text" name="name" value="<?php echo htmlentities($username); ?>" />
-->
    <?php echo $strHeading; ?>
    <h2>Step1. Enter the customer details and submit</h2>
    <form action="TokenProcess.php" method="post">
        <input id="txtEncryptionKey" name="txtEncryptionKey" class=_encryptionkey"
        type="hidden" value="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvWpIQFjQQCPpaIlJKpeg
        irp5kLkzLB1AxHmnLk73D3TJbAGqr1QmlsWDBtMPMRpdzzUM7ZwX3kzhIuATV4Pe
        7RKp3nZlVmcrT0YCQXBrTwqZNh775z58GP2kZs+gVfNqBampJPzSB/hB62KkByhE
        Cn6grrRjiAVwJyZVEvs/2vrxaEpO+aE16emtX12RgI5JdzdOiNyZEQteU6zRBRJE
        ocPWVxExaOpVVVJ5+UnW0LcalzA+lRGRTrQJ5JguAPiAOzRPTK/lYFFpCAl/F8wt
        oAVG1c8zO2NcQ0Pko+fmeidRFxJ/did2btV+9Mkze3mBphwFmvnxa35LF+Cs/XJH
        DwIDAQAB" />
        <table>
        <tr>
        <th>Name: </th><td><input type="text" name="name" value="<?php echo htmlentities($name); ?>"></td>
        </tr>
        <tr>
        <th>CardNumber: </th><td><input type="text" name="ccnumber" id="ccnumber" class=_data"></td>
        </tr>
        </table>
        <input type="submit" name="btn_process" value="Submit" id="btn_process" class="_submit btn btn-success">
    </form>
    <h2>Step2. Submit when encrypted data is available</h2>
    <form action="TokenProcess.php" method="post">
        <table>
        <tr>
        <th>Encrypted CardNumber: </th><td><input type="text" name="_cipherText" value="<?php echo htmlentities($encrypted); ?>" /></td>
        </tr>
        <tr>        
        <th>Merchant ID: </th><td><input type="text" name="merchantId" value="iZwipe1"></td>        
        </tr>
        <tr>
        <th>Password : </th><td><input type="text" name="password" value="iZwipe"></td>
        </tr>
        <tr>
        <th>customerReferenceNo : </th><td><input type="text" name="customerReferenceNo" value="iZwipe"></td>       
        </tr>
        <tr>
        <th>remoteIP : </th><td><input type="text" name="remoteIP" value="10.10.10.80"></td>
        </tr>
        <tr>
        <th>amount : </th><td><input type="text" name="amount" value="10"></td>
        </tr>
        <tr>
        <th>currencyCode : </th><td><input type="text" name="currencyCode" value="356"></td>
        </tr>
        <tr>
        <th>cardNumber : </th><td><input type="text" name="cardNumber" value="<?php echo htmlentities($token); ?>"></td>
        </tr>
        <tr>
        <th>cardExpiryMonth : </th><td><input type="text" name="cardExpiryMonth" value="12"></td>
        </tr>
        <tr>
        <th>cardExpiryYear : </th><td><input type="text" name="cardExpiryYear" value="2014"></td>
        </tr>
        <tr>
        <th>securityCode: </th><td><input type="text" name="securityCode" value="123"></td>
        </tr>
        <tr>
        <th>cardHolderName : </th><td><input type="text" name="cardHolderName" value="<?php echo htmlentities($name); ?>"></td>
        </tr>
        <tr>
        <th>cardType : </th><td><input type="text" name="cardType" value="CC"></td>
        </tr>
        <tr>
        <th>cardProvider: </th><td><input type="text" name="cardProvider" value="VISA"></td>
        </tr>
        <tr>
        <th>name: </th><td><input type="text" name="name" value="<?php echo htmlentities($name); ?>"></td>
        </tr>
        <tr>
        <th>mobileNo : </th><td><input type="text" name="mobileNo" value="9008032751"></td>
        </tr>
        <tr>
        <th>email : </th><td><input type="text" name="email" value="9008032751"></td>
        </tr>
        </table>
        <input type="submit" name="token_process" value="Make Payment" id="token_process" class="btn btn-success"/>
    </form>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongwo5686 2013-11-20 11:43
    关注

    Enclose your </script> tag, It is not enclosed properly,

     echo "<script type='text/javascript'> window.open('$url');</script>";
    

    And in function encryptText_3des() there is no function pkcs5_pad().

    pkcs5_pad() is missing in your code.

     function pkcs5_pad ($text, $blocksize)
    {
        $pad = $blocksize - (strlen($text) % $blocksize);
        return $text . str_repeat(chr($pad), $pad);
    }
    

    Then,

    Remove this line from your code // echo "<script type='text/javascript'> window.open('$url')<\script>";

    Add this line instead header("location:$url");

    Note: Use some standard IDEs it mostly solved your basic errors. Use apache error log file for finding errors.

    Ref: http://php.net/manual/en/ref.mcrypt.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP