解决go1.16移除ioutil包的不兼容影响
This commit is contained in:
parent
7451a8c55f
commit
1c885a9182
@ -5,7 +5,6 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
@ -224,10 +223,11 @@ func (c *Client) WebWxUploadMedia(file *os.File, request BaseRequest, info Login
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
buffer := bytes.Buffer{}
|
||||
if _, err := buffer.ReadFrom(file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data := buffer.Bytes()
|
||||
fileMd5 := fmt.Sprintf("%x", md5.Sum(data))
|
||||
cookies := c.Jar.Cookies(path)
|
||||
uploadMediaRequest := map[string]interface{}{
|
||||
|
@ -1,9 +1,9 @@
|
||||
package openwechat
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@ -46,5 +46,9 @@ func (r *ReturnResponse) ReadAll() ([]byte, error) {
|
||||
if r.Err() != nil {
|
||||
return nil, r.Err()
|
||||
}
|
||||
return ioutil.ReadAll(r.Body)
|
||||
buffer := bytes.Buffer{}
|
||||
if _, err := buffer.ReadFrom(r.Body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
8
user.go
8
user.go
@ -1,8 +1,8 @@
|
||||
package openwechat
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
@ -62,11 +62,11 @@ func (u *User) SaveAvatar(filename string) error {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
buffer := bytes.Buffer{}
|
||||
if _, err := buffer.ReadFrom(resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(filename, data, os.ModePerm)
|
||||
return os.WriteFile(filename, buffer.Bytes(), os.ModePerm)
|
||||
}
|
||||
|
||||
func (u *User) sendMsg(msg *SendMessage) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user