码迷,mamicode.com
首页 > 其他好文 > 详细

获取后台用户 token 的方法

时间:2017-09-15 11:01:52      阅读:528      评论:0      收藏:0      [点我收藏+]

标签:protect   not   his   print   fun   mod   mint   tin   class   

一,通过电子邮箱获取用户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;
}


获取后台用户 token 的方法

标签:protect   not   his   print   fun   mod   mint   tin   class   

原文地址:http://www.cnblogs.com/shenlongjue/p/7525139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!