NP-API

Contact


필수: jquery 1.8.3 or hire


전체 Get QR이미지 Blob Get QR이미지 Get QR이미지 문자열(리더기값)


# Get QR이미지 Blob (ajax 방식)

var url = 'http://local.sangsanguniv.com';
var data = encodeURIComponent('값');
$.ajax({
    type: 'post',
    url: url+'/Open/GetQR',
    data: {data: data},
    success: function (r) {
        if (r.status == 1){
            $("#이미지아이디").attr("src", r.data);
        }
    }, error: function (e) {
        console.log(e.responseText);
        //something wrong
    }, complete: function () {
    }
});
        

Example


blob 이미지 적용
QRCode:

# Get QR이미지 Blob (Server Web 방식 : Java Source)

@ResponseBody
@RequestMapping(value="/GetServerQR.do", method=org.springframework.web.bind.annotation.RequestMethod.POST) 
public String GetServerQR(@org.springframework.web.bind.annotation.RequestParam("data") String data, javax.servlet.http.HttpServletResponse response) throws Exception{
    java.net.URL url = new java.net.URL("http://local.sangsanguniv.com/Open/GetServerQR");
    java.net.HttpURLConnection con = (java.net.HttpURLConnection)url.openConnection(); 
    con.setRequestMethod("POST");
    con.setDoOutput(true); 
    java.io.DataOutputStream wr = new java.io.DataOutputStream(con.getOutputStream()); 
    wr.writeBytes("data="+data); //data: blob이미지데이터로 변환할 값(id?)
    wr.flush(); 
    wr.close(); 
    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream())); 
    String inputLine; 
    StringBuffer sb = new StringBuffer(); 
    while ((inputLine = in.readLine()) != null) { 
        sb.append(inputLine); 
    } 
    in.close(); 
    return sb.toString();//blog문자열: img 태그의 src속성에 바인딩해야하는 값
}
        



# Get QR이미지 (ajax 방식)

var url = 'http://local.sangsanguniv.com';
var data = encodeURIComponent('userid');
var filename = 'qrcode';
$.ajax({
    type: 'post',
    url: url+'/Open/GetAuth',
    success: function (r) {
        if (r.status == 1){
            location.href = url+'/Open/QRDown?data='+data+'&filename='+ filename +'&token='+encodeURIComponent(r.data);
        }
    }, error: function (e) {
        console.log(e.responseText);
        //something wrong
    }, complete: function () {
    }
});
        

Example


QR 이미지 다운로드

# Get QR이미지 (Server Web 방식 : Java Source)

@ResponseBody
@RequestMapping(value="/QRServerDown.do") 
public void QRServerDown(@org.springframework.web.bind.annotation.RequestParam("data") String data, javax.servlet.http.HttpServletResponse response) throws Exception{
    java.net.URL url = new java.net.URL("http://local.sangsanguniv.com/Open/QRServerDown");
    java.net.HttpURLConnection con = (java.net.HttpURLConnection)url.openConnection(); 
    con.setRequestMethod("POST");
    con.setDoOutput(true); 
    java.io.DataOutputStream wr = new java.io.DataOutputStream(con.getOutputStream()); 
    wr.writeBytes("data="+data);//QR이미지로변환할값 
    wr.flush(); 
    wr.close(); 
    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream())); 
    String inputLine; 
    StringBuffer sb = new StringBuffer(); 
    while ((inputLine = in.readLine()) != null) { 
    sb.append(inputLine); 
    } 
    in.close(); 
    byte[] rtn = javax.xml.bind.DatatypeConverter.parseBase64Binary(sb.toString());         
    response.setContentType("application/octet-stream"); 
    response.setContentLength(rtn.length); 
    response.setHeader("Content-Disposition", "attachment; fileName=\"" + java.net.URLEncoder.encode("파일이름.png","UTF-8")+"\";"); 
    response.setHeader("Content-Transfer-Encoding", "binary"); 
    response.getOutputStream().write(rtn); 
    response.getOutputStream().flush(); 
    response.getOutputStream().close();
}
        



# Get QR이미지 문자열(리더기값)

var url = 'http://local.sangsanguniv.com';
var data = '복호화할 값-QC리더기로 읽은 값';
$.ajax({
    type: 'post',
    url: url+'/Open/ReadQR',
    data: {data: data},
    success: function (r) {
        if (r.status == 1){
            alert(r.data);
        }
    }, error: function (e) {
        console.log(e.responseText);
        //something wrong
    }, complete: function () {
    }
});
        

Example


QR데이터 확인

# Get QR이미지 문자열 (리더기값) (Server Web 방식 : Java Source)

@ResponseBody
@RequestMapping(value="/ReadServerQR.do", method=org.springframework.web.bind.annotation.RequestMethod.POST) 
public String ReadServerQR(@org.springframework.web.bind.annotation.RequestParam("data") String data,  javax.servlet.http.HttpServletResponse response) throws Exception{
    java.net.URL url = new java.net.URL("http://local.sangsanguniv.com/Open/ReadServerQR");
    java.net.HttpURLConnection con = (java.net.HttpURLConnection)url.openConnection(); 
    con.setRequestMethod("POST");
    con.setDoOutput(true); 
    java.io.DataOutputStream wr = new java.io.DataOutputStream(con.getOutputStream()); 
    wr.writeBytes("data="+java.net.URLEncoder.encode(data, "UTF-8"));//data: QR리더기에서 읽은 값 (id?)
    wr.flush(); 
    wr.close(); 
    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream())); 
    String inputLine; 
    StringBuffer sb = new StringBuffer(); 
    while ((inputLine = in.readLine()) != null) { 
        sb.append(inputLine); 
    } 
    in.close(); 
    return sb.toString(); //리더기로 읽은  값을 정산 문자열로 변환한 값
}

        
Copyright ⓒ NPTECH

제목

Close