Sagepay字符(%27)urlencode问题

时间:2015-01-06 10:39:29

标签: curl urlencode sagepay

我的Sagepay实现一段时间以来一直运行良好,但是最近有%27个字符(')的用户一直在返回错误:

'无效:3035:VendorTxCode格式无效。'

目前我在将姓氏发送到我的createVendorTxCode函数之前对其进行URLE编码:

    $encodedSurname = urlencode(Input::get('BillingSurname'));

    // Create a custom VendorTxCode. This must be unique every time.
    $VendorTxCode = $this->createVendorTxCode($encodedSurname, $ids);

...

public function createVendorTxCode($lastName, $ids) {
    $lesson_ids = str_replace(',', '-', $ids);

    $VendorTxCode = $lastName;
    $VendorTxCode .= date("-YmdHis-");
    $VendorTxCode .= rand(0,32000)*rand(0,32000);

    return $VendorTxCode;
}

使用像O'Neil这样的名字,现在返回的姓氏为O%27Neil,我认为这是导致问题的原因(没有此角色的所有其他用户)。在构建了URL的其余部分并将其发送到我的requestPost函数(如下所示)之后,Sagepay将返回上面启动的无效错误

public function requestPost($url, $data){
    set_time_limit(60);
    $output = array();
    $curlSession = curl_init();
    curl_setopt ($curlSession, CURLOPT_URL, $url);
    curl_setopt ($curlSession, CURLOPT_HEADER, 0);
    curl_setopt ($curlSession, CURLOPT_POST, 1);
    curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($curlSession, CURLOPT_TIMEOUT,30); 
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);

    $rawresponse = curl_exec($curlSession);
    $_SESSION["rawresponse"]=$rawresponse;

    $response = explode(chr(10), $rawresponse);
    // Check that a connection was made
    if (curl_error($curlSession)){
        $output['Status'] = "FAIL";
        $output['StatusDetail'] = curl_error($curlSession);
    }

    curl_close ($curlSession);

    for ($i=0; $i<count($response); $i++){
        $splitAt = strpos($response[$i], "=");
        $output[trim(substr($response[$i], 0, $splitAt))] = trim(substr($response[$i], ($splitAt+1)));
    }
    return $output;
}

以下是回复的输出:

   array(3) { ["VPSProtocol"]=> string(4) "2.23" ["Status"]=> string(7) "INVALID" ["StatusDetail"]=> string(42) "3035 : The VendorTxCode format is invalid." }

正如我所说的,这与其他所有姓氏一起工作正常,而不是任何其他姓氏。

非常感谢任何帮助或见解。感谢。

1 个答案:

答案 0 :(得分:1)

vendorTxCode字段仅允许a-z A-Z - _。 (最大长度为40个字符),因此对'字符失败。我担心在vendorTxCode中嵌入姓氏的危险。

相关问题