测试Yii2.0即接口认证功能(出坑指南):
//认证
bindValTap: function () {
var page = this;
wx.request({
url: ‘http://apitest.test/invmembers?access-token=rg1v5BF7OBGE4Bze562wZSUfiStakUK_‘,
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!
原文地址:http://blog.51cto.com/13238147/2152076
时间: 2024-10-13 11:17:32