我正在将 Magento 与第 3 方 Java Web 应用程序一起使用。我的应用程序通过 Magento SOAP API V2 “连接”到 Magento。
如何通过 api 从我的 Java 应用程序(Magento 之外)执行客户身份验证?
任何帮助,将不胜感激。
我想出了一个关于如何通过 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);
就是这样,现在您有一个登录的客户。
如何通过 api 从我的 Java 应用程序(Magento 之外)执行客户身份验证?SOAP API V2
澄清:API 用户(至少是 Soap)和客户是两种用户类型。如果您有一个预先存在的用户列表,并且正在寻找他们是否作为用户在 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
远程操作,如结帐,可能相当复杂。问题仍然存在,您希望在您的应用程序旁边或代表用户做什么?
参考资料: http: //www.magentocommerce.com/api/soap/customer/customer.list.html http://www.magentocommerce.com/api/soap/customer/customer.info.html
干杯,
您的代码示例不使用 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