CreateFlowUtils.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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() *essbasic.Agent {
  33. appId := SysConfig.SerCfg.TencentCfg.AppId
  34. proxyAppId := ""
  35. proxyOrganizationOpenId := SysConfig.SerCfg.TencentCfg.ProxyOrganizationOpenId
  36. proxyOperatorOpenId := SysConfig.SerCfg.TencentCfg.ProxyOperatorOpenId
  37. userInfo := &essbasic.UserInfo{}
  38. userInfo.OpenId = &proxyOperatorOpenId
  39. var agent = &essbasic.Agent{
  40. AppId: &appId,
  41. ProxyAppId: &proxyAppId,
  42. ProxyOrganizationOpenId: &proxyOrganizationOpenId,
  43. ProxyOperator: userInfo,
  44. }
  45. return agent
  46. }
  47. // FillFlowInfo 设置FlowInfo
  48. func FillFlowInfo(templateId, flowName string,
  49. flowApproverInfos []*essbasic.FlowApproverInfo) *essbasic.FlowInfo {
  50. FlowType := "合同"
  51. var flowInfo = &essbasic.FlowInfo{
  52. TemplateId: &templateId,
  53. FlowName: &flowName,
  54. FlowApprovers: flowApproverInfos,
  55. FlowType: &FlowType,
  56. }
  57. return flowInfo
  58. }
  59. // ConvertImageFileToBase64 将图片文件转化为字符串,并对其进行Base64编码处理
  60. func ConvertImageFileToBase64(filePath string) string {
  61. fileBytes, err := os.ReadFile(filePath)
  62. if err != nil {
  63. return ""
  64. }
  65. bs64 := base64.StdEncoding.EncodeToString(fileBytes)
  66. return bs64
  67. }