php框架中使用mcpack进行发包

需要进行一下操作

1. 直接在框架入口module.php设置对应参数,设置配置

public static function test()
{
static $as = null;
if ($as === null) {
$as = new As_Client(Newapi_Conf_Common::$asServer);
}
return $as;
}
Env::set('NewapiAS',NewapiModule::test());

然后增加配置:

public static $asServer = array("host"=>array("121.40.104.68"), "port"=>1527, "timeout"=>0.5);

2. 调用对应的mcpack访问接口
创建头

protected function create_simple_asreq()
{
$as_head = array();
$as_head['id'] = 0x01;
$as_head['provider'] = "request";
$as_head['version'] = 0x100;
$as_req = array(
"head" => $as_head,
"request_body" => array()
);
return $as_req;
}

执行访问:

$as = Env::get('NewapiAS');
$retry = 0;
$times = 2;
$req = $this->create_simple_asreq();
$req['request_body'] = array("type" => 2);
do {
try{
$res = $as->query($req);
break;
}catch (Exception $ex){
if(1+$retry >= $times){
throw new Exception("as back error!");
}
}

}while(++$retry < $times);
var_dump($res);exit(1);

发表评论

电子邮件地址不会被公开。 必填项已用*标注