This commit is contained in:
xxj
2022-11-29 22:19:28 +08:00
parent fbda2e3cb3
commit c5e66eaa54
2 changed files with 29 additions and 1 deletions

View File

@@ -100,6 +100,24 @@ func WriteFile(fname string, src []string, isClear bool) bool {
return true
}
// WriteFile 写入文件
func WriteFileEx(fname string, src []byte, isClear bool) bool {
flag := os.O_CREATE | os.O_WRONLY | os.O_TRUNC
if !isClear {
flag = os.O_CREATE | os.O_RDWR | os.O_APPEND
}
f, err := os.OpenFile(fname, flag, 0666)
if err != nil {
mylog.Error(err)
return false
}
defer f.Close()
f.Write(src)
return true
}
// ReadFile 读取文件
func ReadFile(fname string) (src []string) {
f, err := os.OpenFile(fname, os.O_RDONLY, 0666)

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"path"
"strconv"
"strings"
"time"
@@ -14,8 +15,10 @@ import (
"github.com/usthooz/gutil"
"github.com/xxjwxc/public/message"
"github.com/xxjwxc/public/mycache"
"github.com/xxjwxc/public/myglobal"
"github.com/xxjwxc/public/myhttp"
"github.com/xxjwxc/public/mylog"
"github.com/xxjwxc/public/tools"
)
const (
@@ -397,7 +400,14 @@ func (_wx *wxTools) GetMaterial(mediaId string) (string, error) {
bo, _ := json.Marshal(req)
resb, _ := myhttp.OnPostJSON(_setGetMaterial+accessToken, string(bo))
var res MediaResp
json.Unmarshal(resb, &res)
fmt.Println(string(resb))
err = json.Unmarshal(resb, &res)
if err != nil {
id := fmt.Sprintf("/file/img/%v.jpg", myglobal.GetNode().GetID())
fileName := path.Join(tools.GetCurrentDirectory(), id)
tools.WriteFileEx(fileName, resb, true)
return id, nil
}
if len(res.DownUrl) > 0 {
return res.DownUrl, nil
}