接口实现
go
// This file is auto-generated, don't edit it. Thanks.
package main
import (
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
facebody20191230 "github.com/alibabacloud-go/facebody-20191230/v5/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"os"
)
// CreateClient
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *facebody20191230.Client, _err error) {
config := &openapi.Config{
// 必填,您的 AccessKey ID
AccessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
AccessKeySecret: accessKeySecret,
}
// Endpoint 请参考 https://api.aliyun.com/product/facebody
config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
_result = &facebody20191230.Client{}
_result, _err = facebody20191230.NewClient(config)
return _result, _err
}
func _main(args []*string) (_err error) {
var keyId = ""
var keySecret = ""
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378661.html
client, _err := CreateClient(tea.String(keyId), tea.String(keySecret))
if _err != nil {
return _err
}
ImageUrl := make([]string, 5)
ImageUrl[0] = "http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAIS4bGYMVuIdKJ/40b1cfa9407d2fe09ca09b775792613dnxbe1696821032.jpg"
ImageUrl[1] = "http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAIS4bGYMVuIdKJ/6cba5110e1fd24e0a8c3a95f7e07b2bcDKoB1696821051.jpg"
ImageUrl[2] = "http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAIS4bGYMVuIdKJ/07e7fe3debbf2db5aff65e3c789cd189Jslg1696821057.jpg"
ImageUrl[3] = "http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAIS4bGYMVuIdKJ/a3377f0c093923af809ff37780595d83R9z91696821064.jpg"
ImageUrl[4] = "http://viapi-customer-temp.oss-cn-shanghai.aliyuncs.com/LTAIS4bGYMVuIdKJ/a3377f0c093923af809ff37780595d83R9z91696821064.jpg"
for i := 0; i < len(ImageUrl); {
compareFaceRequest := &facebody20191230.CompareFaceRequest{
ImageURLA: tea.String(ImageUrl[i]),
ImageURLB: tea.String(ImageUrl[i+1]),
}
runtime := &util.RuntimeOptions{}
resp, _err := client.CompareFaceWithOptions(compareFaceRequest, runtime)
if _err != nil {
return _err
}
if len(ImageUrl)%2 == 1 && i == len(ImageUrl)-3 {
i++
compareFaceRequest = &facebody20191230.CompareFaceRequest{
ImageURLA: tea.String(ImageUrl[0]),
ImageURLB: tea.String(ImageUrl[i]),
}
runtime = &util.RuntimeOptions{}
resp, _err = client.CompareFaceWithOptions(compareFaceRequest, runtime)
if _err != nil {
return _err
}
} else {
i += 2
}
fmt.Println(resp)
}
return _err
}
func main() {
err := _main(tea.StringSlice(os.Args[1:]))
if err != nil {
panic(err)
}
}
地址转换
go
package main
import (
"fmt"
"github.com/alibabacloud-go/tea/tea"
viapiutil "github.com/alibabacloud-go/viapi-utils/client"
)
func main() {
// 场景一,使用本地文件
// file := tea.String("/tmp/bankCard.png")
// 场景二,使用任意可访问的url
file := tea.String("https://alicdn.fbmms.cn/files/202310/R9z91696821064.jpg")
// 上传成功后,返回上传后的文件地址
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量
var keyId = ""
var keySecret = ""
ossUrl, _err := viapiutil.Upload(tea.String(keyId), tea.String(keySecret), file)
if _err != nil {
fmt.Println(_err)
}
// 生成的url,可用于调用视觉智能开放平台的能力
fmt.Println(*ossUrl)
}