-
Notifications
You must be signed in to change notification settings - Fork 44
与PHP通信
0xcc edited this page May 9, 2018
·
1 revision
与第三方接口对接时,大部分提供的是web接口。
这种请求一般会在游戏侧增加一层web接口提供给客户端。
PHPService = CallbackServer:new();
-- 主入口函数。从这里开始lua逻辑
function ServiceInit()
PHPService:Init( "PHP", "tcp" );
PHPService:Listen( 20458 );
end
\BaseService\tools\server\www\
require_once('tools/nel_message.php');
class CPayServiceWeb extends CCallbackClient
{
function cbPay($userId, buyId)
{
$msg = new CMessage;
$msg->setName("CBUP");
$msg->serialUint32($userId);
$msg->serialUint32($buyId);
return parent::sendMessage($msg);
}
function waitCallback()
{
$message = parent::waitMessage();
if ($message == false)
return false;
switch($message->MsgName)
{
case "CBUP_SUCESS":
break;
default:
return false;
}
return true;
}
}
如何使用:
// 验证支付参数
...
// 游戏服发货
$pay_svr = new CPayServiceWeb;
$res = "";
$pay_svr->connect($GameServerIP, $GameServerPort, $res);
$pay_svr->cbPay($pids, $buyId);
if (!$pay_svr->waitCallback())
{
echo 'timeout';
die();
}