79 lines
3.5 KiB
PHP
79 lines
3.5 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: abcdefg
|
||
* Date: 2016-08-08
|
||
* Time: 9:29
|
||
*/
|
||
require_once __DIR__ . '/common/common.inc.php';
|
||
|
||
/// html header.
|
||
header("Access-Control-Allow-Origin: *");
|
||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
||
header("Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With");
|
||
header("Access-Control-Allow-Credentials: true");
|
||
header("Content-Type: text/html; charset=utf-8");
|
||
|
||
///
|
||
///date_default_timezone_set('PRC');
|
||
date_default_timezone_set('Asia/Shanghai');
|
||
|
||
|
||
/// 请求参数
|
||
/// app_id: 【未使用】appid
|
||
/// developer_id: 【未使用】开发者身份信息
|
||
/// method: 【必须】模块名(包.类.方法)
|
||
/// format: 【必须】格式(json)
|
||
/// charset: 【必须】编码(utf-8)
|
||
/// timestamp: 【必须】调用方的时间戳
|
||
/// version: 【必须】模块对应的版本
|
||
/// notify_url: 【可选】回调地址(如需要,接口会通过指定的该地址通知调用方)
|
||
/// user_auth_token: 【非必须】用户授权信息,操作员/用户身份信息(除部分指定接口外、每次接口调用前都会校验该参数)
|
||
/// app_auth_token: 【未使用】应用授权信息
|
||
/// biz_content: 【必须】包体,模块对应需要的参数。
|
||
/// random_string: 【可选】随机字符串
|
||
/// tag: 【可选】附带参数,服务器不处理,只返回
|
||
/// signature: 【未校验】包体的签名值
|
||
|
||
/// https://localhost?method=test.test.test_1&format=json&charset=utf-8×tamp=1&version=1.0&biz_content={"a":"a","b":"b"}&user_auth_token=xxxxxxxx&tag=tag&random_string=xxxxxx
|
||
|
||
|
||
/// 响应参数
|
||
/// retcode: 【必须】返回值(0为成功,非0失败)
|
||
/// retinfo: 【必须】返回信息(当接口执行错误时,即retcode为非0时,由该域返回详细的错误信息。)
|
||
/// user_auth_token: 【必须】用户授权信息(自用),操作员/用户身份信息(当接口被成功调用则会返回一个新的授权码用于下次调用。)
|
||
/// app_auth_token: 【必须】应用授权信息(自用)
|
||
/// biz_content: 【必须】接口返回信息(当接口执行成功时,即retcode为0时,由该域返回详细数据。)
|
||
/// tag: 【可选】附带参数,服务器不处理,只返回
|
||
/// signature: 【必须】包体的签名值
|
||
|
||
|
||
$app = new OpenAPITrunk(); /// 创建对象
|
||
if (ERRORCODE_SUCCESS == $app->GetErrorCode()) /// errorcode不等于errorcode_success表示创建对象过程中出错(连接redis出错)
|
||
{
|
||
$return = $app->DispatchProcedure($_REQUEST);
|
||
if (null == $return->biz_content)
|
||
$return->biz_content = (object)null;
|
||
$app = null;
|
||
|
||
if (DEBUG_MODE)
|
||
{
|
||
OutputDebugMessage('request ==> ' . ObjectToLinkString($_REQUEST) . PHP_EOL . 'return ==> ' . JsonObjectToJsonString($return));
|
||
die(JsonObjectToJsonString($return));
|
||
}
|
||
else
|
||
die(rawurlencode(JsonObjectToJsonString($return)));
|
||
}
|
||
else
|
||
{
|
||
$return = new ReturnParameter(array('retcode' => $app->GetErrorCode(), 'retinfo' => $app->GetErrorInfo()));
|
||
$return->RefreshSignature(SIGN_KEY);
|
||
OutputDebugMessage('request ==> ' . ObjectToLinkString($_REQUEST) . PHP_EOL . 'return ==> ' . JsonObjectToJsonString($return));
|
||
if (DEBUG_MODE)
|
||
die(JsonObjectToJsonString($return));
|
||
else
|
||
die(rawurlencode(JsonObjectToJsonString($return)));
|
||
}
|
||
|
||
|