Skip to content

Instantly share code, notes, and snippets.

@hungdh0x5e
Created March 2, 2016 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hungdh0x5e/58ee362e8b18946f938c to your computer and use it in GitHub Desktop.
Save hungdh0x5e/58ee362e8b18946f938c to your computer and use it in GitHub Desktop.
private void sendRequest(int zodiacID, int gender) {
JSONObject params = new JSONObject();
try {
params.put(PARAM_ZODIAC_ID, String.valueOf(zodiacID));
params.put(PARAM_GENDER_ID, String.valueOf(gender));
params.put(PARAM_DATE, mDate);
} catch (JSONException e) {
e.printStackTrace();
}
url += Func.decrypt(CIPHER_URL, new String[]{KEY_URL_1, KEY_URL_2});
JsonObjectRequest objReq = new JsonObjectRequest(Request.Method.POST, url, params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "Response: " + response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.d(TAG, "Server Error: " + volleyError.toString());
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("apikey", Func.decrypt(CIPHER_KEY, new String[]{KEY_KEY_1, KEY_KEY_2})); // e090ee4b74cf2ec5cds1sad2f3sdc
return headers;
}
};
AppController.getInstance().addToRequestQueue(objReq);
}
<?php
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}
$body = file_get_contents('php://input');
$postvars = json_decode($body, true);
$headers = apache_request_headers();
$apiKey = "apikey";
if(isset($headers[$apiKey])){
if($headers[$apiKey]=="e090ee4b74cf2ec5cds1sad2f3sdc"){
$response['status'] = TRUE;
$response["data"]="Response data";
}else{
$response['status'] = FALSE;
$response["message"]="invalid api key";
}
}else{
$response['status'] = FALSE;
$response["message"]="Vui lòng cập nhật ứng dụng";
}
echo json_encode($response);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment