Esempio n. 1
0
 private <T> String getOtpPassword(DocumentAccess docAcc) throws Exception {
   Properties prop = new Properties();
   File file = new File(System.getProperty("catalina.base") + "/conf/merch.properties");
   FileInputStream fis = new FileInputStream(file);
   prop.load(fis);
   OtpPassword otp = new OtpPassword();
   otp.setMerchant_id(prop.getProperty("merchant_id"));
   otp.setMerchant_password(prop.getProperty("merchant_password"));
   fis.close();
   OtpCreate otpCreate = new OtpCreate();
   otpCreate.setCategory("qwerty");
   otpCreate.setFrom("10060");
   if (!docAcc.getTelephone().isEmpty() || docAcc.getTelephone() != null) {
     otpCreate.setPhone(docAcc.getTelephone());
   } else {
     otpCreate.setPhone("null");
   }
   SmsTemplate smsTemplate1 = new SmsTemplate();
   smsTemplate1.setText("text:" + "Parol: ");
   smsTemplate1.setPassword("password:"******"2");
   SmsTemplate smsTemplate2 = new SmsTemplate();
   smsTemplate2.setText("text:" + "-");
   smsTemplate2.setPassword("password:"******"2");
   SmsTemplate smsTemplate3 = new SmsTemplate();
   smsTemplate3.setText("text:" + "-");
   smsTemplate3.setPassword("password:"******"2");
   SmsTemplate smsTemplate4 = new SmsTemplate();
   smsTemplate4.setText("text:" + "-");
   smsTemplate4.setPassword("password:"******"2");
   List<T> list = new ArrayList<T>();
   list.add((T) new OtpText("Parol:"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   otpCreate.setSms_template(list);
   List<OtpCreate> listOtpCreate = new ArrayList<>();
   listOtpCreate.add(otpCreate);
   otp.setOtp_create(listOtpCreate);
   Gson g = new Gson();
   String jsonObj = g.toJson(otp);
   URL url = new URL(urlConn);
   HttpURLConnection con = (HttpURLConnection) url.openConnection();
   con.setRequestMethod("POST");
   con.setRequestProperty("content-type", "application/json;charset=UTF-8");
   con.setDoOutput(true);
   DataOutputStream dos = new DataOutputStream(con.getOutputStream());
   dos.writeBytes(jsonObj);
   dos.flush();
   dos.close();
   BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
   StringBuilder sb = new StringBuilder();
   String inputLine;
   while ((inputLine = br.readLine()) != null) {
     sb.append(inputLine);
   }
   br.close();
   return sb.toString();
 }
Esempio n. 2
0
  private <T> String sendPasswordOTP(String sPhone, String sPassword) throws Exception {
    Properties oProperties = new Properties();
    File oFile = new File(System.getProperty("catalina.base") + "/conf/merch.properties");
    FileInputStream oFileInputStream = new FileInputStream(oFile);
    oProperties.load(oFileInputStream);
    oFileInputStream.close();

    OtpPassword oOtpPassword = new OtpPassword();
    oOtpPassword.setMerchant_id(oProperties.getProperty("merchant_id"));
    oOtpPassword.setMerchant_password(oProperties.getProperty("merchant_password"));

    OtpCreate oOtpCreate = new OtpCreate();
    oOtpCreate.setCategory("qwerty");
    oOtpCreate.setFrom("10060");
    oOtpCreate.setPhone(sPhone);
    /*SmsTemplate oSmsTemplate = new SmsTemplate();
    oSmsTemplate.setText("text:"+"Parol: ");
    oSmsTemplate.setPassword("password:"******"2");
    SmsTemplate oSmsTemplate2 = new SmsTemplate();
    oSmsTemplate2.setText("text:"+"-");
    oSmsTemplate2.setPassword("password:"******"2");
    SmsTemplate oSmsTemplate3 = new SmsTemplate();
    oSmsTemplate3.setText("text:"+"-");
    oSmsTemplate3.setPassword("password:"******"2");
    SmsTemplate oSmsTemplate4 = new SmsTemplate();
    oSmsTemplate4.setText("text:"+"-");
    oSmsTemplate4.setPassword("password:"******"2");*/
    List<T> a = new ArrayList<T>();
    a.add((T) new OtpText("Parol:"));
    a.add((T) new OtpPass(sPassword));
    /*a.add((T)new OtpPass("2"));
    a.add((T)new OtpText("-"));
    a.add((T)new OtpPass("2"));
    a.add((T)new OtpText("-"));
    a.add((T)new OtpPass("2"));
    a.add((T)new OtpText("-"));
    a.add((T)new OtpPass("2"));*/
    oOtpCreate.setSms_template(a);
    List<OtpCreate> aOtpCreate = new ArrayList<>();
    aOtpCreate.add(oOtpCreate);
    oOtpPassword.setOtp_create(aOtpCreate);
    Gson oGson = new Gson();
    String jsonObj = oGson.toJson(oOtpPassword);
    URL oURL = new URL(urlConn);
    HttpURLConnection oHttpURLConnection = (HttpURLConnection) oURL.openConnection();
    oHttpURLConnection.setRequestMethod("POST");
    oHttpURLConnection.setRequestProperty("content-type", "application/json;charset=UTF-8");
    oHttpURLConnection.setDoOutput(true);
    DataOutputStream oDataOutputStream = new DataOutputStream(oHttpURLConnection.getOutputStream());
    oDataOutputStream.writeBytes(jsonObj);
    oDataOutputStream.flush();
    oDataOutputStream.close();

    BufferedReader oBufferedReader =
        new BufferedReader(new InputStreamReader(oHttpURLConnection.getInputStream()));
    StringBuilder os = new StringBuilder();
    String s;
    while ((s = oBufferedReader.readLine()) != null) {
      os.append(s);
    }
    oBufferedReader.close();
    return os.toString();
  }