百度证件api认证处理


图片存base64

base64_code = Base64.encode64(File.read(file.tempfile))
if base64_code.length > 4*1024*1024
@size_error = true
else
ActiveRecord::Base.transaction do
@license = @transport_company.business_licenses.build(business_license_params.merge(base64_code: base64_code))
@license.save
attachment = @license.build_attachment(path: file, created_by: CreatedBy.format_created_by(current_employee))
attachment.save
end
end


# 百度证件api处理

$("#license_file").change(function () {
val = $(this).val();
if (val != '') {
var form_data = new FormData();
form_data.append("file", $("#license_file")[0].files[0]);
$.ajax({
url: '/api/ocr_business_license',
type: 'post',
data: form_data,
processData: false,
contentType: false,
beforeSend: function () {
$("#ocr_notice").hide();
$("#ocr_loading").addClass('active');
},
success: function (resp) {
if (resp.result == 'success') {
$("#business_license_license_no").val(resp.words_result['证件编号'].words);
$("#business_license_credit_code").val(resp.words_result['社会信用代码'].words);
$("#business_license_company_name").val(resp.words_result['单位名称'].words);
$("#business_license_legal_person").val(resp.words_result['法人'].words);
$("#business_license_address").val(resp.words_result['地址'].words);
$("#business_license_establishment_on").val(resp.words_result['成立日期'].words.replace('年', '-').replace('月', '-').replace('日', ''));
$("#business_license_expiry_on").val(resp.words_result['有效期'].words.replace('年', '-').replace('月', '-').replace('日', ''));
} else {
$("#ocr_notice p").html(resp.msg);
$("#ocr_notice").show()
}
$("#ocr_loading").removeClass('active');
},
error: function (responseStr) {
$("#ocr_loading").removeClass('active');
}
});
}
});

你可能感兴趣的:(百度证件api认证处理)