//#import HttpUtil.js
//#import $owlService:services/common/SettingUtil.jsx
//#import $owl_idcard:services/modelService.jsx

var IdCardService = {
    verifyIdCard:function(idcardNumber,idname){
        var idcard = owl_idcardService.get("owl_idcard_" + idcardNumber);
        if(idcard && idcard.del!=='T'){
           if(idcard.idname===idname){
               return true;
           }
           else{
               return false;
           }
        }
        var appCodeKey = 'owl_mall_setting_0_verifyIdCard_appCode';//公众号appKey
        var appCode = SettingUtil.getArgValue(appCodeKey)
        var url = 'https://yxidcard.market.alicloudapi.com/idcard';

        var headers = {
            'Authorization':'APPCODE ' + appCode
        }
        url = url + "?idcard=" + idcardNumber + "&realname=" + idname;
        var result = HttpUtils.getRaw(url, headers)
        var retObj = JSON.parse(result);
        if(retObj.code==200){
            var idcard = {
                idcard:idcardNumber,
                realname:idname,
                addr:retObj.data.addr,
                sex:retObj.data.sex,
                birth:retObj.data.birth,
                rawText:result
            }
            owl_idcardService.add(idcard);
            return true;
        }
        else{
            return false;
        }
    }
}