content_service.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package service
  2. //
  3. //import (
  4. // "fmt"
  5. // "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
  6. // //region "github.com/huaweicloud/huaweicloud-review_service-go-v3/core/region"
  7. // moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3"
  8. // "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model"
  9. // moderationRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region"
  10. // "youngee_m_api/app/vo"
  11. //)
  12. //
  13. //type ContentService struct{}
  14. //
  15. //// 内容审核
  16. //func (s ContentService) CheckContent(contentCheckParam *vo.ContentCheckParam) (*string, error) {
  17. // // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;
  18. // // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
  19. // ak := "CNN8MCCSJFGHL1MXCJRF"
  20. // sk := "91arFGHyO7RrzXnZIFSPcLSC6y4P4MTKtkq3qLIy"
  21. // projectId := "CNN8MCCSJFGHL1MXCJRF"
  22. // eventType := "article"
  23. //
  24. // auth := basic.NewCredentialsBuilder().
  25. // WithAk(ak).
  26. // WithSk(sk).
  27. // WithProjectId(projectId).
  28. // Build()
  29. //
  30. // client := moderation.NewModerationClient(
  31. // moderation.ModerationClientBuilder().
  32. // WithRegion(moderationRegion.ValueOf("cn-north-4")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。
  33. // WithCredential(auth).
  34. // Build())
  35. //
  36. // //request := &model.RunTextModerationRequest{}
  37. // //request.EnterpriseProjectId = &projectId
  38. // //databody := &model.TextDetectionDataReq{
  39. // // Text: contentCheckParam.Summary,
  40. // //}
  41. // //request.Body = &model.TextDetectionReq{
  42. // // Data: databody,
  43. // // EventType: &eventType,
  44. // //}
  45. // //response, err := client.RunTextModeration(request)
  46. // //if err == nil {
  47. // // fmt.Printf("%+v\n", response)
  48. // //} else {
  49. // // fmt.Println(err)
  50. // //}
  51. // request := &model.CheckImageModerationRequest{}
  52. // var listCategoriesbody = []string{
  53. // "porn", "terrorism",
  54. // }
  55. // eventType = "head_image"
  56. // urlImageDetectionReq := "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1oXRBY.img?w=640&h=360&m=6"
  57. // request.Body = &model.ImageDetectionReq{
  58. // Url: &urlImageDetectionReq,
  59. // Categories: &listCategoriesbody,
  60. // EventType: &eventType,
  61. // }
  62. // response, err := client.CheckImageModeration(request)
  63. // if err == nil {
  64. // fmt.Printf("%+v\n", response)
  65. // } else {
  66. // fmt.Println(err)
  67. // }
  68. // result := response.Result
  69. // fmt.Print(result)
  70. //
  71. // return nil, nil
  72. //}