| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package utils
- import (
- "encoding/base64"
- SysConfig "mtp2_if/config"
- "mtp2_if/logger"
- "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 {
- logger.GetLogger().Errorf("InitTencentESSClient failed: %s", err.Error())
- return
- }
- return
- }
- // SetAgent 设置Agent
- func SetAgent(appId, proxyOrganizationOpenId, proxyOperatorOpenId *string) *essbasic.Agent {
- if appId == nil {
- appId = &SysConfig.SerCfg.TencentCfg.AppId
- }
- proxyAppId := ""
- if proxyOrganizationOpenId == nil {
- proxyOrganizationOpenId = &SysConfig.SerCfg.TencentCfg.ProxyOrganizationOpenId
- }
- if proxyOperatorOpenId == nil {
- proxyOperatorOpenId = &SysConfig.SerCfg.TencentCfg.ProxyOperatorOpenId
- }
- // if userId != nil {
- // if esignConfig, err := models.GetEsignareatemplateconfig(*userId); err == nil && esignConfig != nil {
- // appId = esignConfig.APPID
- // proxyOrganizationOpenId = esignConfig.PROXYORGANIZATIONOPENID
- // proxyOperatorOpenId = esignConfig.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,
- formFields []*essbasic.FormField) *essbasic.FlowInfo {
- FlowType := "合同"
- var flowInfo = &essbasic.FlowInfo{
- TemplateId: &templateId,
- FlowName: &flowName,
- FlowApprovers: flowApproverInfos,
- FlowType: &FlowType,
- }
- if len(formFields) > 0 {
- flowInfo.FormFields = formFields
- }
- 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
- }
|