Skip to content

Instantly share code, notes, and snippets.

@dvv
Last active April 25, 2020 12:24
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 dvv/294fe96917846a828be3ab14acb34823 to your computer and use it in GitHub Desktop.
Save dvv/294fe96917846a828be3ab14acb34823 to your computer and use it in GitHub Desktop.
Fetch russian shopping cheque contents by its qrcode
package vd.myhome.cheque;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;
public class Cheque {
public Cheque(
final Context context,
String q_t,
String q_fn,
String q_i,
String q_fp,
String q_s,
String q_n,
final String auth
)
{
if (q_t == null || q_fn == null || q_i == null || q_fp == null || q_s == null || q_n == null) {
return;
}
RequestQueue queue = Volley.newRequestQueue(context);
// NB: This is preflight request. It's likely to return 406. Just ignore and go on.
queue.add(new StringRequest(
Request.Method.GET,
String.format(
"https://proverkacheka.nalog.ru:9999/v1/ofds/*/inns/*/fss/%s/operations/%s/tickets/%s?fiscalSign=%s&date=%s&sum=%s",
q_fn, q_n, q_i, q_fp, q_t, q_s
),
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d("myhome/qrcode/cheque/1", response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Log.e("myhome/qrcode/cheque/1", "CHECK: " + error);
}
}
));
// Actual fetch request
queue.add(new StringRequest(
Request.Method.GET,
String.format(
"https://proverkacheka.nalog.ru:9999/v1/inns/*/kkts/*/fss/%s/tickets/%s?fiscalSign=%s&sendToEmail=no",
q_fn, q_i, q_fp
),
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("myhome/qrcode/cheque/2", response);
//---------------------------
// NB: here we have the JSON
TextView textView = (TextView) ((Activity) context).findViewById(R.id.cheque_content);
textView.setText(response);
//---------------------------
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("myhome/qrcode/cheque/2", "FETCH: " + error);
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Device-Id", "Curl");
params.put("Device-Os", "Linux");
params.put("Authorization", "Basic " + auth);
return params;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment