<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Api id="__3Z5U0FxXFerva7nG4Tp">
  <name>人脸识别</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <status>published</status>
  <apiGroup></apiGroup>
  <encode>UTF-8</encode>
  <requestType>post</requestType>
  <requestUrl>/face/faceRecognition</requestUrl>
  <tags></tags>
  <responseType>json</responseType>
  <responseScript><![CDATA[(function () {
  var result = new Packages.java.util.HashMap(); //创建指定类对象
  var jsonStr = getParameter("_content");
  if(isNotNull(jsonStr)){
    var json = JSON.parse(jsonStr);
    var id = json["id"];
    var oneImg = json["oneImg"];
    var twoImg = json["twoImg"];
    var type = json["faceOrhandType"]
    var bizFaceMode = "HIGHLIVENESS";
    var vtp = 70;
    var needface = "0"
    var appointChannel = "UNIAPP";
    if(isNotNull(id)){
      var Info = findDocument(id);
      if(isNotNull(Info)){
        var value = Info.findItem("needface");
        if(isNotNull(value)){
          needface = value.getValue();
        }
      }
    }
    if(!"1".equals(needface)){
      var url = "http://identify.bcxin.com.cn/identify/api/baidu/match-face";
      //var url = "http://identify.test.bcxin.com.cn/identify/api/baidu/match-face";
      var URLConnector = Packages.cn.hutool.http.HttpUtil;
      var strS ="bizFaceMode="+bizFaceMode+"&vtp="+vtp+"&appointChannel="+appointChannel+"&oneImg="+oneImg+"&twoImg="+twoImg+"";
      try{
        var rtJsonStr = URLConnector.post(url,strS);
        var rtJsonStrData = eval('('+rtJsonStr+')');
        println("rtJsonStrData-->"+rtJsonStrData);
      }catch(e){return e};
      var process = getDocumentProcess();
      var formProcess = getFormProcess();            
      var personInfo = formProcess.doView("__H3prrd7XNwXffINTzzP");
      var personInfoDoc = process.doNew(personInfo,getWebUser(),createParamsTable()); 
      personInfoDoc.addStringItem("photo",twoImg);
      personInfoDoc.addStringItem("person_id",getWebUser().getId());
      personInfoDoc.addStringItem("person_name",getWebUser().getName());
      personInfoDoc.addStringItem("exam_id",Info.findItem("examId").getValue());
      personInfoDoc.addStringItem("type",type);
     
      if('0'.equals(rtJsonStrData.retType)){
        if('1'.equals(rtJsonStrData.data.result)){
          personInfoDoc.addStringItem("msg","人脸识别成功");
          result.put("msg","人脸识别成功")
          result.put("code","1");
           personInfoDoc.addStringItem("check_resuilt","1");
        }else{
          personInfoDoc.addStringItem("msg","人脸识别失败");
          result.put("msg","人脸识别失败")
          result.put("code","0");
          personInfoDoc.addStringItem("check_resuilt","0");
        }
      }else{
        personInfoDoc.addStringItem("msg","人脸识别出错");
        result.put("msg","人脸识别出错")
        result.put("code","0");
        personInfoDoc.addStringItem("check_resuilt","0");
      }
    }else{
      personInfoDoc.addStringItem("msg","跳过人脸识别");
      result.put("msg","跳过人脸识别")
      result.put("code","1");
      personInfoDoc.addStringItem("check_resuilt","1");
    }
    process.doCreate(personInfoDoc); 
    return result
  }
})()]]></responseScript>
</Api>