联系官方销售客服
1835022288
028-61286886
在httpapi插件中,接口数据使用php代码,我将参数以JSON格式用base64编码后传入,在后台解码后使用,文件的代码如下:
$cans = \Phpcmf\Service::L('input')->get('cans');
$cans = strToUtf8(base64_decode($cans));
$return = [
$get['cxb'] =>$cans.cxb,
$get['cxzd'] =>$cans.cxzd,
$get['cxtj'] =>$cans.cxtj,
];
function strToUtf8($str){
$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
if($encode == 'UTF-8'){
return $str;
}else{
return mb_convert_encoding($str, 'UTF-8', $encode);
}
}
返回数据能正常解码,可数据内容有点怪,请高手帮看看是什么原因。
传入的参数编码前为:{"cxb":"abc","cxzd":["字段A","字段B","字段C"],"cxtj":[{"字段A":">=5","字段C":"DESC"}]}
编码后为:eyJjeGIiOiJhYmMiLCJjeHpkIjpbItfWts5BIiwi19a2zkIiLCLX1rbOQyJdLCJjeHRqIjpbeyLX1rbOQSI6Ij49NSIsItfWts5DIjoiREVTQyJ9XX0=
可返回值变成:{"code":1,"msg":"ok","data":{"":"{\"cxb\":\"abc\",\"cxzd\":[\"字段A\",\"字段B\",\"字段C\"],\"cxtj\":[{\"字段A\":\">=5\",\"字段C\":\"DESC\"}]}cxtj"}}
data中的键名是空,后面又多了个cxtj。
正常的应该是返回 data内容为{\"cxb\":\"abc\",\"cxzd\":[\"字段A\",\"字段B\",\"字段C\"],\"cxtj\":[{\"字段A\":\">=5\",\"字段C\":\"DESC\"}]}才对,为何多出了些东西?
我记得php里面不能写这种点语法吧?