No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

83 líneas
3.5KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. )
  6. type attachmentID struct {
  7. ID string `json:"attachmentId"`
  8. }
  9. func crmAttachFile(path string) (fileID string) {
  10. //http post
  11. r, _ := crmPostAttach(path)
  12. attach := attachmentID{}
  13. json.Unmarshal([]byte(r), &attach)
  14. return attach.ID
  15. }
  16. func crmPostAttachmentURL() string {
  17. return "https://c.hitxy.org.au/api/v1/Attachment/action/upload"
  18. }
  19. func crmAuthHeader() string {
  20. return "Basic cGF0cmljazpiNjFmYWRlMTM5OWYwY2ZjNmZjZjcxNTU0OTljNTNkOQ=="
  21. //return "Basic cGF0cmljazp3b3JraGFyZA=="
  22. }
  23. func crmFileDataString(path string) string {
  24. //read file
  25. //encode it
  26. return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXIAAAFyAQMAAADS6sNKAAAABlBMVEX///8AAABVwtN+AAABsklEQVR4nO2aS47EIAxEkXKAHClX7yPlAJHcwR8MgZnljCqqWrjzefQG29iQUiiKoiiK+h+J67Krcqg566s93n3I4/J2s1/1apP7shq9vU2PkMfk67TrO/UCN5s9M0ch/wq+uoI6hYjFO/k38Yaa0eHkX8GXYe6b0Wc9Qh6Sz3rssz/Msh4jD8X3I9t6raX2miKPxasr3F1UjfJTl+rN0HCFbfIf8kC8zn033NBTmyqx9oo8Ml97J98Faeu1ds7aVE31GHk43k1U3mHkfJRi5CF58V3MLrN7U+WJ4OEP5JF4i2grxYLPreq5MiOPxQdweWYvLZWrPxxT0JOH4rPKHraq16UbeTg+UrlEAWYOEPX2yn/IY/GezyVLbc/nl/8beVw+HucBRFULf0XI4/IZ1j73w8liWYg8Eh+ldoT1ERsgnWeQx+X7kZnA9xz03O8iD8X7tEeXXErpv9eyQeSBebsJIJtm94cpP5AH43cP8OinfKk2zeeP5GH56KfSFeZDCfKovNjOtcjYSv3oD+QxeP1prbL1U/m91llGkQfjXddQb9t54u/1G3kEnqIoiqKov9QXf1Q2La7tzOYAAAAASUVORK5CYII="
  27. }
  28. func crmPostAttach(path string) (resp string, err error) {
  29. headers := map[string]string{}
  30. headers["Authorization"] = crmAuthHeader()
  31. headers["Accept"] = "application/json, text/javascript, */*; q=0.01"
  32. data := []byte(crmFileDataString(path))
  33. URL := crmPostAttachmentURL()
  34. resp, err = postRAW(data, URL, headers)
  35. return
  36. }
  37. type attachmentInfo struct {
  38. ID string `json:"id"` //"id": "591e55398345683ee",
  39. Name string `json:"name"` //"name": "static_qr_code_without_logo.png",
  40. Deleted bool `json:"deleted"` //"deleted": false,
  41. Type string `json:"type"` // "type": "image\/png",
  42. Size int `json:"size"` //"size": 509,
  43. SourceID string `json:"sourceId"` //"sourceId": null,
  44. CreateAT string `json:"createAt"` //"createdAt": "2017-05-19 02:15:21",
  45. Role string `json:"role"` //"role": "Attachment",
  46. Storage string `json:"storage"` //"storage": null,
  47. StorageFielPath string `json:"storageFilePath"` //"storageFilePath": null,
  48. Global bool `json:"global"` // "global": false,
  49. ParentID string `json:"parentId"` // "parentId": null,
  50. ParentType string `json:"parentType"` // "parentType": null,
  51. RelatedID string `json:"relatedId"` // "relatedId": null,
  52. RelatedType string `json:"relatedType"` // "relatedType": null,
  53. CreatedByID string `json:"createdById"` // "createdById": "1",
  54. CreatedbyName string `json:"createdByName"` // "createdByName": "Admin"
  55. }
  56. func crmPatchAttachmentInfo(id string) (j string) {
  57. info := map[string]interface{}{}
  58. //{"name":"static_qr_code_without_logo.png","type":"image/png","role":"Attachment","size":509}
  59. info["name"] = "static_qr_code_without_logo.png"
  60. info["type"] = "image/png"
  61. info["role"] = "Attachment"
  62. info["size"] = 509
  63. url := "https://c.hitxy.org.au/api/v1/Attachment/591e5f7b9463d7147"
  64. headers := map[string]string{}
  65. headers["Authorization"] = crmAuthHeader()
  66. headers["Content-Type"] = "application/json"
  67. jb, _ := json.Marshal(info)
  68. log.Println(string(jb))
  69. j, _ = putRAW(jb, url, headers)
  70. return
  71. }