2013-04-16 50 views
2

我正在使用Magento和第三方Java Web应用程序。 我的应用程序通过Magento SOAP API V2“连接”到Magento。Magento客户通过API认证

如何通过api从我的Java应用程序(Magento以外)执行客户验证?

任何帮助,将不胜感激。

回答

4

我想出了关于如何给客户通过SOAP API登录,我将它张贴在这里的解决方案所以它可以为others.Here有益的是我做过什么,使其工作:

  1. 我创建了一个自定义模块在Magento与登录客户定制的方法和retuns的会话ID即在服务器端设置。

    Mage::app()->setCurrentStore($website); 
    // Init a Magento session. This is super ultra important 
    Mage::getSingleton('core/session'); 
    
    // $customer Mage_Customer_Model_Customer 
    // We get an instance of the customer model for the actual website 
    $customer = Mage::getModel('customer/customer') 
        ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 
    
    // Load the client with the appropriate email 
    $customer->loadByEmail($email); 
    
    // Get a customer session 
    $session = Mage::getSingleton('customer/session'); 
    
    $session->loginById($customer->getId()); 
        if ($session->isLoggedIn()) { 
        return $session->getSessionId(); 
    } else { 
        return null; 
    } 
    
  2. 我创建了一个Magento Custom Api这样我就可以通过SOAP调用我的登录方法。

  3. 从我的JAVA应用程序中调用登录方法,获取sessionId,然后根据收到的sessionId在浏览器上设置cookie。 http://yourmagentohost/setCookies.php?sessionId=your_session_id

而且里面setCookies.php您有:setcookie("frontend", $_GET["sessionId"] , time()+3600);

就是这样,现在你有一个客户记录。

-2

您的代码示例不使用SOAP。 Magento的SOAP存取实际上如下所示:


    $client = new SoapClient('http://magentohost/soap/api/?wsdl'); 

    // If somestuff requires api authentification, 
    // then get a session token 
    $session = $client->login('apiUser', 'apiKey'); 

看一看API文档:http://www.magentocommerce.com/api/soap/introduction.html

+1

如写在你的代码的评论,它执行** API认证**,不是**客户认证**。 – vadim

+0

根据文档,没有创建客户会话或设置合适的Cookie的呼叫,以便客户在他/她事后访问商店时登录。 –

1

如何通过API从我的Java aplication 执行客户身份验证(外面的Magento的)? SOAP API V2

说明: API用户(至少Soap)和客户是两种用户类型。如果您有一个预先存在的用户列表,并且正在查找它们是否以用户的身份存在于Magento中,则可以检索电子邮件帐户及其相关属性和相应的密码哈希值(CE:md5:salt或CE/EE:sha :盐)都通过SOAP。如果您想要进行比较操作,您需要对密码执行相同的哈希以执行1:1比较。如果您希望让您的应用程序使用SOAP来直接执行操作,那么我会确保存在一个抽象层,因为您的应用程序可能被恶意地用于其他用户标识的全部,这取决于Magento的Admin中设置的SOAP角色和ACL 。 移动...

V2:您必须交换到Java,例如:PHP。

$username 'yourUsername'; 

$password = 'yourApiKeyPlainText'; 

$proxy = new SoapClient('https://www.yourdomain.com/magento/api/v2_soap?wsdl=1'); 

$sessionId = $proxy->login($username, $password); 

//Get a Full customer List from Magento 
$customerList = $proxy->customerCustomerList($sessionId); 
//get back a list  

//Target a user from your List, Compare Details against your App 
$customerInfo = $proxy->customerCustomerInfo($sessionId, '2'); //Customer Id 

远程操作,如Checkout,可能是相当复杂的。问题依然存在,您希望在应用程序旁边或代表用户使用您的应用程序做什么?

参考文献: http://www.magentocommerce.com/api/soap/customer/customer.list.html http://www.magentocommerce.com/api/soap/customer/customer.info.html

干杯,