修理图片下载,增加消息中缺少的字段
This commit is contained in:
Vendored
+21
-2
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
@@ -196,6 +197,7 @@ func SendIMG(c *gin.Context) {
|
||||
var RequestData struct {
|
||||
Path string `json:"path"`
|
||||
Receiver string `json:"receiver"`
|
||||
Suffix string `json:"suffix"`
|
||||
}
|
||||
if err := c.BindJSON(&RequestData); err != nil {
|
||||
result.Code = 0
|
||||
@@ -205,6 +207,9 @@ func SendIMG(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, result)
|
||||
return
|
||||
}
|
||||
if RequestData.Path[0:4] == "http" {
|
||||
RequestData.Path, _ = DownloadFile(RequestData.Path, "file", RequestData.Suffix)
|
||||
}
|
||||
result.Code = 1
|
||||
result.Message = "发送完成"
|
||||
var data = WxClient.SendIMG(RequestData.Path, RequestData.Receiver)
|
||||
@@ -218,6 +223,7 @@ func SendFile(c *gin.Context) {
|
||||
var RequestData struct {
|
||||
Path string `json:"path"`
|
||||
Receiver string `json:"receiver"`
|
||||
Suffix string `json:"suffix"`
|
||||
}
|
||||
if err := c.BindJSON(&RequestData); err != nil {
|
||||
result.Code = 0
|
||||
@@ -227,6 +233,9 @@ func SendFile(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, result)
|
||||
return
|
||||
}
|
||||
if RequestData.Path[0:4] == "http" {
|
||||
RequestData.Path, _ = DownloadFile(RequestData.Path, "file", RequestData.Suffix)
|
||||
}
|
||||
result.Code = 1
|
||||
result.Message = "发送完成"
|
||||
var data = WxClient.SendFile(RequestData.Path, RequestData.Receiver)
|
||||
@@ -444,7 +453,17 @@ func DownloadAttach(c *gin.Context) {
|
||||
}
|
||||
result.Code = 1
|
||||
result.Message = "下载附件调用成功"
|
||||
var data = WxClient.DownloadAttach(RequestData.Id, RequestData.Thumb, RequestData.Extra)
|
||||
result.Data = data
|
||||
WxClient.DownloadAttach(RequestData.Id, "", RequestData.Extra)
|
||||
times := 1
|
||||
path := ""
|
||||
for times < 30 {
|
||||
path = WxClient.DecryptImage(RequestData.Extra, RequestData.Thumb)
|
||||
if path != "func:FUNC_DECRYPT_IMAGE str:\"\"" && path != "func:FUNC_DECRYPT_IMAGE str:\"\"" {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond * 1000)
|
||||
times += 1
|
||||
}
|
||||
result.Data = map[string]string{"path": path}
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
Vendored
+58
-1
@@ -10,8 +10,15 @@ extern int WxDestroySDK();
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/google/uuid"
|
||||
"go_wechatFerry/wcf"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,6 +26,7 @@ var WxClient *wcf.Client
|
||||
|
||||
// Message 组装成一个结构体展示消息
|
||||
type Message struct {
|
||||
IsSelf bool `json:"is_self,omitempty"`
|
||||
IsGroup bool `json:"is_group,omitempty"`
|
||||
MessageId uint64 `json:"message_id,omitempty"`
|
||||
Type uint32 `json:"type,omitempty"`
|
||||
@@ -27,12 +35,13 @@ type Message struct {
|
||||
Content string `json:"content,omitempty"`
|
||||
WxId string `json:"wx_id,omitempty"`
|
||||
Sign string `json:"sign,omitempty"`
|
||||
Thumb string `json:"thumb,omitempty"`
|
||||
Extra string `json:"extra,omitempty"`
|
||||
Xml string `json:"xml,omitempty"`
|
||||
}
|
||||
|
||||
// WechatFerryInit 调用sdk.dll中的WxInitSdk 进行启动微信并注入
|
||||
func WechatFerryInit() {
|
||||
|
||||
// 调试模式 端口
|
||||
initSuccess := C.WxInitSDK(C.bool(false), C.int(10086))
|
||||
if initSuccess == 0 {
|
||||
@@ -60,6 +69,13 @@ func WechatFerryInit() {
|
||||
fmt.Println("初始化完成")
|
||||
}
|
||||
|
||||
// MessageProcess 在这里可以继续写代码了
|
||||
func MessageProcess(msg Message) {
|
||||
// 方法都在WxClient中
|
||||
//WxClient.SendTxt("测试","","")
|
||||
fmt.Println(msg)
|
||||
}
|
||||
|
||||
// ContactsInit 通讯录初始化
|
||||
func ContactsInit() {
|
||||
var contactsMap []map[string]string
|
||||
@@ -86,3 +102,44 @@ func ContactsInit() {
|
||||
}
|
||||
WxClient.ContactsMap = contactsMap
|
||||
}
|
||||
|
||||
// DownloadFile 下载文件
|
||||
func DownloadFile(url string, fileType string, suffix string) (string, error) {
|
||||
fmt.Println(url)
|
||||
// 发送HTTP请求获取文件
|
||||
resp, err := resty.New().R().Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 获取当前日期
|
||||
currentTime := time.Now()
|
||||
datePath := filepath.Join("./resource/static/"+fileType, currentTime.Format("2006-01-02"))
|
||||
// 创建目录
|
||||
if err := os.MkdirAll(datePath, os.ModePerm); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 生成唯一的文件名
|
||||
fileName := uuid.New().String() + "." + suffix
|
||||
filePath := filepath.Join(datePath, fileName)
|
||||
|
||||
// 创建文件
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
// 将HTTP响应的Body复制到文件
|
||||
_, err = io.Copy(file, bytes.NewBuffer(resp.Body()))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
currentDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
filePath = currentDir + "/" + filePath
|
||||
filePath = strings.Replace(filePath, "\\", "/", -1)
|
||||
return filePath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user