-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
743e550
commit 4075c92
Showing
9 changed files
with
561 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# qq空间表白墙 | ||
|
||
## 参考 | ||
|
||
* [opq-osc/OPQBot](https://github.com/opq-osc/OPQBot) QQ空间发表说说流程 | ||
* [【Ono】QQ空间协议分析----扫码登录----【1】](https://www.52pojie.cn/thread-1022123-1-1.html) QQ空间扫码登录流程 | ||
|
||
## 优化点 | ||
- [ ] 匿名头像背景颜色优化 | ||
- [ ] 转发消息生成图片气泡背景板 | ||
- [x] 查看说说消息分页 (优先) | ||
- [ ] 加zbp水印 (优先) | ||
- [ ] 发表白墙互动优化, 监听对话 | ||
- [ ] 自动审核稿 | ||
- [x] 一次同意多条说说并发送 (优先) | ||
- [ ] 拒绝说说的时候可发送拒绝消息 | ||
- [ ] 表白墙接入钱包 (待定) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package qzone | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
_ "github.com/fumiama/sqlite3" // use sql | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
// qdb qq空间数据库全局变量 | ||
var qdb *qzonedb | ||
|
||
// qzonedb qq空间数据库结构体 | ||
type qzonedb gorm.DB | ||
|
||
// initialize 初始化 | ||
func initialize(dbpath string) *qzonedb { | ||
var err error | ||
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) { | ||
// 生成文件 | ||
f, err := os.Create(dbpath) | ||
if err != nil { | ||
return nil | ||
} | ||
defer f.Close() | ||
} | ||
qdb, err := gorm.Open("sqlite3", dbpath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
qdb.AutoMigrate(&qzoneConfig{}).AutoMigrate(&emotion{}) | ||
return (*qzonedb)(qdb) | ||
} | ||
|
||
// qzoneConfig qq空间初始化信息 | ||
type qzoneConfig struct { | ||
ID uint `gorm:"primary_key;AUTO_INCREMENT"` | ||
QQ int64 `gorm:"column:qq;unique;not null"` | ||
Cookie string `gorm:"column:cookie;type:varchar(1024)"` | ||
} | ||
|
||
// TableName 表名 | ||
func (qzoneConfig) TableName() string { | ||
return "qzone_config" | ||
} | ||
|
||
func (qdb *qzonedb) insertOrUpdate(qq int64, cookie string) (err error) { | ||
db := (*gorm.DB)(qdb) | ||
qc := qzoneConfig{ | ||
QQ: qq, | ||
Cookie: cookie, | ||
} | ||
var oqc qzoneConfig | ||
err = db.Take(&oqc, "qq = ?", qc.QQ).Error | ||
if err != nil { | ||
if gorm.IsRecordNotFoundError(err) { | ||
err = db.Create(&qc).Error | ||
} | ||
return | ||
} | ||
err = db.Model(&oqc).Updates(qc).Error | ||
return | ||
} | ||
|
||
func (qdb *qzonedb) getByUin(qq int64) (qc qzoneConfig, err error) { | ||
db := (*gorm.DB)(qdb) | ||
err = db.Take(&qc, "qq = ?", qq).Error | ||
return | ||
} | ||
|
||
// emotion 说说信息 | ||
type emotion struct { | ||
gorm.Model | ||
Anonymous bool `gorm:"column:anonymous"` | ||
QQ int64 `gorm:"column:qq"` | ||
Msg string `gorm:"column:msg"` | ||
Status int `gorm:"column:status"` // 1-审核中,2-同意,3-拒绝 | ||
Tag string `gorm:"column:tag"` | ||
} | ||
|
||
func (e emotion) textBrief() (t string) { | ||
t = fmt.Sprintf("序号: %v\nQQ: %v\n创建时间: %v\n", e.ID, e.QQ, e.CreatedAt.Format("2006-01-02 15:04:05")) | ||
switch e.Status { | ||
case 1: | ||
t += "状态: 审核中\n" | ||
case 2: | ||
t += "状态: 同意\n" | ||
case 3: | ||
t += "状态: 拒绝\n" | ||
} | ||
if e.Anonymous { | ||
t += "匿名: 是" | ||
} else { | ||
t += "匿名: 否" | ||
} | ||
return | ||
} | ||
|
||
// TableName 表名 | ||
func (emotion) TableName() string { | ||
return "emotion" | ||
} | ||
|
||
func (qdb *qzonedb) saveEmotion(e emotion) (id int64, err error) { | ||
db := (*gorm.DB)(qdb) | ||
err = db.Create(&e).Error | ||
id = int64(e.ID) | ||
return | ||
} | ||
|
||
func (qdb *qzonedb) getEmotionByIDList(idList []int64) (el []emotion, err error) { | ||
db := (*gorm.DB)(qdb) | ||
err = db.Find(&el, "id in (?)", idList).Error | ||
return | ||
} | ||
|
||
func (qdb *qzonedb) getLoveEmotionByStatus(status int, pageNum int) (el []emotion, err error) { | ||
db := (*gorm.DB)(qdb) | ||
if status == 0 { | ||
err = db.Order("created_at desc").Limit(5).Offset(pageNum*5).Find(&el, "tag like ?", "%"+loveTag+"%").Error | ||
return | ||
} | ||
err = db.Order("created_at desc").Limit(5).Offset(pageNum*5).Find(&el, "status = ? and tag like ?", status, "%"+loveTag+"%").Error | ||
return | ||
} | ||
|
||
func (qdb *qzonedb) updateEmotionStatusByIDList(idList []int64, status int) (err error) { | ||
db := (*gorm.DB)(qdb) | ||
err = db.Model(&emotion{}).Where("id in (?)", idList).Update("status", status).Error | ||
return | ||
} |
Oops, something went wrong.