使用Base64解码PHP的结果不一致

时间:2017-11-29 10:00:01

标签: php json base64 linden-scripting-language

我在第二个生命中有一个脚本构建一个json字符串,它是base64编码并发送到PHP脚本。

Login(string action)
{
    string json_string = "{\"Action\": \""+action+"\", \"Name\": \""+simName+"\", \"OwnersKey\": \""+ (string)llGetOwner() +"\", \"ObjectID\": \""+ (string)objectID +"\", \"ParcelName\": \""+ parcelName +"\"}";
    string data = "Data=" + llStringToBase64(json_string);
    toWebPage(data);
}

toWebPage(string params)
{
    params += "&FromSL=true";
    string tst = "";
    if(DEBUG)
    {
        tst = "/tst";
    }
    myRequest = llHTTPRequest(URL + PRODUCTNAME + tst + "/"+controller+".php",
  [HTTP_METHOD, "POST",
   HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
   params);
}

我有两次调用Login脚本。

Login("RegisterTower");

创建json字符串

{"Action": "RegisterTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}

Login("CheckInTower");

创建json字符串

{"Action": "CheckInTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}

这些json字符串以base64编码并发送到php脚本。他们遇到的第一个脚本是Main.php

<?php
include_once "Controller.php";
$params = $_GET;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $params = $_POST;
}
Controller::Process($params);
?>

控制器就是这样

<?php
include_once 'Common.php';
include_once 'Entities.php';
include_once 'Database.php';

<?php
class Controller
{
    public static function Process($data)
    {
        echo base64_decode($data["Data"]);
    }
}
?>

当我检查结果时,我得到了

{"Action": "RegisterTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost Lands~"}
{"Action": "CheckInTower", "Name": "Korzun", "OwnersKey": "8d13fa0f-b54d-43c9-8426-f7cb28f93cfd", "ObjectID": "be4885a4-a596-6a65-925e-470f149e9b63", "ParcelName": "~Lost LandsHŸ

为什么第二个json字符串用

解码
"~Lost LandsHŸ

第一次做的时候

"~Lost Lands~"}

更新:正如Decent Dabble所建议的那样 $ data [“Data”]的内容每次都是

eyJBY3Rpb24iOiAiUmVnaXN0ZXJUb3dlciIsICJOYW1lIjogIktvcnp1biIsICJPd25lcnNLZXkiOiAiOGQxM2ZhMGYtYjU0ZC00M2M5LTg0MjYtZjdjYjI4ZjkzY2ZkIiwgIk9iamVjdElEIjogImJlNDg4NWE0LWE1OTYtNmE2NS05MjVlLTQ3MGYxNDllOWI2MyIsICJQYXJjZWxOYW1lIjogIn5Mb3N0IExhbmRzfiJ9 

eyJBY3Rpb24iOiAiQ2hlY2tJblRvd2VyIiwgIk5hbWUiOiAiS29yenVuIiwgIk93bmVyc0tleSI6ICI4ZDEzZmEwZi1iNTRkLTQzYzktODQyNi1mN2NiMjhmOTNjZmQiLCAiT2JqZWN0SUQiOiAiYmU0ODg1YTQtYTU5Ni02YTY1LTkyNWUtNDcwZjE0OWU5YjYzIiwgIlBhcmNlbE5hbWUiOiAifkxvc3QgTGFuZHN In0=

我现在假设我发布了这个,问题是第二个结尾的空间。我发送的原始数据是

eyJBY3Rpb24iOiAiQ2hlY2tJblRvd2VyIiwgIk5hbWUiOiAiS29yenVuIiwgIk93bmVyc0tleSI6ICI4ZDEzZmEwZi1iNTRkLTQzYzktODQyNi1mN2NiMjhmOTNjZmQiLCAiT2JqZWN0SUQiOiAiYmU0ODg1YTQtYTU5Ni02YTY1LTkyNWUtNDcwZjE0OWU5YjYzIiwgIlBhcmNlbE5hbWUiOiAifkxvc3QgTGFuZHN+In0=

那么我现在如何解决这个问题?

0 个答案:

没有答案