|
|
package cmd
|
|
|
|
|
|
import (
|
|
|
"github.com/go-resty/resty/v2"
|
|
|
"github.com/mizuki1412/go-core-kit/class/exception"
|
|
|
"github.com/mizuki1412/go-core-kit/init/initkit"
|
|
|
"github.com/mizuki1412/go-core-kit/service/configkit"
|
|
|
"github.com/mizuki1412/go-core-kit/service/logkit"
|
|
|
"github.com/spf13/cast"
|
|
|
"github.com/spf13/cobra"
|
|
|
"github.com/tidwall/gjson"
|
|
|
"net/url"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
//法治在沃
|
|
|
|
|
|
func init() {
|
|
|
rootCmd.AddCommand(lawCmd)
|
|
|
defFlagsLaw(lawCmd)
|
|
|
}
|
|
|
|
|
|
var lawCmd = &cobra.Command{
|
|
|
Use: "law",
|
|
|
Short: "Batch processing operations of the law platform",
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
initkit.BindFlags(cmd)
|
|
|
handle()
|
|
|
},
|
|
|
}
|
|
|
|
|
|
func defFlagsLaw(cmd *cobra.Command) {
|
|
|
cmd.Flags().String("cookie", "", "*Specify the cookie")
|
|
|
}
|
|
|
|
|
|
var lawClient = resty.New().SetRetryCount(5).SetRetryWaitTime(10 * time.Second)
|
|
|
|
|
|
func handle() {
|
|
|
resp, err := lawClient.R().
|
|
|
SetHeaders(map[string]string{
|
|
|
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
|
"Cookie": cast.ToString(configkit.Get("cookie", "")),
|
|
|
}).SetFormData(map[string]string{
|
|
|
"pid": "0",
|
|
|
}).Post("http://lawplatform.unicom.local/law/tpubTreeMenu/getMenuByRole.do")
|
|
|
if err != nil || resp.IsError() || gjson.Get(resp.String(), "ok").Bool() != true {
|
|
|
panic(exception.New("获取菜单失败"))
|
|
|
}
|
|
|
data := gjson.Get(resp.String(), "data.menuList").Array()
|
|
|
for _, v := range data {
|
|
|
for _, vv := range gjson.Get(v.String(), "chirlds").Array() {
|
|
|
for _, vvv := range gjson.Get(vv.String(), "chirlds").Array() {
|
|
|
rawURL := gjson.Get(vvv.String(), "tpubTreeMenuUrl").String()
|
|
|
resp, err = lawClient.R().
|
|
|
SetHeaders(map[string]string{
|
|
|
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
|
"Cookie": cast.ToString(configkit.Get("cookie", "")),
|
|
|
}).SetFormData(map[string]string{
|
|
|
"page": "1",
|
|
|
"pageSize": "1000",
|
|
|
}).Post(getUrl(rawURL))
|
|
|
if err != nil || resp.IsError() || resp.StatusCode() != 200 {
|
|
|
panic(exception.New("获取文章列表失败"))
|
|
|
}
|
|
|
articleData := gjson.Get(resp.String(), "data").Array()
|
|
|
for _, a := range articleData {
|
|
|
infoId := gjson.Get(a.String(), "infoId").String()
|
|
|
creatorTime := gjson.Get(a.String(), "creatorTime").String()
|
|
|
//TODO 以后每年修改这个
|
|
|
if !strings.Contains(creatorTime, "2024") {
|
|
|
logkit.Info("非2024文章,跳过...")
|
|
|
continue
|
|
|
}
|
|
|
resp, err = lawClient.R().
|
|
|
SetHeaders(map[string]string{
|
|
|
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
|
"Cookie": cast.ToString(configkit.Get("cookie", "")),
|
|
|
}).SetFormData(map[string]string{
|
|
|
"infoId": infoId,
|
|
|
}).Post("http://lawplatform.unicom.local/law/tpfLike/toLike.do")
|
|
|
if err != nil || resp.IsError() || resp.StatusCode() != 200 {
|
|
|
panic(exception.New("点赞失败"))
|
|
|
} else {
|
|
|
time.Sleep(1 * time.Second)
|
|
|
logkit.Info("点赞成功~")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func getUrl(rawURL string) string {
|
|
|
// 解析 URL
|
|
|
u, err := url.Parse(rawURL)
|
|
|
if err != nil {
|
|
|
panic(exception.New("解析URL失败"))
|
|
|
}
|
|
|
// 提取查询参数
|
|
|
queryParams := u.Query()
|
|
|
// 获取 pftype 的值
|
|
|
pfType := queryParams.Get("pftype")
|
|
|
uri := "http://lawplatform.unicom.local/law/tpfInfoQuery/findPfInfoList.do?pftype=" + pfType + "&pfsortLevel=3&cache_id=" + cast.ToString(time.Now().UnixMilli())
|
|
|
return uri
|
|
|
}
|