728x90
반응형

/*--------------------------------------------------------------------- 
   Json Rest API
 ---------------------------------------------------------------------*/
OleObject lole_SrvHTTP
String ls_status, ls_response, ls_arg, ls_url
ls_arg = '{ "USER_NM": "xxxxxxx@xxxx.co.kr"}}'
ls_url = 'https://nexthr-apix.singlex.com/nexthr/hr-xmti/dev/xmti/v1/gw/org/LG01'
lole_SrvHTTP = CREATE  OleObject
lole_SrvHTTP.connectToNewObject("MSXML2.ServerXMLHTTP.6.0")
lole_SrvHTTP.Open('POST', ls_url, FALSE)
lole_SrvHTTP.SetRequestHeader( "Content-Type", "application/json")
lole_SrvHTTP.SetRequestHeader( "x-apikey", "xxxxxxxxxxxx")
lole_SrvHTTP.setOption(2,'13056') 
lole_SrvHTTP.send(ls_arg)
ls_status   = string(lole_SrvHTTP.Status)
ls_response = string(lole_SrvHTTP.ResponseText)
/*------------------------------------------------------------------------------------
  Datawindow로 자료 생성 
--------------------------------------------------------------------------------------*/
Reset()
long    p1, p2, row
string  ls_json, ls_Row[], ls_Cdata, item 
string  ls_Cols[]={"RSLTDT","HR_ORG_CD","PARENT_HR_ORG_CD","ORG_NM","ENG_ORG_NM","ORG_SORT","LCTN_CD","MGR_EMP_NO","DEPT_USEYN","LEVEL","PATH_HR_ORG_CD","PATH_ORG_NM","PATH_ENG_ORG_NM","PARENT_ORG_NM","PARENT_ENG_ORG_NM","MGR_EMP_NM"}
integer i, i_max, j, j_max
ls_json = of_replace(ls_response,'[','')
ls_json = Trim( of_replace(ls_json,']','') )
messagebox("확인",ls_json)
/*------------------------------------------------------------------------------------
  구분자로 되어 있는 String -> String Array
i_max = StringToArray( ls_json, '},', ls_Row[])
--------------------------------------------------------------------------------------*/
DO WHILE ls_json <> '' 
   item = Trim ( f_getfirstitem( ls_json, '},' )  )
   IF item = '' THEN 
   ELSE 
      i_max ++ 
      ls_Row[i_max] = item 
   END IF 
LOOP 
/*------------------------------------------------------------------------------------
  Datawindow 에 자료 추가 
--------------------------------------------------------------------------------------*/
j_max = UpperBound(ls_Cols[])
FOR i = 1 TO i_max
   ls_Row[i] = of_replace(ls_Row[i],'{'   ,'')
   ls_Row[i] = of_replace(ls_Row[i],'}'   ,'')
   ls_Row[i] = of_replace(ls_Row[i],'~r~n','')
   ls_Row[i] = of_replace(ls_Row[i],',"'  ,'^')
   ls_Row[i] = of_replace(ls_Row[i],'"'   ,'') + '^'
   
   row = Insertrow( 0 )
   FOR j = 1 TO j_max 
      // Column data  
      p1    = Pos( ls_Row[i], ls_Cols[j] )
      p2    = Pos( ls_Row[i], '^', p1 )
      ls_Cdata = Mid( ls_Row[i], p1, p2 - p1 )
      f_getfirstitem( ls_Cdata, ':' )  // ls_Cdata = Trim( f_nth(ls_Cdata,':',2) )
      ls_Cdata = Trim( of_replace(ls_Cdata,',','') )
      CHOOSE CASE j
         CASE 1
            CHOOSE CASE ls_Cdata
               case '1' ; Setitem(row, j, '성공')
               case '2' ; Setitem(row, j, 'Data코드오류')
               case '3' ; Setitem(row, j, '인증코드오류')
               case '4' ; Setitem(row, j, '일일제한횟수마감')
            end choose
         CASE 7, 11 //number
            Setitem(row, j, integer(ls_Cdata))
         CASE 2, 3     //char
            Setitem(row, j, ls_Cdata)
         CASE ELSE     //decimal
            Setitem(row, j, Dec(ls_Cdata))
      END CHOOSE
   NEXT 
NEXT 
Sort()
DESTROY lole_SrvHTTP


lole_SrvHTTP.setOption(2,'13056') //  https 연동시 ssl 인증서가 정상 설치 되지 않은 경우 인증서 무시 옵션

lole_SrvHTTP.send(ls_arg)
ls_status   = string(lole_SrvHTTP.Status)
ls_response = string(lole_SrvHTTP.ResponseText)
DESTROY lole_SrvHTTP


이거 없으면 연동 안됨.



+ Recent posts