本文共 1002 字,大约阅读时间需要 3 分钟。
测试Yii2.0即接口认证功能(出坑指南):
//认证bindValTap: function () {
var page = this;wx.request({ url: '',header: { 'content-type': 'application/json'},method: 'get',data: { 'per-page': 6,// page: 5},success: function (res) { // page.setData({motto:res.data[0].name});console.log(res.data);}})},
出现Yii2.0 restfut接口认证错误:Your request was made with invalid
研究了很久,后来找到\vendor\yiisoft\yii2\filters\auth\QueryParamAuth.php 中
class QueryParamAuth extends AuthMethod
{ /**
@var string the parameter name for passing the access token
*/public $tokenParam = 'access-token';/**
@inheritdoc
*/public function authenticate($user, $request, $response){ $accessToken = $request->get($this->tokenParam);if (is_string($accessToken)) { $identity = $user->loginByAccessToken($accessToken, get_class($this));if ($identity !== null) { return $identity;}}if ($accessToken !== null) { $this->handleFailure($response);}return null;}
}
才发现传递的参数是access-token,而不是access_token!
转载于:https://blog.51cto.com/13238147/2152076