CreateFlowUtils.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package utils
  2. import (
  3. "encoding/base64"
  4. SysConfig "mtp2_if/config"
  5. "mtp2_if/logger"
  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. logger.GetLogger().Errorf("InitTencentESSClient failed: %s", err.Error())
  29. return
  30. }
  31. return
  32. }
  33. // SetAgent 设置Agent
  34. func SetAgent(appId, proxyOrganizationOpenId, proxyOperatorOpenId *string) *essbasic.Agent {
  35. if appId == nil {
  36. appId = &SysConfig.SerCfg.TencentCfg.AppId
  37. }
  38. proxyAppId := ""
  39. if proxyOrganizationOpenId == nil {
  40. proxyOrganizationOpenId = &SysConfig.SerCfg.TencentCfg.ProxyOrganizationOpenId
  41. }
  42. if proxyOperatorOpenId == nil {
  43. proxyOperatorOpenId = &SysConfig.SerCfg.TencentCfg.ProxyOperatorOpenId
  44. }
  45. // if userId != nil {
  46. // if esignConfig, err := models.GetEsignareatemplateconfig(*userId); err == nil && esignConfig != nil {
  47. // appId = esignConfig.APPID
  48. // proxyOrganizationOpenId = esignConfig.PROXYORGANIZATIONOPENID
  49. // proxyOperatorOpenId = esignConfig.PROXYOPERATOROPENID
  50. // }
  51. // }
  52. userInfo := &essbasic.UserInfo{}
  53. userInfo.OpenId = proxyOperatorOpenId
  54. var agent = &essbasic.Agent{
  55. AppId: appId,
  56. ProxyAppId: &proxyAppId,
  57. ProxyOrganizationOpenId: proxyOrganizationOpenId,
  58. ProxyOperator: userInfo,
  59. }
  60. return agent
  61. }
  62. // FillFlowInfo 设置FlowInfo
  63. func FillFlowInfo(templateId, flowName string,
  64. flowApproverInfos []*essbasic.FlowApproverInfo,
  65. formFields []*essbasic.FormField) *essbasic.FlowInfo {
  66. FlowType := "合同"
  67. var flowInfo = &essbasic.FlowInfo{
  68. TemplateId: &templateId,
  69. FlowName: &flowName,
  70. FlowApprovers: flowApproverInfos,
  71. FlowType: &FlowType,
  72. }
  73. if len(formFields) > 0 {
  74. flowInfo.FormFields = formFields
  75. }
  76. return flowInfo
  77. }
  78. // ConvertImageFileToBase64 将图片文件转化为字符串,并对其进行Base64编码处理
  79. func ConvertImageFileToBase64(filePath string) string {
  80. fileBytes, err := os.ReadFile(filePath)
  81. if err != nil {
  82. return ""
  83. }
  84. bs64 := base64.StdEncoding.EncodeToString(fileBytes)
  85. return bs64
  86. }