一,通过电子邮箱获取用户token
protected function getCustomerToken($emailId){ /** * @var MagentoCustomerModelCustomer $customer */ */ $customer->loadByEmail($emailId); if($customer->getId()){ /** * @var MagentoIntegrationModelOauthTokenFactory $tokenModelFactory */ $customerToken = $this->tokenModelFactory->create(); $tokenKey = $customerToken->createCustomerToken($customerId)->getToken(); return $tokenKey; } return "YOU MSG FOR CUSTOMER NOT FOUND"; }
二、通过用户名和密码获取token
public function getToken($username,$password)
{
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$token = $objectManager->get('MagentoIntegrationModelAdminTokenService')->createAdminAccessToken($username,$password);
return $token;
}