百度证件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');
}
});
}
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值