我正在尝试使用PHP内部的XMLRPC在Magneto中创建用户。直接从页面调用它时调用成功,但是,如果我在函数内部放置相同的调用,则根本不会发生。有什么想法吗?
直接在页面上编码:[完美工作]
<?php
require 'Zend/XmlRpc/Client.php';
$client = new Zend_XmlRpc_Client('myclient.com/api/xmlrpc/');
$session = $client->call('login', array('myuser', 'mypass'));
$new_customer = array('email' => 'nasr@di91.com','firstname' => 'Nair','lastname' => 'Perwaiz','password' => '123456','website_id' => 1,'store_id' => 1,'group_id' => 1);
$zendSpecificArray =array(Zend_XmlRpc_Value::getXmlRpcValue($new_customer,Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT));
$rArray = array($session,'customer.create',$zendSpecificArray);
$new_customer_id = $client->call('call',$rArray);
$rtnval='<?xml version="1.0"?>'.PHP_EOL;
$rtnval.='<root>'.PHP_EOL;
$rtnval.='<result>'.'Customer created with ID :'.$new_customer_id .'</result>'.PHP_EOL;
$rtnval.='</root>'.PHP_EOL;
$client->endSession($session);
header('Content-Type:','Application/xml');
echo $rtnval;
?>
函数内的代码:[没有收到输出]
function registerUser($email,$firstname,$lastname,$password)
{
$client = new Zend_XmlRpc_Client('myclient.com/api/xmlrpc/');
$session = $client->call('login', array('myuser', 'mypass'));
$new_customer = array('email' => $email,'firstname' => $firstname,'lastname' => $lastname, 'password' => $password,'website_id' => 1,'store_id' => 1,'group_id' => 1);
$zendSpecificArray =array(Zend_XmlRpc_Value::getXmlRpcValue($new_customer,Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT));
$rArray = array($session,'customer.create',$zendSpecificArray);
$new_customer_id = $client->call('call',$rArray);
$rtnval='<?xml version="1.0"?>'.PHP_EOL;
$rtnval.='<root>'.PHP_EOL;
$rtnval.='<result>'.'Customer created with ID :'.$new_customer_id .'</result>'.PHP_EOL;
$rtnval.='</root>'.PHP_EOL;
$client->endSession($session);
header('Content-Type:','Application/xml');
echo $rtnval;
}
致电:http://localhost/xxx/rpcclient/rpc.php?methodname=registeruser&em=uuuy@gmail.com&f=ab&l=ty&p=kaddoo
答案 0 :(得分:0)
找到一条wirehark的踪迹,发现我的程序没有发现错误。所以修好了。非常感谢大家!