获取后台用户 token 的方法


一,通过电子邮箱获取用户token

protected function getCustomerToken($emailId){ /** * @var \Magento\Customer\Model\Customer $customer */ */ $customer->loadByEmail($emailId); if($customer->getId()){ /** * @var \Magento\Integration\Model\Oauth\TokenFactory $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 = \Magento\Framework\App\ObjectManager::getInstance();
$token = $objectManager->get('\Magento\Integration\Model\AdminTokenService')->createAdminAccessToken($username,$password);
return $token;
}



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM