首页 文章

通过API进行Magento客户身份验证

提问于
浏览
2

我正在使用Magento和第三方Java Web应用程序 . 我的应用程序通过Magento SOAP API V2与Magento“连接” .

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

任何帮助,将不胜感激 .

3 回答

  • -2

    我找到了一个如何通过SOAP API登录客户的解决方案,我将在此处发布,以便对其他人有所帮助 . 这就是我为使其工作所做的事情:

    • 我使用自定义方法在Magento中创建了一个自定义模块,该方法登录客户并返回在服务器端设置的 sessionID .
    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;
    }
    
    • 我创建了Magento Custom Api所以我可以通过SOAP调用我的登录方法 .

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

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

    就是这样,现在你已经登录了客户 .

  • 4

    如何通过api从我的Java应用程序(Magento之外)执行客户身份验证? SOAP API V2

    澄清:API用户(至少是Soap)和Customer是两种用户类型 . 如果您有一个预先存在的用户列表,并且想要查看它们是否作为Magento内部的用户存在,您可以检索电子邮件帐户及其相关属性和相应的密码哈希值(CE:md5:salt或CE / EE:sha :salt)全部通过SOAP . 如果您希望进行比较操作,则需要对密码实施相同的哈希,以进行1:1比较 . 如果您希望让您的应用程序使用SOAP直接执行操作,我会确保存在一个抽象层,因为您的应用程序可能会被恶意地用于其他用户ID,这取决于Magento管理员中设置的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

    干杯,

  • 1

    您的代码示例不使用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

相关问题