Magento SOAP客户身份验证?

时间:2013-11-20 10:17:45

标签: php magento soap

我目前正在寻找创建一个与Magento商店集成的移动应用程序,并设法使用SOAP API(例如检索产品和类别)使其工作的许多方面。

我现在正在寻找一个问题,我需要移动应用程序的用户使用他们的Magento客户登录详细信息登录,但是通过SOAP API查找实际客户无法登录的方法?

有没有人知道如何执行此任务。

由于

2 个答案:

答案 0 :(得分:9)

实际上,在您的案例中,很容易对客户进行身份验证。客户信息SOAP响应为我们提供了在Magento中注册的用户的password_hash。此哈希是一个md5哈希,可以使用用户将在系统中输入的密码输入密码进行身份验证。我有一个示例代码,希望这有助于任何人寻找这个答案。

$complexFilter = array(
    'complex_filter' => array(
        array(
            'key' => 'email',
            'value' => array('key' => 'eq', 'value' => 'someemail@gmail.com')
        )
    )
);
$result = $proxy->customerCustomerList($sessionId, $complexFilter);

var_dump($result);

/**
 * Validate hash against hashing method (with or without salt)
 *
 * @param string $password
 * @param string $hash
 * @return bool
 */
function validateHash($password, $hash)
{
    $hashArr = explode(':', $hash);

    switch (count($hashArr)) {
        case 1:
            return md5($password) === $hash;
        case 2:
            return md5($hashArr[1] . $password) === $hashArr[0];
    }
}

var_dump(validateHash('asdfgh',$result[0]->password_hash));

答案 1 :(得分:0)

经过一些试验和错误以及更多研究后,我设法提出了这个解决方案,现在允许我对Magento的用户名和密码进行身份验证。

它涉及创建一个PHP脚本,我已经上传到Magento网站目前它是一个概念证明,但我会添加一些更多的安全性,例如手机通过SSL发送请求的唯一哈希密钥,这个连同用户名和密码将验证并获得Magento会话。

<?php
header('Content-Type: application/json');

// Get Post Vars
$username = addslashes($_REQUEST['username']);
$password = addslashes($_REQUEST['password']);

if ($username == "") {
    echo json_encode(array('error','Access Denied'));
    die();
}

if ($password == "") {
    echo json_encode(array('error','Access Denied'));
    die();
}

// Mage Path
require_once( dirname(__FILE__).'/app/Mage.php' );

// Initialize Magento ...
Mage::app("default");

$id = 1;  // The Store ID.
$session = Mage::getSingleton('customer/session');

$status = true;
try {
    $session->login($username, $password);
    $session->setCustomerAsLoggedIn($session->getCustomer());
}catch ( Exception $e) {
    $status = false;
}

if ($status == true) {
    $userID = Mage::getSingleton('customer/session')->getId();
    echo json_encode(array('status' => 1, 'userID' => $userID));
} else {
    echo json_encode(array('status' => 0, 'message' => 'Access Denied'));
}

&GT;