修改登录接口

This commit is contained in:
Cool 2024-11-05 18:38:23 +08:00
parent f570189652
commit e3c9470b4d
1 changed files with 54 additions and 54 deletions

View File

@ -1,13 +1,15 @@
package main package main
import ( import (
"fmt"
"strings"
"net/http"
"io/ioutil"
"time"
"os"
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
"github.com/eatmoreapple/openwechat" "github.com/eatmoreapple/openwechat"
) )
@ -57,19 +59,18 @@ func HttpPost(url string, data interface{}, timelim int) []byte {
result, _ := ioutil.ReadAll(resp.Body) result, _ := ioutil.ReadAll(resp.Body)
return result return result
// ——————————————— // ———————————————
// 版权声明本文为CSDN博主「gaoluhua」的原创文章遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。 // 版权声明本文为CSDN博主「gaoluhua」的原创文章遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。
// 原文链接https://blog.csdn.net/gaoluhua/article/details/124855716 // 原文链接https://blog.csdn.net/gaoluhua/article/details/124855716
} }
func main() { func main() {
bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式,上面登录不上的可以尝试切换这种模式 bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式
reloadStorage := openwechat.NewJsonFileHotReloadStorage("storage.json")
defer reloadStorage.Close()
err := bot.PushLogin(reloadStorage, openwechat.NewRetryLoginOption()) // 注册登陆二维码回调
if err != nil { bot.UUIDCallback = openwechat.PrintlnQrcodeUrl
if err := bot.Login(); err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
@ -119,10 +120,9 @@ func main() {
// 调用Stable Diffusion // 调用Stable Diffusion
// msg.ReplyText("这个功能还没有实现,可以先期待一下~") // msg.ReplyText("这个功能还没有实现,可以先期待一下~")
sender, _ := msg.Sender() sender, _ := msg.Sender()
content = strings.TrimLeft(content[len("生成图片"):], " \t\n") content = strings.TrimLeft(content[len("生成图片"):], " \t\n")
resp_raw := HttpPost("http://localhost:11111/draw", GenerateImageRequest{UserName : sender.ID(), Prompt : content}, 120) resp_raw := HttpPost("http://localhost:11111/draw", GenerateImageRequest{UserName: sender.ID(), Prompt: content}, 120)
if len(resp_raw) == 0 { if len(resp_raw) == 0 {
msg.ReplyText("生成图片出错啦QwQ或许可以再试一次") msg.ReplyText("生成图片出错啦QwQ或许可以再试一次")
return return
@ -132,7 +132,7 @@ func main() {
json.Unmarshal(resp_raw, &resp) json.Unmarshal(resp_raw, &resp)
//fmt.Println(resp.FileName) //fmt.Println(resp.FileName)
if resp.HasError { if resp.HasError {
msg.ReplyText( fmt.Sprintf("生成图片出错啦QwQ错误信息是%s", resp.ErrorMessage) ) msg.ReplyText(fmt.Sprintf("生成图片出错啦QwQ错误信息是%s", resp.ErrorMessage))
} else { } else {
for i := 0; i < len(resp.FileNames); i++ { for i := 0; i < len(resp.FileNames); i++ {
img, _ := os.Open(resp.FileNames[i]) img, _ := os.Open(resp.FileNames[i])
@ -149,14 +149,14 @@ func main() {
var group *openwechat.Group = nil var group *openwechat.Group = nil
if msg.IsSendByGroup() { if msg.IsSendByGroup() {
group = &openwechat.Group{User : sender} group = &openwechat.Group{User: sender}
} }
if content == "重置上下文" { if content == "重置上下文" {
if !msg.IsSendByGroup() { if !msg.IsSendByGroup() {
HttpPost("http://localhost:11111/chat_clear", SendTextRequest{InGroup : msg.IsSendByGroup(), UserID : sender.ID(), Text : ""}, 60) HttpPost("http://localhost:11111/chat_clear", SendTextRequest{InGroup: msg.IsSendByGroup(), UserID: sender.ID(), Text: ""}, 60)
} else { } else {
HttpPost("http://localhost:11111/chat_clear", SendTextRequest{InGroup : msg.IsSendByGroup(), UserID : group.ID(), Text : ""}, 60) HttpPost("http://localhost:11111/chat_clear", SendTextRequest{InGroup: msg.IsSendByGroup(), UserID: group.ID(), Text: ""}, 60)
} }
msg.ReplyText("OK我忘掉了之前的上下文。") msg.ReplyText("OK我忘掉了之前的上下文。")
return return
@ -166,9 +166,9 @@ func main() {
resp_raw := []byte("") resp_raw := []byte("")
if !msg.IsSendByGroup() { if !msg.IsSendByGroup() {
resp_raw = HttpPost("http://localhost:11111/chat", SendTextRequest{InGroup : false, UserID : sender.ID(), Text : msg.Content}, 60) resp_raw = HttpPost("http://localhost:11111/chat", SendTextRequest{InGroup: false, UserID: sender.ID(), Text: msg.Content}, 60)
} else { } else {
resp_raw = HttpPost("http://localhost:11111/chat", SendTextRequest{InGroup : false, UserID : group.ID(), Text : msg.Content}, 60) resp_raw = HttpPost("http://localhost:11111/chat", SendTextRequest{InGroup: false, UserID: group.ID(), Text: msg.Content}, 60)
} }
if len(resp_raw) == 0 { if len(resp_raw) == 0 {
msg.ReplyText("运算超时了QAQ或许可以再试一次。") msg.ReplyText("运算超时了QAQ或许可以再试一次。")