

ocr.ap-shanghai.tencentcloudapi.com就是要访问上海这个接入点。公共参数 Region 决定的是要访问业务资源所在区,例如Region=ap-beijing就是要操作北京区的资源,如果域名中不指定地域信息则默认就近接入。就近接入可能会存在问题。如果解析不到 IP 会默认到广州地域里面。另外域名地域和公共参数 Region 可以不一致,但是可能会增加耗时。建议域名和公共参数 Region 选择相同的地域:华南地区(广州),ap-guangzhou。

const tencentcloud = require("../../../../tencentcloud-sdk-nodejs");const OcrClient = tencentcloud.ocr.v20181119.Client;const models = tencentcloud.ocr.v20181119.Models;const Credential = tencentcloud.common.Credential;const ClientProfile = tencentcloud.common.ClientProfile;const HttpProfile = tencentcloud.common.HttpProfile;let cred = new Credential(" SecretId ", " SecretKey ");let httpProfile = new HttpProfile();let clientProfile = new ClientProfile();/*推荐使用 V3 鉴权。当内容超过 1M 时,必须使用 V3 签名鉴权。除 Node SDK 外,其他语言 SDK 都支持 V3。clientProfile.signMethod = "TC3-HMAC-SHA256";*/clientProfile.httpProfile = httpProfile;let client = new OcrClient(cred, "ap-guangzhou", clientProfile);let req = new models.IDCardOCRRequest();req.ImageUrl = "[https://test.jpg](https://test.jpg/)";req.CardSide = "FRONT";let config = {"CropPortrait":true};req.Config = JSON.stringify(config)client.IDCardOCR(req, function(errMsg, response) {if (errMsg) {console.log(errMsg);return;}console.log(response.to_json_string());});
data:image/jpg;base64,和换行符\\n。[TencentCloudSDKException]message:AuthFailure.SignatureFailure-The provided credentialscould not be validated because of exceeding request size limit, please use new signaturemethod `TC3-HMAC-SHA256`. requestId:719970d4-5814-4dd9-9757-a3f11ecc9b20
clientProfile.setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为 HmacSHA256)

文档反馈