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