Package com.bytedesk.social.meta
Class MetaMaterialService
java.lang.Object
com.bytedesk.social.meta.MetaMaterialService
Meta平台素材服务
用于上传附件并获取attachment_id,用于媒体模板
参考文档:
https://developers.facebook.com/docs/messenger-platform/send-messages/saving-assets
https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api/
注意:附件编号将于90天后过期。附件编号过期后,您将需要重新上传素材,才能获取新附件编号。
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.fasterxml.jackson.databind.ObjectMapperprivate final org.springframework.web.client.RestTemplate -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription获取附件类型描述booleanisValidAttachmentType(String type) 验证附件类型是否有效saveMaterialByFile(String pageId, String accessToken, String type, org.springframework.web.multipart.MultipartFile file) 通过文件上传保存素材,返回attachment_idsaveMaterialByUrl(String pageId, String accessToken, String type, String url) 通过URL保存素材,返回attachment_id
-
Field Details
-
restTemplate
private final org.springframework.web.client.RestTemplate restTemplate -
objectMapper
private final com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
-
Constructor Details
-
MetaMaterialService
public MetaMaterialService()
-
-
Method Details
-
saveMaterialByUrl
通过URL保存素材,返回attachment_id- Parameters:
pageId- 页面IDaccessToken- 访问令牌type- 附件类型 (image, video, audio, file)url- 文件URL- Returns:
- attachment_id,失败时返回null
-
saveMaterialByFile
public String saveMaterialByFile(String pageId, String accessToken, String type, org.springframework.web.multipart.MultipartFile file) 通过文件上传保存素材,返回attachment_id- Parameters:
pageId- 页面IDaccessToken- 访问令牌type- 附件类型 (image, video, audio, file)file- 上传的文件- Returns:
- attachment_id,失败时返回null
-
isValidAttachmentType
验证附件类型是否有效- Parameters:
type- 附件类型- Returns:
- 是否有效
-
getAttachmentTypeDescription
获取附件类型描述- Parameters:
type- 附件类型- Returns:
- 类型描述
-