mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
1
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user