我的网站里面有一个数据库,我想从JSON格式的数据库中检索一些非常安全的信息给我的android应用程序。 例如,当我通过我的Android应用程序登录我的网站时,网站安全地将JSON转移给我。 我想确保没有其他人可以解码我的JSON,例如,如果一些黑客可以使用用户凭据登录我的网站,他就无法访问这些安全信息。 我读过一些关于JWT的文章,我真的很困惑。 我真的很感谢你引导我走正确的道路。 json的问题是这样的:当我在我的php代码中添加一些代码以将其从外部隐藏时(只有合法用户可以访问它,我用会话代码执行)json的结果将为null当我连接到android我在Windows中做的时候没有这个问题,也许当我想解析json时,我的android代码有问题,但每当我删除会话部分时,它就完成了。 这是我的安卓代码
public class ParsingJSON {
public static String[] ids;
public static String[] names;
public static String[] passwords;
public static String[] fullnames;
public static String[] emails;
public static String[] otps;
public static final String JSON_ARRAY = "result";
public static final String KEY_ID = "id";
public static final String KEY_NAME = "username";
public static final String KEY_PASSWORD = "password";
public static final String KEY_FULLNAME= "fullname";
public static final String KEY_EMAIL= "email";
public static final String KEY_OTP = "otp";
private JSONArray users = null;
private String json;
public ParsingJSON(String json){
this.json = json;
}
protected String[] ParsingJSON(){
JSONObject jsonObject=null;
try {
jsonObject = new JSONObject(json);
users = jsonObject.getJSONArray(JSON_ARRAY);
Log.v("sharareh:", String.valueOf(users));
ids = new String[users.length()];
names = new String[users.length()];
passwords = new String[users.length()];
fullnames = new String[users.length()];
emails = new String[users.length()];
otps = new String[users.length()];
for(int i=0;i<users.length();i++){
Log.v("sharareh1:", "sharareh");
JSONObject jo = users.getJSONObject(i);
ids[i] = jo.getString(KEY_ID);
names[i] = jo.getString(KEY_NAME);
passwords[i] = jo.getString(KEY_PASSWORD);
fullnames[i] = jo.getString(KEY_FULLNAME);
emails[i] = jo.getString(KEY_EMAIL);
otps[i] = jo.getString(KEY_OTP);
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.v("OTPJSON:", otps[0]);
return otps;
}
这是我的php代码:
<?php
define('HOST', 'x');
define('USER', 'y');
define('PASS', 'z');
define('DB', 'y');
require_once 'totp.class.php';
session_start();
include_once 'include/class.user.php';
$user = new User();
$var_value = $_SESSION['varname'];
echo $var_value;
$user = $var_value;
$con = mysqli_connect(HOST,USER,PASS,DB);
$sql = "select * from users WHERE uemail='$user' ";
$res = mysqli_query($con,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array('id'=>$row[0],
'username'=>$row[1],
'password'=>$row[2],
'fullname'=>$row[3],
'email'=>$row[4],
'otp'=>$row[5]
));
}
echo json_encode(array("result"=>$result));
mysqli_close($con);?>