复制链接

扫一扫

二次开发 自定义输出格式json/xml

API详情
名称:
API接口:
说明:
返回说明:
参数
说明
注释
&api= API接口名称 必填
&BSphpSeSsL= BSphpSeSsL连接Cookies 必填
&date= 服务器时间超时验证 可空,后台设置超时0就是关闭
&mutualkey= 通信认证Key 必填,用作软件数据包交换数据验证串
&appsafecode= 封包劫持检测 可空,客户端提交参数给服务器时候原样返回
&md5= 程序MD5 可空,后台MD5内容要为空

说明:绿色公共参数每个接口都有的,蓝色当前接口私有参数.

软件和服务器通信过程中会使用到JSON/XML格式。

BSPHP完全支持二次开发自己的输出格式

BSPHP格式目录:include/applibapi/output

可以自行打开文件进行编辑修改,建议重命名不影响升级!
文件名:bsphp_josn.php
函数名字:bsphp_josn_bsphp_output


命明格式:
文件名:bsphp自己定名称.php
函数名字:bsphp自己定名称_bsphp_output

  1. <?php
  2. header("Content-type: application/json; charset=utf-8");
  3. /**
  4. * 输出文件
  5. *
  6. * * 文件名_bsphp_output(显示内容) 输出显示函数
  7. */
  8. /**
  9. * @输出给客户端mxl格式文件
  10. */
  11. function bsphp_josn_bsphp_output($data, $code)
  12. {
  13. $data = json_encode($data);
  14. $microtime = Plug_Execute_Time();
  15. $sginstr = str_replace(
  16. '[KEY]',
  17. $data .
  18. PLUG_DATE() .
  19. PLUG_UNIX() .
  20. $microtime .
  21. Plug_Set_Data('appsafecode'),
  22. PLUG_DATA_TOSGIN()
  23. );
  24. $key = PLUG_DATA_TOSGIN();
  25. $sgin_md5 = md5($sginstr);
  26. #签名调试记录日志
  27. Plug_Dbug_update("`to_sigm_key`='{$key}',`to_sigm_txt` = '{$sginstr}',`to_sigm_md5`='{$sgin_md5}' ");
  28. $json_array = array();
  29. $json_array['response']['data'] = $data; //数据内容
  30. $json_array['response']['code'] = $code; //数据内容编码代号
  31. $json_array['response']['SeSsL'] = session_id(); //session/BSphpSeSsL
  32. $json_array['response']['unix'] = PLUG_UNIX(); //系统时间
  33. $json_array['response']['date'] = PLUG_DATE(); //系统时间
  34. $json_array['response']['microtime'] = $microtime; //执行时间
  35. $json_array['response']['appsafecode'] = Plug_Set_Data('appsafecode'); //原样返回安全代码
  36. $json_array['response']['sgin'] = $sgin_md5; //签名
  37. $data = json_encode($json_array, JSON_UNESCAPED_UNICODE);
  38. return ($data);
  39. }

xml格式

  1. <?php
  2. /**
  3. * 输出文件
  4. *
  5. * * 文件名_bsphp_output(显示内容) 输出显示函数
  6. */
  7. /**
  8. * @输出给客户端mxl格式文件
  9. */
  10. function bsphp_xml_bsphp_output($data, $code)
  11. {
  12. if (is_array($data)) {
  13. //参数修改
  14. $code_array_php = '';
  15. foreach ($data as $param_value => $key) {
  16. $key = addslashes($key);
  17. $code_array_php .= "<$param_value>$key</$param_value>";
  18. }
  19. $data = $code_array_php;
  20. }
  21. $microtime = Plug_Execute_Time();
  22. $sginstr = str_replace('[KEY]', $data . PLUG_DATE() . PLUG_UNIX() . $microtime . Plug_Set_Data('appsafecode'), Plug_App_DaTa('app_tosgin'));
  23. $sgin_md5 = md5($sginstr);
  24. $str = iconv("UTF-8", "gbk//TRANSLIT", $sginstr);
  25. $sgin_md52 = md5($str);
  26. #签名调试记录日志
  27. $sgin_md5all = "Utf8:{$sgin_md5}/GBK:{$sgin_md52}";
  28. $key = Plug_App_DaTa('app_tosgin');
  29. Plug_Dbug_update("`to_sigm_key`='{$key}',`to_sigm_txt` = '{$sginstr}',`to_sigm_md5`='{$sgin_md5all}' ");
  30. $data = "<?xml version="1.0" encoding="utf-8"?><response><data>{$data}</data><code>{$code}</code><date>" . PLUG_DATE() . "</date><unix>" . PLUG_UNIX() . "</unix><microtime>" . $microtime . "</microtime><appsafecode>" . Plug_Set_Data('appsafecode') . "</appsafecode><sgin>" . $sgin_md5 . "</sgin><sgin2>" . $sgin_md52 . "</sgin2></response>";
  31. return ($data);
  32. }
调用接口指引
标准调用 前往查看 标准POST/GET传递调用,无加密等配置
在线调试 前往ApiDbug工具 在线调试工具快速模拟客户端环境调试,需要配置软件信息
SDK调用 点击下载演示 加密通信案例参考调用