1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 12:03:50 +08:00

feature solve silder.

This commit is contained in:
Mrs4s 2020-12-26 01:30:01 +08:00
parent 569b89a117
commit 99a68b144b
3 changed files with 32 additions and 8 deletions

View File

@ -4,6 +4,8 @@ import (
"bytes"
"compress/gzip"
"fmt"
"github.com/guonaihong/gout"
"github.com/pkg/errors"
"io/ioutil"
"net"
"net/http"
@ -62,6 +64,26 @@ func GetBytes(url string) ([]byte, error) {
return body, nil
}
func GetSilderTicket(raw, version string) (string, error) {
u, err := url.Parse(raw)
if err != nil {
return "", err
}
q := u.Query()
var rsp string
if err = gout.GET(fmt.Sprintf("https://api.shkong.com/gocqhttpapi/silder/ticket?uin=%v&sid=%v&cap=%v", q["uin"][0], q["sid"][0], q["cap_cd"][0])).
SetHeader(gout.H{"User-Agent": "go-cqhttp/" + version}).
BindBody(&rsp).
Do(); err != nil {
return "", err
}
g := gjson.Parse(rsp)
if g.Get("error").Str != "" {
return "", errors.New(g.Get("error").Str)
}
return g.Get("ticket").Str, nil
}
func QQMusicSongInfo(id string) (gjson.Result, error) {
d, err := GetBytes(`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:` + id + `},%22module%22:%22music.pf_song_detail_svr%22}}`)
if err != nil {

1
go.mod
View File

@ -17,6 +17,7 @@ require (
github.com/kr/binarydist v0.1.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/pkg/errors v0.9.1
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.7.0
github.com/syndtr/goleveldb v1.0.0

View File

@ -125,16 +125,17 @@ func (s *webServer) Dologin() {
if !rsp.Success {
switch rsp.Error {
case client.SliderNeededError:
if client.SystemDeviceInfo.Protocol == client.AndroidPhone {
log.Warnf("警告: Android Phone 强制要求暂不支持的滑条验证码, 请开启设备锁或切换到Watch协议验证通过后再使用.")
log.Infof("按 Enter 继续....")
readLine()
os.Exit(0)
}
log.Warnf("正在处理滑条验证码, 这可能需要一段时间.")
ticket, err := global.GetSilderTicket(rsp.VerifyUrl, coolq.Version)
if err != nil {
log.Warnf("处理滑条验证码时出现错误: %v 将尝试跳过.", err)
cli.AllowSlider = false
cli.Disconnect()
rsp, err = cli.Login()
continue
}
rsp, err = cli.SubmitTicket(ticket)
continue
case client.NeedCaptcha:
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))