CreateFlowUtils.go 2.9 KB

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