diff --git a/common/src/main/java/org/phoenixctms/ctsms/util/CommonUtil.java b/common/src/main/java/org/phoenixctms/ctsms/util/CommonUtil.java
index 35acc698d4ab..2d42bab26ce9 100644
--- a/common/src/main/java/org/phoenixctms/ctsms/util/CommonUtil.java
+++ b/common/src/main/java/org/phoenixctms/ctsms/util/CommonUtil.java
@@ -256,6 +256,8 @@ public final void remove() {
private static final String HEX_DIGITS = "0123456789ABCDEF";
public final static String GIF_FILENAME_EXTENSION = "gif";
public static final String GIF_MIMETYPE_STRING = "image/gif";
+ public static final String PNG_FILENAME_EXTENSION = "png";
+ public static final String PNG_MIMETYPE_STRING = "image/png";
public static final String HTML_MIMETYPE_STRING = "text/html";
public static final String BEACON_PATH = "beacon";
public static final String UNSUBSCRIBE_PATH = "unsubscribe";
diff --git a/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPAuthenticator.java b/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPAuthenticator.java
index f9f9e201faff..d6405cae5342 100644
--- a/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPAuthenticator.java
+++ b/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPAuthenticator.java
@@ -111,8 +111,8 @@ protected Map createTemplateModel(Map messageParameters, Object vo) throws Excep
Settings.getString(SettingCodes.APPLICATION_ABBREVIATION, Bundle.SETTINGS, null));
model.put(
OTPRegistrationInfoMessageTemplateParameters.INSTANCE_NAME, Settings.getInstanceName());
- // model.put(
- // OTPRegistrationInfoMessageTemplateParameters.HTTP_BASE_URL, Settings.getHttpBaseUrl());
+ model.put(
+ OTPRegistrationInfoMessageTemplateParameters.HTTP_BASE_URL, Settings.getHttpBaseUrl());
//model.put(
// OTPRegistrationInfoMessageTemplateParameters.HTTP_DOMAIN_NAME, Settings.getHttpDomainName());
model.put(OTPRegistrationInfoMessageTemplateParameters.TEMPLATE_ENCODING, TEMPLATE_ENCODING);
diff --git a/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPRegistrationInfoMessageTemplateParameters.java b/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPRegistrationInfoMessageTemplateParameters.java
index 7aa124e31a55..3bafbf1f67eb 100644
--- a/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPRegistrationInfoMessageTemplateParameters.java
+++ b/core/src/main/java/org/phoenixctms/ctsms/security/otp/OTPRegistrationInfoMessageTemplateParameters.java
@@ -6,6 +6,7 @@ public interface OTPRegistrationInfoMessageTemplateParameters {
public static final boolean TEMPLATE_MODEL_LOWER_CASE_FIELD_NAMES = true;
public static final String OTP_SECRET = "otp_secret";
public static final String INSTANCE_NAME = "instance_name";
+ public static final String HTTP_BASE_URL = "http_base_url";
//public static final String HTTP_DOMAIN_NAME = "http_domain_name";
public static final String APPLICATION_ABBREVIATION = "application_abbreviation";
public static final Object STRING_UTILS = "string_utils";
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ar.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ar.vsl
index 20c148d51624..3d4bdc6dd13e 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ar.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ar.vsl
@@ -9,7 +9,7 @@
2. افتح التطبيق لتسجيل حسابك $application_abbreviation (امسح رمز الاستجابة السريعة أدناه).
-
+
|
3. استخدم التطبيق لإنشاء رمز التحقق المطلوب.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-da.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-da.vsl
index 5b058760836f..c7c503b81926 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-da.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-da.vsl
@@ -9,7 +9,7 @@
2. Åbn appen for at registrere din $application_abbreviation -konto (scan QR-koden nedenfor).
|
-
+
|
3. Brug appen til at generere den anmodede bekræftelseskode.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-de.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-de.vsl
index 6df515fe078e..a47c9f360af1 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-de.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-de.vsl
@@ -9,7 +9,7 @@
2. Die App öffnen und Ihren $application_abbreviation Zugang registrieren (QR Code scannen).
|
-
+
|
3. Mit der App den angeforderten Bestätigungscode erzeugen.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-es.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-es.vsl
index 21d07ccfb4b4..5865878e9cb8 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-es.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-es.vsl
@@ -9,7 +9,7 @@
2. Abra la aplicación para registrar su cuenta $application_abbreviation (escanee el código QR a continuación).
|
-
+
|
3. Utilice la aplicación para generar el código de verificación solicitado.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ff.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ff.vsl
index 1c81e2606da9..90ccea8a53c4 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ff.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ff.vsl
@@ -9,7 +9,7 @@
2. Open the app to register your $application_abbreviation account (scan QR code below).
|
-
+
|
3. Use the app to generate the requested verification code.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fi.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fi.vsl
index 7c6097ffcec9..ad0215a41519 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fi.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fi.vsl
@@ -9,7 +9,7 @@
2. Avaa sovellus rekisteröidäksesi $application_abbreviation -tilisi (skannaa QR-koodi alla).
|
-
+
|
3. Luo pyydetty vahvistuskoodi sovelluksella.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fr.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fr.vsl
index bdfa1024a2d6..8a6185a79af3 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fr.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-fr.vsl
@@ -9,7 +9,7 @@
2. Ouvrez l'application pour enregistrer votre compte $application_abbreviation (scannez le code QR ci-dessous).
|
-
+
|
3. Utilisez l'application pour générer le code de vérification demandé.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hi.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hi.vsl
index 339f701a574a..318e833e6b1a 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hi.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hi.vsl
@@ -9,7 +9,7 @@
2. अपना $application_abbreviation खाता पंजीकृत करने के लिए ऐप खोलें (नीचे QR कोड स्कैन करें)।
|
-
+
|
3. अनुरोधित सत्यापन कोड उत्पन्न करने के लिए ऐप का उपयोग करें।
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hr.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hr.vsl
index 9891a4ff78f2..928a1c29b00e 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hr.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hr.vsl
@@ -9,7 +9,7 @@
2. Otvorite aplikaciju da registrirate svoj $application_abbreviation račun (skenirajte QR kod ispod).
|
-
+
|
3. Koristite aplikaciju za generiranje traženog kontrolnog koda.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hu.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hu.vsl
index 41d0973ddfd8..56fdde547517 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hu.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-hu.vsl
@@ -9,7 +9,7 @@
2. Nyissa meg az alkalmazást a $application_abbreviation fiók regisztrálásához (olvassa be a QR-kódot lent).
|
-
+
|
3. Használja az alkalmazást a kért ellenőrző kód létrehozásához.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ig.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ig.vsl
index 52e52a1d70c6..79140c611832 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ig.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ig.vsl
@@ -9,7 +9,7 @@
2. Mepee ngwa ahụ ka ịdebanye aha $application_abbreviation akaụntụ gị (nyochaa koodu QR n'okpuru).
|
-
+
|
3. Jiri ngwa ahụ mepụta koodu nkwenye achọrọ.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-it.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-it.vsl
index 100cadf20410..af94851c7c53 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-it.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-it.vsl
@@ -9,7 +9,7 @@
2. Apri l'app per registrare il tuo account $application_abbreviation (scansiona il codice QR di seguito).
|
-
+
|
3. Utilizza l'app per generare il codice di verifica richiesto.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ja.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ja.vsl
index a12fcc25f76b..5878443ac1c0 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ja.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ja.vsl
@@ -9,7 +9,7 @@
2. アプリを開いて $application_abbreviation アカウントを登録します (下の QR コードをスキャンしてください)。
|
-
+
|
3. アプリを使用して、要求された確認コードを生成します。
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-kg.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-kg.vsl
index 1c81e2606da9..90ccea8a53c4 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-kg.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-kg.vsl
@@ -9,7 +9,7 @@
2. Open the app to register your $application_abbreviation account (scan QR code below).
|
-
+
|
3. Use the app to generate the requested verification code.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ko.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ko.vsl
index 50284610f2c6..5b3cf6edad31 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ko.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ko.vsl
@@ -9,7 +9,7 @@
2. 앱을 열어 $application_abbreviation 계정을 등록하세요(아래 QR 코드 스캔).
|
-
+
|
삼. 앱을 사용하여 요청된 인증 코드를 생성하세요.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ln.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ln.vsl
index 89735a417efd..54176b4f0ab5 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ln.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ln.vsl
@@ -9,7 +9,7 @@
2. Ezali na ntina mingi. Fungola appli pona ko enregistrer compte $application_abbreviation na yo (scanner code QR na se).
|
-
+
|
3. Ezali na ntina mingi. Salelá appli mpo na kobimisa code ya vérification oyo osɛngi.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-nl.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-nl.vsl
index 0753ee3325af..29e80fa18f3b 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-nl.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-nl.vsl
@@ -9,7 +9,7 @@
2. Open de app om uw $application_abbreviation account te registreren (scan de QR-code hieronder).
|
-
+
|
3. Gebruik de app om de gevraagde verificatiecode te genereren.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-pt.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-pt.vsl
index 47102db86d5c..98e530542779 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-pt.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-pt.vsl
@@ -9,7 +9,7 @@
2. Abra o aplicativo para registrar sua conta $application_abbreviation (digitalize o código QR abaixo).
|
-
+
|
3. Use o aplicativo para gerar o código de verificação solicitado.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ro.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ro.vsl
index 918de83d56e9..5bd25c6e500e 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ro.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ro.vsl
@@ -9,7 +9,7 @@
2. Deschideți aplicația pentru a vă înregistra contul $application_abbreviation (scanați codul QR de mai jos).
|
-
+
|
3. Utilizați aplicația pentru a genera codul de verificare solicitat.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ru.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ru.vsl
index 9e61e59194f5..35829479a4f0 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ru.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-ru.vsl
@@ -9,7 +9,7 @@
2. Откройте приложение, чтобы зарегистрировать свою учетную запись $application_abbreviation (отсканируйте QR-код ниже).
|
-
+
|
3. Используйте приложение, чтобы сгенерировать запрошенный код подтверждения.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sk.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sk.vsl
index dbc003b23d42..c709108e9a85 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sk.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sk.vsl
@@ -9,7 +9,7 @@
2. Otvorte aplikáciu a zaregistrujte si svoj účet $application_abbreviation (naskenujte QR kód nižšie).
|
-
+
|
3. Pomocou aplikácie vygenerujte požadovaný overovací kód.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sl.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sl.vsl
index e923569bf2b0..5098c22fd221 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sl.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sl.vsl
@@ -9,7 +9,7 @@
2. Odprite aplikacijo, da registrirate svoj $application_abbreviation račun (skenirajte kodo QR spodaj).
|
-
+
|
3. Z aplikacijo ustvarite zahtevano kodo za preverjanje.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sv.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sv.vsl
index 0b2465d1a03f..f05ed287255a 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sv.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sv.vsl
@@ -9,7 +9,7 @@
2. Öppna appen för att registrera ditt $application_abbreviation -konto (skanna QR-koden nedan).
|
-
+
|
3. Använd appen för att generera den begärda verifieringskoden.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sw.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sw.vsl
index dad3b333e272..84f17da1a5c5 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sw.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-sw.vsl
@@ -9,7 +9,7 @@
2. Fungua programu ili kusajili akaunti yako $application_abbreviation (changanua msimbo wa QR hapa chini).
|
-
+
|
3. Tumia programu kutengeneza nambari ya kuthibitisha iliyoombwa.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-tr.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-tr.vsl
index acf001c97f4c..b749957113ac 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-tr.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-tr.vsl
@@ -9,7 +9,7 @@
2. $application_abbreviation hesabınızı kaydetmek için uygulamayı açın (aşağıdaki QR kodunu tarayın).
|
-
+
|
3. İstenen doğrulama kodunu oluşturmak için uygulamayı kullanın.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-uk.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-uk.vsl
index 2a97540702ea..9dfd67e40288 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-uk.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-uk.vsl
@@ -9,7 +9,7 @@
2. Відкрийте програму, щоб зареєструвати обліковий запис $application_abbreviation (відскануйте QR-код нижче).
|
-
+
|
3. Використовуйте програму для створення потрібного коду підтвердження.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-yo.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-yo.vsl
index f5b3a05a9e7c..4b91a6579a55 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-yo.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-yo.vsl
@@ -9,7 +9,7 @@
2. Ṣii app naa lati forukọsilẹ iroyin $application_abbreviation rẹ (ṣayẹwo koodu QR ni isalẹ).
|
-
+
|
3. Lo ìṣàfilọlẹ náà láti ṣàgbékalẹ̀ kóòdù ìmúdájú tí a béèrè.
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-zh.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-zh.vsl
index 4f6c05d83ec9..3c725b2477b9 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator-zh.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator-zh.vsl
@@ -9,7 +9,7 @@
2. Open the app to register your $application_abbreviation account (scan QR code below).
|
-
+
|
3. 使用该应用程序生成所请求的验证码。
diff --git a/core/src/main/resources/ctsms-otpinfo-googleauthenticator.vsl b/core/src/main/resources/ctsms-otpinfo-googleauthenticator.vsl
index 1c81e2606da9..90ccea8a53c4 100644
--- a/core/src/main/resources/ctsms-otpinfo-googleauthenticator.vsl
+++ b/core/src/main/resources/ctsms-otpinfo-googleauthenticator.vsl
@@ -9,7 +9,7 @@
2. Open the app to register your $application_abbreviation account (scan QR code below).
|
-
+
|
3. Use the app to generate the requested verification code.
diff --git a/web/pom.xml b/web/pom.xml
index f5d62fd4f7e4..e55eb2f543a3 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -349,6 +349,11 @@
1.5
runtime
+
+ com.google.zxing
+ core
+ 3.3.2
+
${application.id}-${project.version}
diff --git a/web/src/main/java/org/phoenixctms/ctsms/web/servlet/QRCodeServlet.java b/web/src/main/java/org/phoenixctms/ctsms/web/servlet/QRCodeServlet.java
new file mode 100644
index 000000000000..9b2cb3344773
--- /dev/null
+++ b/web/src/main/java/org/phoenixctms/ctsms/web/servlet/QRCodeServlet.java
@@ -0,0 +1,119 @@
+package org.phoenixctms.ctsms.web.servlet;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.phoenixctms.ctsms.util.CommonUtil;
+import org.phoenixctms.ctsms.web.util.GetParamNames;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+public class QRCodeServlet extends FileServletBase {
+
+ private final static ErrorCorrectionLevel DEFAULT_ERROR_CORRECTION_LEVEL = ErrorCorrectionLevel.L;
+ private final static int DEFAULT_WIDTH = 100;
+ private final static int DEFAULT_HEIGHT = 100;
+ private final static int DEFAULT_MARGIN = 4;
+ private final static String FILE_NAME = "qrcode." + CommonUtil.PNG_FILENAME_EXTENSION;
+
+ @Override
+ protected FileStream createFileStream(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ ErrorCorrectionLevel errorCorrectionLevel = DEFAULT_ERROR_CORRECTION_LEVEL;
+ int margin = DEFAULT_MARGIN;
+ try {
+ String labelData[] = request.getParameter(GetParamNames.QR_CODE_CHLD.toString()).trim().split("\\s*\\|\\s*", 2);
+ errorCorrectionLevel = ErrorCorrectionLevel.valueOf(labelData[0]);
+ margin = Integer.parseInt(labelData[1]);
+ } catch (Exception e) {
+ }
+ int width = DEFAULT_WIDTH;
+ int height = DEFAULT_HEIGHT;
+ try {
+ String size[] = request.getParameter(GetParamNames.QR_CODE_CHS.toString()).trim().split("\\s*x\\s*", 2);
+ width = Integer.parseInt(size[0]);
+ height = Integer.parseInt(size[1]);
+ } catch (Exception e) {
+ }
+ String text = request.getParameter(GetParamNames.QR_CODE_CHL.toString());
+ final byte[] data;
+ final Long fileSize;
+ if (!CommonUtil.isEmptyString(text)) {
+ Hashtable hintMap = new Hashtable<>();
+ //hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
+ hintMap.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);
+ hintMap.put(EncodeHintType.MARGIN, margin);
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
+ BitMatrix byteMatrix = null;
+ try {
+ byteMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height, hintMap);
+ } catch (Exception e) {
+ }
+ if (byteMatrix != null) {
+ BufferedImage image = new BufferedImage(byteMatrix.getWidth(), byteMatrix.getHeight(), BufferedImage.TYPE_INT_RGB);
+ image.createGraphics();
+ Graphics2D graphics = (Graphics2D) image.getGraphics();
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect(0, 0, byteMatrix.getWidth(), byteMatrix.getHeight());
+ graphics.setColor(Color.BLACK);
+ for (int i = 0; i < byteMatrix.getWidth(); i++) {
+ for (int j = 0; j < byteMatrix.getHeight(); j++) {
+ if (byteMatrix.get(i, j)) {
+ graphics.fillRect(i, j, 1, 1);
+ }
+ }
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ImageIO.write(image, CommonUtil.PNG_FILENAME_EXTENSION, baos);
+ data = baos.toByteArray();
+ fileSize = (long) data.length;
+ } else {
+ data = null;
+ fileSize = null;
+ }
+ } else {
+ data = null;
+ fileSize = null;
+ }
+ return new FileStream() {
+
+ @Override
+ public String getFileName() {
+ return FILE_NAME;
+ }
+
+ @Override
+ public Long getFileSize() {
+ return fileSize;
+ }
+
+ @Override
+ public String getMimeType() {
+ return CommonUtil.PNG_MIMETYPE_STRING;
+ }
+
+ @Override
+ public InputStream getStream() {
+ return new ByteArrayInputStream(data);
+ }
+
+ @Override
+ public boolean isNotFound() {
+ return data == null;
+ }
+ };
+ }
+}
diff --git a/web/src/main/java/org/phoenixctms/ctsms/web/util/GetParamNames.java b/web/src/main/java/org/phoenixctms/ctsms/web/util/GetParamNames.java
index ff708a7d886b..c76a1a57f0f4 100644
--- a/web/src/main/java/org/phoenixctms/ctsms/web/util/GetParamNames.java
+++ b/web/src/main/java/org/phoenixctms/ctsms/web/util/GetParamNames.java
@@ -76,7 +76,10 @@ public enum GetParamNames {
REFERER("referer"),
UUID("uuid"),
VALIDATE("validate"),
- BEACON("beacon");
+ BEACON("beacon"),
+ QR_CODE_CHLD("chld"),
+ QR_CODE_CHS("chs"),
+ QR_CODE_CHL("chl");
private final String value;
diff --git a/web/src/main/webapp/WEB-INF/web.xml b/web/src/main/webapp/WEB-INF/web.xml
index 942155a35933..5ea2c66fdb37 100644
--- a/web/src/main/webapp/WEB-INF/web.xml
+++ b/web/src/main/webapp/WEB-INF/web.xml
@@ -162,6 +162,11 @@
org.phoenixctms.ctsms.web.servlet.UnsubscribeServlet
3
+
+ qrCodeServlet
+ org.phoenixctms.ctsms.web.servlet.QRCodeServlet
+ 4
+
@@ -180,6 +185,10 @@
unsubscribeServlet
/unsubscribe/*
+
+ qrCodeServlet
+ /chart
+
javax.faces.VALIDATE_EMPTY_FIELDS
true
|