package utils import ( "encoding/base64" SysConfig "mtp2_if/config" "os" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" essbasic "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/essbasic/v20210526" ) var TencentESSClient *essbasic.Client // InitTencentESSClient 初始化Client func InitTencentESSClient() (err error) { secretId := SysConfig.SerCfg.TencentCfg.SecretId secretKey := SysConfig.SerCfg.TencentCfg.SecretKey // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密 // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取 credential := common.NewCredential( secretId, secretKey, ) // 实例化一个client选项,可选的,没有特殊需求可以跳过 cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = SysConfig.SerCfg.TencentCfg.EndPoint // 实例化要请求产品的client对象,clientProfile是可选的 TencentESSClient, err = essbasic.NewClient(credential, "", cpf) if err != nil { return } return } // SetAgent 设置Agent func SetAgent() *essbasic.Agent { appId := SysConfig.SerCfg.TencentCfg.AppId proxyAppId := "" proxyOrganizationOpenId := SysConfig.SerCfg.TencentCfg.ProxyOrganizationOpenId proxyOperatorOpenId := SysConfig.SerCfg.TencentCfg.ProxyOperatorOpenId userInfo := &essbasic.UserInfo{} userInfo.OpenId = &proxyOperatorOpenId var agent = &essbasic.Agent{ AppId: &appId, ProxyAppId: &proxyAppId, ProxyOrganizationOpenId: &proxyOrganizationOpenId, ProxyOperator: userInfo, } return agent } // FillFlowInfo 设置FlowInfo func FillFlowInfo(templateId, flowName string, flowApproverInfos []*essbasic.FlowApproverInfo) *essbasic.FlowInfo { FlowType := "合同" var flowInfo = &essbasic.FlowInfo{ TemplateId: &templateId, FlowName: &flowName, FlowApprovers: flowApproverInfos, FlowType: &FlowType, } return flowInfo } // ConvertImageFileToBase64 将图片文件转化为字符串,并对其进行Base64编码处理 func ConvertImageFileToBase64(filePath string) string { fileBytes, err := os.ReadFile(filePath) if err != nil { return "" } bs64 := base64.StdEncoding.EncodeToString(fileBytes) return bs64 }