Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 小红书openapi demo完成、爱团团视频发布列表解决视频文件名太长的兼容问题
gaoSire97cb61d7293
diff --git a/demo/xhs/index.html b/demo/xhs/index.htmlindex 190e83f6..480732a3 100644--- a/demo/xhs/index.html+++ b/demo/xhs/index.html@@ -5,31 +5,35 @@<meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge">- <title>Document</title>+ <title>小红书api demo</title></head><body>+ <button onclick="start()">开始</button>+<script src="https://fe-static.xhscdn.com/biz-static/goten/xhs-1.0.1.js"></script><script>- xhs.share({- shareInfo: {- type: 'video', // 必填,笔记类型 'video' | 'normal'- title: '', // 笔记标题- content: '', // 笔记正文- images: [], //图文类型必填,笔记图片,必须是服务器地址,暂时不支持本地文件- video: 'https://v2.kwaicdn.com/ksc2/VmX3B76w8gFXMDBsRimf78ezmXWpFE9J_Icv6tNSDH5ypAcqiNwEMXvyIIcytk45IJk597zST0AAT8z6p8_j_0pivi6BfA4aYkthLPCeoMt6X-ZHAfhrG0_UAmyBd8Ws.mp4?pkey=AAUputNjdOyCup9trHzJeM0BfThdt6s38U-6KX66Wgi5Fd45hYFBN6bGFt9C4T1a375WlxkUF30R8reD7_17OTPilPDCxxlQ63VvorbpPqBRa0q2EJxfuRxopT_B46PogMs&tag=1-1741178711-unknown-0-hazkxkcjwr-fd564f77b8f22cef&clientCacheKey=3x6kpd8ge4ajy5q_7b82d723&di=dfa08008&bp=14944&tt=hd15&ss=vp', // 视频类型必填,必须是服务器地址- cover: '' // 视频封面图,必须是服务器地址,暂时不支持本地文件- },- verifyConfig: {- appKey: 'red.gLvsVoksierVz0uF', //必填,应用的唯一标识,- nonce: '106krnew4gdr', // 必填,服务端生成签名的随机字符串- timestamp: 1741181993022, // 必填,服务端生成签名的时间戳- signature: '76908895db88441161ef039dad7b94b3bf44778f574bb196ae6b592ccd01415a', // 必填,服务端生成的签名- },- fail: (e) => {- console.log(e)- // 调用失败时执行的回调函数- },- })+ function start() {+ xhs.share({+ shareInfo: {+ type: 'video', // 必填,笔记类型 'video' | 'normal'+ title: '', // 笔记标题+ content: '', // 笔记正文+ images: [], //图文类型必填,笔记图片,必须是服务器地址,暂时不支持本地文件+ video: `https://v2.kwaicdn.com/ksc2/SMdhuIRTGiY9m3ArzOK-oHez6UYVeUxXanHgmB1xBBnsbp74iJ_obAfIGVj_d7RHk6egi72Fhhavh4Qt3kjvcX800rPTC5C4syQmMn0JNmCLXkLc0x0eZWPixd9v8ojThsZlGa5-R-cGkJ6Yz_5w3o6LTNvznfEwWK5IuTbsTyo6JyqnSjXHJXTJt60OfHLe.mp4?pkey=AAUeTe5wQYga8lqgFEiu9QADrMJ-cmeeNpa4a56yDq9mUM4dwIxc3BPJngfj0w8jM6NTOFDeMt89qwdGNeinaf0mnVdWuk3OXt32rpKDlVwqQgN2grlkN-TtNH9tSRnd_hE&tag=1-1741227422-unknown-0-6brouypjgg-0d40512211807271&clientCacheKey=3xm49hn8ttwywgm_b.mp4&di=72fe0292&bp=14944&tt=b&ss=vp`,+ cover: '' // 视频封面图,必须是服务器地址,暂时不支持本地文件+ },+ verifyConfig: {+ appKey: 'red.gLvsVoksierVz0uF', //必填,应用的唯一标识,+ nonce: 'xln7snms4mh', // 必填,服务端生成签名的随机字符串+ timestamp: 1741227154604, // 必填,服务端生成签名的时间戳+ signature: '646b7c0c796fdc8f7b15eb1aaeac0b198ce875716742a3d3b8af0b583c66bf71', // 必填,服务端生成的签名+ },+ fail: (e) => {+ console.log(e)+ // 调用失败时执行的回调函数+ },+ })+ }</script></body></html>\ No newline at end of filediff --git a/demo/xhs/signature.js b/demo/xhs/signature.jsindex 23f42ae4..345d15e9 100644--- a/demo/xhs/signature.js+++ b/demo/xhs/signature.js@@ -1,7 +1,7 @@import axios from "axios";import crypto from "crypto-js"const appKey = "red.gLvsVoksierVz0uF";-const appSecret = "xxxx";+const appSecret = "f13a2266d1e2c32a553cb7a42ea63c48";let cachedAccessToken = null;let accessTokenExpiresAt = 0; // 记录 access_token 过期时间@@ -16,7 +16,7 @@ function generateSignature(appKey, nonce, timeStamp, appSecret) {.sort().map((key) => `${key}=${params[key]}`).join("&");- const stringToSign = sortedParams + '&appSecret=' + appSecret;+ const stringToSign = sortedParams + appSecret;console.log(stringToSign);return crypto.SHA256(stringToSign).toString();}@@ -63,8 +63,8 @@ const getAccessToken = async (nonce, timestamp) => {const nonce = Math.random().toString(36).substring(2);const timestamp = Date.now();const accessToken = await getAccessToken(nonce, timestamp);-// const signature = generateSignature(appKey, nonce, timestamp, accessToken);-// console.log("appKey:", appKey);-// console.log("nonce:", nonce);-// console.log("timestamp:", timestamp);-// console.log("signature:", signature);+const signature = generateSignature(appKey, nonce, timestamp, accessToken);+console.log("appKey:", appKey);+console.log("nonce:", nonce);+console.log("timestamp:", timestamp);+console.log("signature:", signature);diff --git a/src/views/publish/children/videoPage/components/VideoChooseItem.tsx b/src/views/publish/children/videoPage/components/VideoChooseItem.tsxindex af7f6316..dfe7e91c 100644--- a/src/views/publish/children/videoPage/components/VideoChooseItem.tsx+++ b/src/views/publish/children/videoPage/components/VideoChooseItem.tsx@@ -84,7 +84,10 @@ const VideoChooseItem = memo(</div></div><div className="videoChooseItem-left-info">- <p className="videoChooseItem-left-title">+ <p+ className="videoChooseItem-left-title"+ title={videoChooseItem.video?.filename}+ >{videoChooseItem.video?.filename}</p><div className="videoChooseItem-left-bottom">diff --git a/src/views/publish/children/videoPage/useVideoPageStore.ts b/src/views/publish/children/videoPage/useVideoPageStore.tsindex 3711cc14..dc8901b3 100644--- a/src/views/publish/children/videoPage/useVideoPageStore.ts+++ b/src/views/publish/children/videoPage/useVideoPageStore.ts@@ -245,10 +245,10 @@ export const useVideoPageStore = create(// 清空所有数据clear() {- store.commonPubParams.cover = undefined;- set({- ...store,- });+ // store.commonPubParams.cover = undefined;+ // set({+ // ...store,+ // });},// 删除某个视频diff --git a/src/views/publish/children/videoPage/video.module.scss b/src/views/publish/children/videoPage/video.module.scssindex 5287e071..e1907071 100644--- a/src/views/publish/children/videoPage/video.module.scss+++ b/src/views/publish/children/videoPage/video.module.scss@@ -118,6 +118,7 @@display: flex;&-noAccount {width: 100%;+ min-width: 0;display: flex;flex-direction: column;align-items: center;@@ -196,6 +197,7 @@border-radius: 8px;height: 100%;width: 100%;+ min-width: 0;&:hover {border-color: var(--colorPrimary5);.videoChooseItem-video-close {@@ -207,6 +209,7 @@&-left {display: flex;width: 100%;+ min-width: 0;&-chooseVideo {width: 100%;cursor: pointer;@@ -237,6 +240,7 @@flex-direction: column;margin-left: 15px;justify-content: center;+ overflow: hidden;}&-bottom {display: flex;@@ -253,8 +257,20 @@&-title {font-size: var(--fs-sm);font-weight: 900;+ white-space: nowrap;+ text-overflow: ellipsis;+ overflow: hidden;}}+ &-right {+ width: 200px;+ flex-shrink: 0;+ display: flex;+ align-items: center;+ border-left: 1px solid #e5e5e5;+ padding-left: 20px;+ box-sizing: border-box;+ }&-account {width: 100%;display: flex;@@ -301,18 +317,11 @@}}}- &-right {- width: 200px;- flex-shrink: 0;- display: flex;- align-items: center;- border-left: 1px solid #e5e5e5;- padding-left: 20px;- }&-video {width: 50px;height: 100%;position: relative;+ flex-shrink: 0;&-close {border-radius: 50%;position: absolute;