donglikuang8145 2013-04-16 07:59
浏览 83
已采纳

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

I am using Magento with a 3rd party Java Web Application. My application is "connected" to Magento via Magento SOAP API V2.

How can I perform a Customer Authentication from my Java aplication (outside of Magento) via api?

Any help would be appreciated.

  • 写回答

3条回答 默认 最新

  • doumaji6215 2013-04-23 07:40
    关注

    I came up to a solution on how to login a customer via SOAP API and I will post it here so it can be helpful for others.Here is what I did to make it work:

    1. I created a custom module in Magento with a custom method that login a customer and retuns the sessionID that is set on server side.

      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. I created a Magento Custom Api so I can call my login method via SOAP.

    3. Call the login method from my JAVA app, get the sessionId, then set the cookies on the browser, based on received sessionId. http://yourmagentohost/setCookies.php?sessionId=your_session_id

    And inside setCookies.php you have: setcookie("frontend", $_GET["sessionId"] , time()+3600);

    That's it, now you have a logged in customer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败