zhengyiming
2 天以前 e108e18dfb1cb8791c2033aea2682862ce9d825d
packages/hooks/identify.ts
@@ -1,43 +1,44 @@
import * as accountServices from '@12333/services/api/Account';
import { EnumOcrAccess } from '@12333/constants';
import * as ocrUtilsServices from '@12333/services/apiV2/ocrUtils';
import { FileItem } from '@nutui/nutui-taro/dist/types/__VUE/uploader/type';
import _ from 'lodash';
type VatLicenseOptions = {
  onSuccess?: (res: API.LicenseOcrModel) => any;
  onSuccess?: (res: API.BaiduOcrBusinessLicenseResultModel) => any;
};
export async function vatLicense(response: FileItem, options: VatLicenseOptions = {}) {
  try {
    if (response?.url) {
      const { onSuccess } = options;
      let res = await accountServices.vatLicense({
      let res = await ocrUtilsServices.getLicenseOcr({
        url: response.url,
      });
      onSuccess?.(
        _.mapValues(res, (x) => {
          if (x === '无') return '';
          return x;
        })
      );
      onSuccess?.(res.model);
    }
  } catch (error) {}
}
// type UserCredentialVerifyOcrIDCardOptions = {
//   onSuccess?: (res: API.UserCredentialVerifyOcrIDCardResponse) => any;
// };
type UserCredentialVerifyOcrIDCardOptions = {
  access?: EnumOcrAccess;
  scene?: string;
  isOssUrl?: boolean;
  url?: string;
  onSuccess?: (res: API.GetIdentityFrontOcrCommandResult) => any;
};
// export async function userCredentialVerifyOcrIDCard(
//   response: FileItem,
//   options: UserCredentialVerifyOcrIDCardOptions = {}
// ) {
//   try {
//     if (response?.url) {
//       const { onSuccess } = options;
//       let res = await commonServices.userCredentialVerifyOcrIDCard({
//         identityImageUrl: response.url,
//       });
//       onSuccess?.(res);
//     }
//   } catch (error) {}
// }
export async function userCredentialVerifyOcrIDCard(
  options: UserCredentialVerifyOcrIDCardOptions = {}
) {
  try {
    const { onSuccess, access, isOssUrl, url, scene } = options;
    if (url) {
      let res = await ocrUtilsServices.getIdentityFrontOcr({
        access: access,
        url: url,
        isOssUrl: isOssUrl,
      });
      onSuccess?.(res);
    }
  } catch (error) {}
}