Skip to content

Instantly share code, notes, and snippets.

@melice
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melice/9403958 to your computer and use it in GitHub Desktop.
Save melice/9403958 to your computer and use it in GitHub Desktop.
<?php
try {
$reqStr = getInputString();
file_put_contents(__DIR__ . '/callbackService.log', sprintf("%s BODY:%s POST:%s METHOD:%s\n",
date('Y-m-d H:i:s'), $reqStr, json_encode($_POST), $_SERVER['REQUEST_METHOD']), FILE_APPEND);
// logger.info("reqStr:" + reqStr);
if (!empty($reqStr)) {
$json = json_decode($reqStr, true);
$serviceName = $json['serviceName'];
$callPara = $json['callPara'];
if (!empty($serviceName) && !empty($callPara)) {
$ret = null;
/**
* 进行游戏充值
* 调用游戏资产相关函数进行划帐
*/
if ('payGem' == $serviceName) {
/*
* 划拨
* 参数示例:{"serviceName":"payGem","callPara":{"orderId":"b53d29fc-e277-4469-a4af-814e850ef8e2","productType":"1","amount":"1","payType":"1","gameRoleId":"9","timestamp":1352878310509,"verify":"8CFAADCB1119CCE1B9050FAA0B309C93"}}
*
* PP 会根据返回的 JSON 结构中 result,获知划拨是否正常,判断是否进行重试
*
* $ret['result'] -> 0 成功
* $ret['result'] -> >0 失败,不需要重试,返回码由GS自定义。
* $ret['result'] -> <0 失败,需要重试,返回码由GS自定义。
*
*
* echo json_encode($ret);
*
*/
$ret = payGem($callPara);
} else if ('resultMsg' == $serviceName) {
/*
* 异步操作错误提示信息
* 参数示例:{"serviceName":"resultMsg","callPara":{"gameRoleId":"9426","returnCode":"60004","returnMsg":"udid is empty"}}
*/
$ret = resultMsg($callPara);
} else if ('bindEmail' == $serviceName) {
/*
* 邮箱绑定成功通知
* 参数示例:{"serviceName":"bindEmail","callPara":{"gameRoleId":"9426","timestamp":1352878310509,"verify":"8CFAADCB1119CCE1B9050FAA0B309C93"}}
*/
$ret = bindEmail($callPara);
}
if (!empty($ret)) {
// logger.info(ret);
echo json_encode($ret);
} else {
// logger.error("80003:No such method...");
echo '{"result":"80003", "resultMsg":"No such method."}';
}
return;
}
}
// logger.error("80001:Wrong parameters while invoking service...");
echo '{"result":"80001", "resultMsg":"Wrong parameters while invoking service."}';
}
catch (Exception $e) {
// logger.error(e, e);
echo '{"result":"80002", "resultMsg":"Error occur while invoking service."}';
}
/*****************************************************************************/
function getInputString()
{
return @file_get_contents('php://input');
}
function payGem($param)
{
// do pay gem ...
return array(
'result' => 0,
'resultMsg' => 'pay gem success'
);
}
function resultMsg($param)
{
// do result msg
return array(
'result' => 0,
'resultMsg' => 'return msg success'
);
}
function bindEmail($param)
{
// do bind email
return array(
'result' => 0,
'resultMsg' => 'bind email success'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment