Open yjtec opened 4 years ago
1、客户端传参的时候(设置options)使用这种方式 $options增加需要的参数,如 $options[]=['token'=>$token]; 然后这样发起请求 $client->$action(...$options); 服务端的$action会接受到所有的$options参数,但其中新增的token会被传递给$action,当有默认值时会引起错误 2、服务端过滤掉自定义的参数 在服务端的onBeforeInvoke方法中去除掉自定义参数,注意其中的args需要使用引用(牛逼hprose作者传递的是引用) $server->onBeforeInvoke = function ($name, &$args, $byref, \stdClass $context) use ($server) { unset($args[索引号]['token']) }; 这样在hprose调用ivoke方法时就不存在这个参数了,调用你自己的方法也就没事了
$options[]=['token'=>$token];
$client->$action(...$options);
$server->onBeforeInvoke = function ($name, &$args, $byref, \stdClass $context) use ($server) { unset($args[索引号]['token']) };
hprose 3.0 中调用的参数通过参数直接传递,公共参数通过 $context->requestHeaders 传递。这样问题就简化了。
3.0在哪??composer里还是2.0啊
master 里面的是 3.0。
1、客户端传参的时候(设置options)使用这种方式 $options增加需要的参数,如
$options[]=['token'=>$token];
然后这样发起请求$client->$action(...$options);
服务端的$action会接受到所有的$options参数,但其中新增的token会被传递给$action,当有默认值时会引起错误 2、服务端过滤掉自定义的参数 在服务端的onBeforeInvoke方法中去除掉自定义参数,注意其中的args需要使用引用(牛逼hprose作者传递的是引用)$server->onBeforeInvoke = function ($name, &$args, $byref, \stdClass $context) use ($server) { unset($args[索引号]['token']) };
这样在hprose调用ivoke方法时就不存在这个参数了,调用你自己的方法也就没事了