diff --git a/publisher/platforms.py b/publisher/platforms.py index c450482..5c4c974 100644 --- a/publisher/platforms.py +++ b/publisher/platforms.py @@ -153,3 +153,21 @@ def publish_twitter(platform, content): return ('POST', 'https://api.twitter.com/2/tweets', headers, body, 'article') register('twitter', 'Twitter/X', publish_twitter, ['article', 'image', 'video']) + +# -- 微信视频号 -- +def publish_channels(platform, content): + headers = _auth_headers(platform) + headers['Content-Type'] = 'application/json' + body = { + 'title': content.get('title', '')[:50], + 'description': content.get('body', '')[:500], + 'cover_url': content.get('cover_url', ''), + } + if content['content_type'] == 'video' and content.get('media_urls'): + body['video_url'] = json.loads(content['media_urls'])[0] + elif content.get('media_urls'): + body['image_urls'] = json.loads(content['media_urls'])[:9] + return ('POST', platform.get('api_endpoint', 'https://channels.weixin.qq.com/api/post/create'), + headers, body, content['content_type']) + +register('channels', '微信视频号', publish_channels, ['video', 'image'])