3

我尝试了许多不同的方式来调用“使用cart_paymant.methodAPI但总是失败。 MagentoXMLRPC

下面是我用来调用它的代码。

Map<String,String> map = new HashMap<String,String>();
map.put("method","checkmo");
//map.put("po_number",null);
//map.put("cc_cid", null);
//map.put("cc_owner",null);
//map.put("cc_number",null);
//map.put("cc_type",null);
//map.put("cc_exp_year",null);
//map.put("cc_exp_month",null);


Object[] paymentMethod=new Object [] {map};
Object param1[]=new Object[]{shoppingCartId,paymentMethod};
Object param2[]=new Object[]{Utils.sessionId,"cart_payment.method",param1};   

try 
{
  Boolean ans=(Boolean)client.callEx("call", param2);
  Log.i("Payment Method Setting : ", ""+ans);
}  
catch (XMLRPCException e) {
  e.printStackTrace();
  return 0;
}  

我得到的例外:

java.io.IOException: Cannot serialize null
at org.cws.magentoAnd.xmlrpc.XMLRPCSerializer.serialize(XMLRPCSerializer.java:99)
at org.cws.magentoAnd.xmlrpc.XMLRPCSerializer.serialize(XMLRPCSerializer.java:89)
at org.cws.magentoAnd.xmlrpc.XMLRPCSerializer.serialize(XMLRPCSerializer.java:72)
at org.cws.magentoAnd.xmlrpc.XMLRPCSerializer.serialize(XMLRPCSerializer.java:72)
at org.cws.magentoAnd.xmlrpc.XMLRPCCommon.serializeParams(XMLRPCCommon.java:36)
at org.cws.magentoAnd.xmlrpc.XMLRPCClient.methodCall(XMLRPCClient.java:253)
at org.cws.magentoAnd.xmlrpc.XMLRPCClient.callEx(XMLRPCClient.java:174)

仅供参考,我还发布了 Web 上提供的调用该 API 的 php 代码。

$paymentMethod = array(
    “method” => “checkmo”
);

$resultPaymentMethod = $proxy->call(
    $sessionId,
    “cart_payment.method”,
    array(
        $shoppingCartId,
        $paymentMethod
    )
);
4

1 回答 1

0

我已经sessionId登录了,但是当我调用一个方法(例如:)时catalog_category.info,它会抛出异常:

XMLRPC 故障:调用参数与签名不匹配。

这是我的代码:

new AsyncTask<Void, Void, Void>() {
   @Override
   protected Void doInBackground(Void... params) {
      uri = URI.create("http://gameshay.net/magento/index.php/api/xmlrpc/");
      client = new XMLRPCClient(uri);
      String sessionId = "";
      try {
         sessionId = (String)client.call("login", "mdev", "socbay123");
         Log.d("MY_XMLRPC_SUCCESS_SESSION_ID", sessionId);
         @SuppressWarnings("unchecked")
         final Map<String, Object> category = (Map<String, Object>) client.call("call" Object[]{sessionId, "catalog_category.info","5"});
      }
      catch (XMLRPCException e) {
         Log.d("MY_XMLRPCException_MSG", e.getMessage());
      }
      return null;
   }
}.execute();
于 2013-09-18T10:01:08.243 回答