首页 > 其他 > 详细

获取后台用户 token 的方法

时间:2017-09-15 10:56:47      阅读:429      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!