forked from golang/hotime
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package tencent
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
|
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
|
)
|
|
|
|
var credential = common.NewCredential(
|
|
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
|
|
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
|
|
)
|
|
|
|
func OCR(base64Str string) string {
|
|
|
|
cpf := profile.NewClientProfile()
|
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
|
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
|
|
|
request := ocr.NewGeneralAccurateOCRRequest()
|
|
|
|
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
|
|
request.ImageBase64 = common.StringPtr(base64Str)
|
|
|
|
response, err := client.GeneralAccurateOCR(request)
|
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
|
fmt.Println("An API error has returned: %s", err)
|
|
return ""
|
|
}
|
|
if err != nil {
|
|
fmt.Println("An API error has returned: %s", err)
|
|
return ""
|
|
}
|
|
//fmt.Printf("%s", response.ToJsonString())
|
|
|
|
return response.ToJsonString()
|
|
}
|
|
|
|
func Qrcode(base64Str string) string {
|
|
|
|
cpf := profile.NewClientProfile()
|
|
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
|
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
|
|
|
request := ocr.NewQrcodeOCRRequest()
|
|
|
|
request.ImageBase64 = common.StringPtr(base64Str)
|
|
|
|
response, err := client.QrcodeOCR(request)
|
|
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
|
fmt.Println("An API error has returned: %s", err)
|
|
return ""
|
|
}
|
|
if err != nil {
|
|
fmt.Println("An API error has returned: %s", err)
|
|
return ""
|
|
}
|
|
//fmt.Printf("%s", response.ToJsonString())
|
|
|
|
return response.ToJsonString()
|
|
}
|