以前用laravel写微信支付的回调时直接写成any即可,但是lumen用any会报错,提示你
Call to undefined method Laravel\Lumen\Application::any()
所以lumen框架不支持any的写法
然后我去看了位于vendor/laravel/lumen-framework/src/Routing/Router.ph这个类里面定义的GET,POST等方法,发现所有的请求都是基于当前类里面的addRoute这个方法。
例如:
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function get($uri, $action)
{
$this->addRoute('GET', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function post($uri, $action)
{
$this->addRoute('POST', $uri, $action);
return $this;
}
/**
* Register a route with the application.
*
* @param string $uri
* @param mixed $action
* @return $this
*/
public function put($uri, $action)
{
$this->addRoute('PUT', $uri, $action);
return $this;
}
/**
* Add a route to the collection.
*
* @param array|string $method
* @param string $uri
* @param mixed $action
* @return void
*/
public function addRoute($method, $uri, $action)
{
$action = $this->parseAction($action);
$attributes = null;
if ($this->hasGroupStack()) {
$attributes = $this->mergeWithLastGroup([]);
}
if (isset($attributes) && is_array($attributes)) {
if (isset($attributes['prefix'])) {
$uri = trim($attributes['prefix'], '/').'/'.trim($uri, '/');
}
if (isset($attributes['suffix'])) {
$uri = trim($uri, '/').rtrim($attributes['suffix'], '/');
}
$action = $this->mergeGroupAttributes($action, $attributes);
}
$uri = '/'.trim($uri, '/');
if (isset($action['as'])) {
$this->namedRoutes[$action['as']] = $uri;
}
if (is_array($method)) {
foreach ($method as $verb) {
$this->routes[$verb.$uri] = ['method' => $verb, 'uri' => $uri, 'action' => $action];
}
} else {
$this->routes[$method.$uri] = ['method' => $method, 'uri' => $uri, 'action' => $action];
}
}
看到这里我觉得我可以在路由文件里直接用addRoute这个方法请求,
例如:
$router->addRoute(['GET', 'POST'], 'notify', 'PaymentController@WXNotify');
然后测试一下,ok!