dph19153 2016-08-04 09:31
浏览 50

有没有办法从json格式的网站安全地传输数据到Android应用程序?

I have website that has a database inside, I want to retrieve some really secure information from that database in the format of JSON to my android application. For example when I login to my website through my android application, the website transfer JSON securely to me. I want to make sure no one else could decode my JSON, for example if some hacker could login with user credentials into my website, he could not access this secure information. I have read some articles about JWT and I got really confused. I really appreciate you to lead me through the correct way. The problem with the json was something like this: when I add some code inside my php code to hide it from outside (only legitimate user can access that, I did it with session code) the result of json is going to be null when I connect with android I do not have this problem when I did in in windows, maybe it is something wrong with my android code when I want to pars json, but whenever I delete the session part it worked perfectley. Here is my android code

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;
}

Here is my php code:

<?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);?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制