Menu

Frequently Asked Questions (API)

This article was last updated 37 days ago, please note whether the content is still available

Output Custom JSON Format (Supported in 1.7.2)

The system API defaults to outputting JSON content with fields code, data, error, and message.

How to output custom fields? For example, outputting errno, msg fields:

//Define the return array within the API output function like this

$array['errno'] = 0;
$array['msg'] = 'success';
$array['data']['isConsumed'] = 2;

return array('json' => $array);

Output XML Format and Other Data Formats (Supported in 1.7.2)

The system API defaults to JSON format. How to output other data formats:

//Define the return array within the API output function like this
$array

$array['raw'] = '0okxml info';
$array['raw-type'] = 'text/xml';

return $array;

Skip CSRF Token Verification When Accessing API Anonymously (POST Request)

If you define a newapi/submit API for non-logged-in users to use via POST, you need to append csrf_token to the API's URL. If you do not want to use csrf_token,

you can use the interface settings to bypass CSRF token verification.

Add_Filter_Plugin('Filter_Plugin_API_VerifyCSRF_Skip', 'newapi_IgnoreCSRF');

function newapi_IgnoreCSRF(&$array)
{
  $array[] = array('mod' => 'newapi', 'act' => 'submit');
}

Apache Cannot Get Authorization Header Information

Modify the .htaccess file and add the following information:

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]

Helpful?

Comments(2)

剑影孤行
剑影孤行

2025-10-10 10:54:14

文章详细介绍了如何自定义JSON输出格式、输出XML等格式数据、处理匿名访问API时的CSRF验证问题以及Apache获取不到Authorization头信息的解决方案。
剑影寒月
剑影寒月

2025-10-10 10:50:56

文章详细介绍了如何自定义JSON输出格式、输出其他格式的数据、跳过CSRF验证以及解决Apache获取不到Authorization头信息的问题。

Post comment

Support Live Chat
TOP