CreateFlowUtils.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package utils
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. SysConfig "mtp2_if/config"
  6. "os"
  7. "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
  8. "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
  9. essbasic "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/essbasic/v20210526"
  10. )
  11. var TencentESSClient *essbasic.Client
  12. // InitTencentESSClient 初始化Client
  13. func InitTencentESSClient() (err error) {
  14. secretId := SysConfig.SerCfg.TencentCfg.SecretId
  15. secretKey := SysConfig.SerCfg.TencentCfg.SecretKey
  16. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  17. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  18. credential := common.NewCredential(
  19. secretId,
  20. secretKey,
  21. )
  22. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  23. cpf := profile.NewClientProfile()
  24. cpf.HttpProfile.Endpoint = SysConfig.SerCfg.TencentCfg.EndPoint
  25. // 实例化要请求产品的client对象,clientProfile是可选的
  26. TencentESSClient, err = essbasic.NewClient(credential, "", cpf)
  27. if err != nil {
  28. return
  29. }
  30. return
  31. }
  32. // SetAgent 设置Agent
  33. func SetAgent(proxyOrganizationOpenId string) *essbasic.Agent {
  34. appId := SysConfig.SerCfg.TencentCfg.AppId
  35. proxyAppId := ""
  36. // proxyOrganizationOpenId := SysConfig.SerCfg.TencentCfg.ProxyOrganizationOpenId
  37. // proxyOperatorOpenId := SysConfig.SerCfg.TencentCfg.ProxyOperatorOpenId
  38. // 子客的管理员ID默认为 USERID_ADMIN,例如 1000_ADMIN
  39. proxyOperatorOpenId := fmt.Sprintf("%s_ADMIN", proxyOrganizationOpenId)
  40. userInfo := &essbasic.UserInfo{}
  41. userInfo.OpenId = &proxyOperatorOpenId
  42. var agent = &essbasic.Agent{
  43. AppId: &appId,
  44. ProxyAppId: &proxyAppId,
  45. ProxyOrganizationOpenId: &proxyOrganizationOpenId,
  46. ProxyOperator: userInfo,
  47. }
  48. return agent
  49. }
  50. // FillFlowInfo 设置FlowInfo
  51. func FillFlowInfo(templateId, flowName string,
  52. flowApproverInfos []*essbasic.FlowApproverInfo) *essbasic.FlowInfo {
  53. FlowType := "合同"
  54. var flowInfo = &essbasic.FlowInfo{
  55. TemplateId: &templateId,
  56. FlowName: &flowName,
  57. FlowApprovers: flowApproverInfos,
  58. FlowType: &FlowType,
  59. }
  60. return flowInfo
  61. }
  62. // ConvertImageFileToBase64 将图片文件转化为字符串,并对其进行Base64编码处理
  63. func ConvertImageFileToBase64(filePath string) string {
  64. fileBytes, err := os.ReadFile(filePath)
  65. if err != nil {
  66. return ""
  67. }
  68. bs64 := base64.StdEncoding.EncodeToString(fileBytes)
  69. return bs64
  70. }