首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用php开发neteller直接API?

如何用php开发neteller直接API?
EN

Stack Overflow用户
提问于 2013-09-19 09:30:06
回答 2查看 5K关注 0票数 3

我的工作是在网站上的neteller直接api,用户可以转移资金到我们的商家帐户。API步骤如下:

  1. 在网站上创建表单
  2. 请用户填写表格
  3. 将表单提交给neteller安全URL,该URL返回带有响应元素的XML页面

在提交表格后,我很困惑下一步该做什么?当我们提交表单时,我们得到了xml页面,这很好,但是现在该怎么办呢?我需要将结果显示给用户,这样在提交表单之后,用户将能够看到一条消息,上面写着“事务已完成”或基于XML批准值的类似消息。我尝试使用jQuery ajax方法,这样我可以在jQuery XML对象中接收响应,所有表单提交都在后台进行,当请求完成时,我可以将响应xml显示给用户。这是不工作的,因为跨域的帖子不工作。(我在网上读到过)那么,向用户提供最佳用户体验的正确步骤是什么呢?我们不能向用户显示这个xml。那么,想知道如何在提交表单后使用下一步吗?

表格示例:

代码语言:javascript
复制
<form method="post" action="https://api.neteller.com/netdirect">
<input type="text" name="version" value=" 4.1">
<input type="text" name="amount" size="10" value="0.02" maxlength="10">
<input type="text" name="currency" value="USD" size="10" maxlength="3">
<input type="text" name="net_account" size="20" maxlength="100">
<input type="text" name="secure_id" size="10" maxlength="6">
<input type="hidden" name="merchant_id" value="">
<input type="hidden" name="merch_key" value="">
<input type="hidden" name="merch_transid" value="" maxlength="50">
<input type="hidden" name="language_code" value="EN">
<input type="hidden" name="merch_name" value="">
<input type="hidden" name="merch_account" value="" maxlength="50">
<input type="hidden" name="custom_1" value="test123" maxlength="50">
<input type="hidden" name="custom_2" value="test123" maxlength="50">
<input type="hidden" name="custom_3" value="test123" maxlength="50">
<button type="submit" name="submit">Make Transfer</button>

有谁能帮忙解决这个问题吗?阿贾克斯还是卷发还是怎么做?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-30 05:22:39

我可以通过卷曲完成这件事。我使用curl方法将结果发布到url并在xml中获得结果,该结果后来被php方法simplexml_load_string()解析。

代码语言:javascript
复制
// open curl connection
$ch = curl_init('https://api.neteller.com/netdirect');

// get the vars from POST request and add them as POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'version' => $_POST['version'],
    'amount' => urlencode($_POST['amount']),
    'currency' => $_POST['currency'],
    'net_account' => urlencode($_POST['net_account']),
    'secure_id' => urlencode($_POST['secure_id']),
    'merchant_id' => urlencode($_POST['merchant_id']),
    'merch_key' => urlencode($_POST['merch_key']),
    'merch_transid' => urlencode($_POST['merch_transid']),
    'language_code' => $_POST['language_code'],
    'merch_name' => urlencode($_POST['merch_name']),
    'merch_account' => urlencode($_POST['merch_account']),
    'custom_1' => urlencode($_POST['custom_1']),
    'custom_2' => urlencode($_POST['custom_2']),
    'custom_3' => urlencode($_POST['custom_3']), 
    'button' => 'Make Transfer'
]));

// set other curl options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

// execute post
$output = curl_exec($ch);
$info = curl_getinfo($ch);
$error = '';
$approval = '';

// check if curl request processed or not
if(($output == false) or ($output == '')) {
    $curlerror = curl_error($ch); 
    $error = 'Server Error. ';

} else {
    $response = simplexml_load_string($output); 
    $approval = $response->approval;
}

// close curl connection
curl_close($ch);
票数 3
EN

Stack Overflow用户

发布于 2013-10-28 14:30:25

您不是将请求发送到neteller,而是发送到您的服务器,而不是将请求从服务器发送到neteller。

-这条路通向你的服务器

代码语言:javascript
复制
function netellerPayment(){
    $.ajax({
        async: false,
        type: "POST",
        url: "http://localhost/neteller/notification.php",
        data: $("#netellerform").serialize(),
        success: function(data){
        }
    })
}

$(function() {
    $('#submitneteller').click(function( event ){
        event.preventDefault();
        netellerPayment();
    })
})

-现在在您的服务器上使用php

代码语言:javascript
复制
$urltopost = "https://api.neteller.com/netdirect";
$data = $_POST;

$urltopost = "https://api.neteller.com/netdirect";
$ch = curl_init ($urltopost);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$returndata = curl_exec ($ch);

$xml = new DOMDocument ( '1.0', 'utf-8' );
$xml->preserveWhiteSpace = false;
$xml->loadXML ( $returndata );
$errors = $xml->getElementsByTagName( 'error' );
foreach ($errors as $error) {
    echo $error->nodeValue; 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18891030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档