Skip to content

Commit

Permalink
fix: wechat publish error
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 13, 2024
1 parent cfc974e commit e080cff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
13 changes: 10 additions & 3 deletions docs/插件开发.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@
在 src/components/set/publish/singleplatform/SingleSettingIndex.vue 注册配置
7. 修改图片上传逻辑,可选
8. docker 代理适配,已不再需要
9. 图片上传注意事项,目前有两种方式
9. 普通请求注意事项,目前全程使用 proxy,例如:简书、知乎、微信公众号,代码要注意的地方

9.1 全程使用 proxy,例如:知乎、简书、微信公众号,代码要注意的地方:
```js
const resJson = await this.webFetch(apiUrl, [mergedHeaders], body, method, contentType, true, "base64", "text")
```

10. 图片上传注意事项,目前有两种方式:

10.1 全程使用 proxy,例如:知乎、简书、微信公众号,代码要注意的地方:

```js
// uploadFile 方法
// 注意:FormData, Blob 等对象必须使用原生浏览器的
const file = new Blob([mediaObject.bits], { type: mediaObject.type })
const filename = mediaObject.name

Expand All @@ -73,7 +80,7 @@
const resJson = await this.webFormFetch(url, [header], formData, true)
```

9.2 网页端使用 proxy,PC 端使用 node-fetch-cjs,例如:CSDN
11.2 网页端使用 proxy,PC 端使用 node-fetch-cjs,例如:CSDN

```js
// uploadFile 方法
Expand Down
9 changes: 1 addition & 8 deletions src/adaptors/web/wechat/wechatWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { BlogConfig, MediaObject, PageTypeEnum, Post, UserBlog } from "zhi-blog-
import { toRaw } from "vue"
import _ from "lodash-es"
import { fileToBuffer } from "~/src/utils/polyfillUtils.ts"
import FormDataUtils from "~/src/utils/FormDataUtils.ts"

/**
* 微信公众号网页授权适配器
Expand Down Expand Up @@ -231,8 +230,6 @@ class WechatWebAdaptor extends BaseWebApi {
save_type: "1",
isneedsave: "0",
}
// get formData and Blob
const { FormData } = FormDataUtils.getFormData(this.appInstance)
// formData
const formData: any = new FormData()
for (const key in params) {
Expand Down Expand Up @@ -373,8 +370,6 @@ class WechatWebAdaptor extends BaseWebApi {
save_type: "1",
isneedsave: "0",
}
// get formData and Blob
const { FormData } = FormDataUtils.getFormData(this.appInstance)
// formData
const formData: any = new FormData()
for (const key in params) {
Expand Down Expand Up @@ -439,8 +434,6 @@ class WechatWebAdaptor extends BaseWebApi {
ajax: "1",
AppMsgId: postid,
}
// get formData and Blob
const { FormData } = FormDataUtils.getFormData(this.appInstance)
// formData
const formData: any = new FormData()
for (const key in params) {
Expand Down Expand Up @@ -569,7 +562,7 @@ class WechatWebAdaptor extends BaseWebApi {
this.logger.debug("向微信公众号请求数据,headers =>", headers)
this.logger.debug("向微信公众号请求数据,body =>", body)

const resJson = await this.webFetch(apiUrl, [mergedHeaders], body, method, contentType, true, "base64")
const resJson = await this.webFetch(apiUrl, [mergedHeaders], body, method, contentType, true, "base64", "text")
this.logger.debug("向微信公众号请求数据,resJson =>", resJson)

return resJson ?? null
Expand Down

0 comments on commit e080cff

Please sign in to comment.