Php 客户未在magento中以编程方式登录
我正在尝试在magento中以编程方式登录客户。我使用了curl并在magento中开发了soap api 要求:我有两个网站,一个在laravel,另一个在magento,所有的电子邮件和密码都设置在这两个网站上。当用户登录到laravel网站时,客户必须登录到magento网站,反之亦然。单一登录概念 使用Soap Api,将参数电子邮件和密码传递给我的Soap客户端。代码如下:Php 客户未在magento中以编程方式登录,php,magento,curl,soap,login,Php,Magento,Curl,Soap,Login,我正在尝试在magento中以编程方式登录客户。我使用了curl并在magento中开发了soap api 要求:我有两个网站,一个在laravel,另一个在magento,所有的电子邮件和密码都设置在这两个网站上。当用户登录到laravel网站时,客户必须登录到magento网站,反之亦然。单一登录概念 使用Soap Api,将参数电子邮件和密码传递给我的Soap客户端。代码如下: class Axovel_Customlogin_Model_Custom_Api extends Mage_A
class Axovel_Customlogin_Model_Custom_Api extends Mage_Api_Model_Resource_Abstract
{
public function login($email,$password) {
$login_customer_result = Mage::getModel('customer/customer')->setWebsiteId(1)->authenticate($email, $password);
if ($login_customer_result == 1) {
Mage::getSingleton("core/session", array("name" => "frontend"));
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
try {
$customer->loadByEmail($email);
//$session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
$session = Mage::getSingleton('customer/session');
$session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
return $session->getSessionId();
}catch(Exception $e){
echo $e;
}
}
}
}
通过soap调用调用此方法,它将返回会话id,并对客户进行身份验证,但不在前端登录客户
我尝试了curl调用customer模块的loginPost操作并传递表单键,下面是curl代码:
$string = "login[username]=xyz@mymail.com&login[password]=123456&form_key=B3pr9GSMp75kwW20";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/performer/index.php/customer/account/loginPost');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id());
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_HEADER, true);
$output = (string) curl_exec($ch);
这也将工作没有任何错误,但客户没有登录
我已经使用action在magento根目录上创建了html表单
http://127.0.0.1/performer/index.php/customer/account/loginPost
文本字段是电子邮件、密码和formkey,在提交表单时,它将成功登录到magento
但无法使用api和curl登录。请尝试$session->loginById和$session->设置CustomerLoggeDin: 摘自我过去的一个项目:
$session = Mage::getSingleton( 'customer/session' );
try
{
$session->loginById( $customer->getId());
$session->setCustomerAsLoggedIn( $session->getCustomer() );
}
catch( Exception $e )
{
return false;
}
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/index'));
@用户5493921我刚刚又看了一遍你最初的问题。看起来您正在使用SOAP调用此代码?这意味着$session变量被设置为SOAP会话,而不是用户的会话?用户需要在浏览器中调用此选项才能正确登录。将它们路由到使用此登录代码的URL,并适当地重定向它们。