parent
f52feef2e8
commit
54373302cc
@ -0,0 +1,7 @@
|
||||
package cloudflare
|
||||
|
||||
type Client struct {
|
||||
AccountID string
|
||||
ZoneID string
|
||||
GlobalAPIKey string
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package cloudflare
|
||||
|
||||
const (
|
||||
URL = "https://api.cloudflare.com/client/v4/"
|
||||
)
|
@ -1,34 +1,72 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
ApiKey string
|
||||
Mongo gomongo.App // 日志数据库
|
||||
apiKey string // 密钥
|
||||
mongo *gomongo.Client // 日志数据库
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gohttp.Response, err error) {
|
||||
// NewApp 创建实例
|
||||
func NewApp(apiKey string, pgsql *gorm.DB) *App {
|
||||
app := &App{apiKey: apiKey}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "dingdanxia"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
// 请求接口
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 公共参数
|
||||
params["apikey"] = app.ApiKey
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
// 请求
|
||||
get, err := gohttp.Get(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, get)
|
||||
return get, err
|
||||
case http.MethodPost:
|
||||
// 请求
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, postJson)
|
||||
return postJson, err
|
||||
default:
|
||||
return resp, errors.New("请求类型不支持")
|
||||
params["apikey"] = app.apiKey
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeForm()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.mongo != nil && app.mongo.Db != nil {
|
||||
go app.mongoLog(request)
|
||||
}
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "dingdanxia"
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(request gorequest.Response) {
|
||||
_, _ = app.mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: request.RequestParams, //【请求】参数
|
||||
RequestHeader: request.RequestHeader, //【请求】头部
|
||||
ResponseHeader: request.ResponseHeader, //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: gomongo.JsonDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "dingdanxia_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gojson"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,39 +1,63 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Secret string
|
||||
AccessToken string
|
||||
Mongo gomongo.App // 日志数据库
|
||||
secret string
|
||||
accessToken string
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
// 请求
|
||||
get, err := gohttp.Get(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, get)
|
||||
return get.Body, err
|
||||
case http.MethodPost:
|
||||
// 请求参数
|
||||
paramsMarshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 请求
|
||||
postJson, err := gohttp.PostJson(url, paramsMarshal)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, postJson)
|
||||
return postJson.Body, err
|
||||
default:
|
||||
return nil, errors.New("请求类型不支持")
|
||||
func NewApp(secret, accessToken string, pgsql *gorm.DB) *App {
|
||||
app := &App{secret: secret, accessToken: accessToken}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "dingtalk"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "dingtalk_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
package douyin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/mvdan/xurls"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AnalysisResponse struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
ItemList []struct {
|
||||
AwemePoiInfo struct {
|
||||
Tag string `json:"tag"`
|
||||
Icon struct {
|
||||
UrlList []string `json:"url_list"`
|
||||
Uri string `json:"uri"`
|
||||
} `json:"icon"`
|
||||
PoiName string `json:"poi_name"`
|
||||
TypeName string `json:"type_name"`
|
||||
} `json:"aweme_poi_info"`
|
||||
Images interface{} `json:"images"`
|
||||
Author struct {
|
||||
Geofencing interface{} `json:"geofencing"`
|
||||
CardEntries interface{} `json:"card_entries"`
|
||||
ShortId string `json:"short_id"`
|
||||
Nickname string `json:"nickname"`
|
||||
FollowStatus int `json:"follow_status"`
|
||||
UniqueId string `json:"unique_id"`
|
||||
PlatformSyncInfo interface{} `json:"platform_sync_info"`
|
||||
Uid string `json:"uid"`
|
||||
AvatarLarger struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"avatar_larger"`
|
||||
PolicyVersion interface{} `json:"policy_version"`
|
||||
MixInfo interface{} `json:"mix_info"`
|
||||
Signature string `json:"signature"`
|
||||
AvatarThumb struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"avatar_thumb"`
|
||||
AvatarMedium struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"avatar_medium"`
|
||||
FollowersDetail interface{} `json:"followers_detail"`
|
||||
TypeLabel interface{} `json:"type_label"`
|
||||
} `json:"author"`
|
||||
ChaList []struct {
|
||||
ViewCount int `json:"view_count"`
|
||||
HashTagProfile string `json:"hash_tag_profile"`
|
||||
Cid string `json:"cid"`
|
||||
CoverItem struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover_item"`
|
||||
UserCount int `json:"user_count"`
|
||||
ConnectMusic interface{} `json:"connect_music"`
|
||||
Type int `json:"type"`
|
||||
IsCommerce bool `json:"is_commerce"`
|
||||
ChaName string `json:"cha_name"`
|
||||
Desc string `json:"desc"`
|
||||
} `json:"cha_list"`
|
||||
Duration int `json:"duration"`
|
||||
LongVideo interface{} `json:"long_video"`
|
||||
Desc string `json:"desc"`
|
||||
AuthorUserId int64 `json:"author_user_id"`
|
||||
LabelTopText interface{} `json:"label_top_text"`
|
||||
IsPreview int `json:"is_preview"`
|
||||
CreateTime int `json:"create_time"`
|
||||
ShareUrl string `json:"share_url"`
|
||||
RiskInfos struct {
|
||||
Warn bool `json:"warn"`
|
||||
Type int `json:"type"`
|
||||
Content string `json:"content"`
|
||||
ReflowUnplayable int `json:"reflow_unplayable"`
|
||||
} `json:"risk_infos"`
|
||||
Promotions interface{} `json:"promotions"`
|
||||
Music struct {
|
||||
Duration int `json:"duration"`
|
||||
Id int64 `json:"id"`
|
||||
Mid string `json:"mid"`
|
||||
Title string `json:"title"`
|
||||
CoverHd struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover_hd"`
|
||||
CoverLarge struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover_large"`
|
||||
CoverMedium struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover_medium"`
|
||||
CoverThumb struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover_thumb"`
|
||||
Author string `json:"author"`
|
||||
PlayUrl struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"play_url"`
|
||||
Position interface{} `json:"position"`
|
||||
Status int `json:"status"`
|
||||
} `json:"music"`
|
||||
CommentList interface{} `json:"comment_list"`
|
||||
ForwardId string `json:"forward_id"`
|
||||
GroupIdStr string `json:"group_id_str"`
|
||||
Video struct {
|
||||
OriginCover struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"origin_cover"`
|
||||
HasWatermark bool `json:"has_watermark"`
|
||||
Duration int `json:"duration"`
|
||||
Height int `json:"height"`
|
||||
DynamicCover struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"dynamic_cover"`
|
||||
Width int `json:"width"`
|
||||
Ratio string `json:"ratio"`
|
||||
BitRate interface{} `json:"bit_rate"`
|
||||
Vid string `json:"vid"`
|
||||
PlayAddr struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"` // 真实去水印地址
|
||||
} `json:"play_addr"`
|
||||
Cover struct {
|
||||
Uri string `json:"uri"`
|
||||
UrlList []string `json:"url_list"`
|
||||
} `json:"cover"`
|
||||
} `json:"video"`
|
||||
TextExtra []struct {
|
||||
Start int `json:"start"`
|
||||
End int `json:"end"`
|
||||
Type int `json:"type"`
|
||||
HashtagName string `json:"hashtag_name"`
|
||||
HashtagId int64 `json:"hashtag_id"`
|
||||
} `json:"text_extra"`
|
||||
VideoLabels interface{} `json:"video_labels"`
|
||||
VideoText interface{} `json:"video_text"`
|
||||
AwemeType int `json:"aweme_type"`
|
||||
ImageInfos interface{} `json:"image_infos"`
|
||||
AwemeId string `json:"aweme_id"`
|
||||
Statistics struct {
|
||||
CommentCount int `json:"comment_count"`
|
||||
DiggCount int `json:"digg_count"`
|
||||
PlayCount int `json:"play_count"`
|
||||
ShareCount int `json:"share_count"`
|
||||
AwemeId string `json:"aweme_id"`
|
||||
} `json:"statistics"`
|
||||
IsLiveReplay bool `json:"is_live_replay"`
|
||||
ShareInfo struct {
|
||||
ShareWeiboDesc string `json:"share_weibo_desc"`
|
||||
ShareDesc string `json:"share_desc"`
|
||||
ShareTitle string `json:"share_title"`
|
||||
} `json:"share_info"`
|
||||
Geofencing interface{} `json:"geofencing"`
|
||||
GroupId int64 `json:"group_id"`
|
||||
} `json:"item_list"`
|
||||
FilterList []interface{} `json:"filter_list"`
|
||||
Extra struct {
|
||||
Now int64 `json:"now"`
|
||||
Logid string `json:"logid"`
|
||||
} `json:"extra"`
|
||||
}
|
||||
|
||||
type AnalysisResult struct {
|
||||
Result AnalysisResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func NewAnalysisResult(result AnalysisResponse, body []byte, http gorequest.Response, err error) *AnalysisResult {
|
||||
return &AnalysisResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// Analysis 抖音解析
|
||||
func (app *App) Analysis(content string) *AnalysisResult {
|
||||
|
||||
// 提取url
|
||||
var url string
|
||||
if strings.Contains(content, "douyin.com") {
|
||||
url = xurls.Relaxed.FindString(content)
|
||||
} else if strings.Contains(content, "iesdouyin.com") {
|
||||
url = xurls.Relaxed.FindString(content)
|
||||
} else {
|
||||
return NewAnalysisResult(AnalysisResponse{}, nil, gorequest.Response{}, errors.New("url为空"))
|
||||
}
|
||||
|
||||
// 重定向信息
|
||||
request302, err := app.request302(url)
|
||||
if err != nil {
|
||||
return NewAnalysisResult(AnalysisResponse{}, nil, gorequest.Response{}, err)
|
||||
}
|
||||
|
||||
// 提取编号
|
||||
itemIds := regexp.MustCompile(`\d+`).FindStringSubmatch(request302)
|
||||
if len(itemIds) < 1 {
|
||||
return NewAnalysisResult(AnalysisResponse{}, nil, gorequest.Response{}, errors.New("参数错误"))
|
||||
}
|
||||
|
||||
// 请求
|
||||
request, err := app.request("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+itemIds[0], map[string]interface{}{}, http.MethodGet)
|
||||
|
||||
// 定义
|
||||
var response AnalysisResponse
|
||||
err = json.Unmarshal(request.ResponseBody, &response)
|
||||
return NewAnalysisResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package douyin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
ua string // 用户代理
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func NewApp(pgsql *gorm.DB) *App {
|
||||
app := &App{ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "douyin"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置用户代理
|
||||
client.SetUserAgent(app.ua)
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
||||
func (app *App) request302(url string) (string, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
client := new(http.Client)
|
||||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||
return errors.New("redirect")
|
||||
}
|
||||
|
||||
response, err := client.Do(req)
|
||||
if err != nil {
|
||||
if response.StatusCode == http.StatusFound {
|
||||
location, err := response.Location()
|
||||
return location.String(), err
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (app *App) urlJudge(str string) string {
|
||||
if strings.Index(str, "douyin.com") != -1 || strings.Index(str, "iesdouyin.com") != -1 {
|
||||
return str
|
||||
}
|
||||
return ""
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package douyin
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,39 +1,76 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
AppID string
|
||||
ApiKey string
|
||||
Mongo gomongo.App // 日志数据库
|
||||
appId string
|
||||
apiKey string
|
||||
mongo *gomongo.Client // 日志数据库
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
func NewApp(appID string, apiKey string, pgsql *gorm.DB) *App {
|
||||
app := &App{appId: appID, apiKey: apiKey}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "eastiot"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 公共参数
|
||||
params["appId"] = app.AppID
|
||||
params["appId"] = app.appId
|
||||
params["timeStamp"] = time.Now().Unix()
|
||||
|
||||
// 签名
|
||||
params["sign"] = app.getSign(app.ApiKey, params)
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
// 请求
|
||||
get, err := gohttp.Get(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, get)
|
||||
return get.Body, err
|
||||
case http.MethodPost:
|
||||
// 请求
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, postJson)
|
||||
return postJson.Body, err
|
||||
default:
|
||||
return nil, errors.New("请求类型不支持")
|
||||
params["sign"] = app.getSign(app.apiKey, params)
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeForm()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.mongo != nil && app.mongo.Db != nil {
|
||||
go app.mongoLog(request)
|
||||
}
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "eastiot"
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(request gorequest.Response) {
|
||||
_, _ = app.mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: request.RequestParams, //【请求】参数
|
||||
RequestHeader: request.RequestHeader, //【请求】头部
|
||||
ResponseHeader: request.ResponseHeader, //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: gomongo.JsonDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "eastiot_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gojson"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,42 +1,79 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gomd5"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
UserID string
|
||||
Pwd string
|
||||
Key string
|
||||
signStr string
|
||||
Mongo gomongo.App // 日志数据库
|
||||
userId string
|
||||
pwd string
|
||||
key string
|
||||
signStr string
|
||||
mongo *gomongo.Client // 日志数据库
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
func NewApp(userId string, pwd string, key string, pgsql *gorm.DB) *App {
|
||||
app := &App{userId: userId, pwd: pwd, key: key}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "ejiaofei"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 公共参数
|
||||
params["userid"] = app.UserID
|
||||
params["pwd"] = app.Pwd
|
||||
params["userid"] = app.userId
|
||||
params["pwd"] = app.pwd
|
||||
|
||||
// 签名
|
||||
params["userkey"] = gomd5.ToUpper(fmt.Sprintf("%s%s", app.signStr, app.Key))
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
// 请求
|
||||
get, err := gohttp.Get(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, get)
|
||||
return get.Body, err
|
||||
case http.MethodPost:
|
||||
// 请求
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, postJson)
|
||||
return postJson.Body, err
|
||||
default:
|
||||
return nil, errors.New("请求类型不支持")
|
||||
params["userkey"] = gomd5.ToUpper(fmt.Sprintf("%s%s", app.signStr, app.key))
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeForm()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.mongo != nil && app.mongo.Db != nil {
|
||||
go app.mongoLog(request)
|
||||
}
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseXml string `json:"response_xml" bson:"response_xml"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "ejiaofei"
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(request gorequest.Response) {
|
||||
_, _ = app.mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: request.RequestParams, //【请求】参数
|
||||
RequestHeader: request.RequestHeader, //【请求】头部
|
||||
ResponseHeader: request.ResponseHeader, //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: gomongo.XmlDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseXml: string(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "ejiaofei_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: string(request.Body),
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gojson"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: datatypes.JSON(gojson.JsonEncodeNoError(gomongo.XmlDecodeNoError(request.ResponseBody))), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,23 +1,59 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Key string
|
||||
Mongo gomongo.App // 日志数据库
|
||||
key string
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) (body []byte, err error) {
|
||||
// 请求参数
|
||||
paramsStr, err := json.Marshal(params)
|
||||
// 请求
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
func NewApp(key string, pgsql *gorm.DB) *App {
|
||||
app := &App{key: key}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "feishu"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Post()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
go app.mongoLog(url, params, http.MethodPost, postJson)
|
||||
return postJson.Body, err
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "feishu_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "jd_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(api string, request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: api, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
CodeAbnormal = 0 // 异常
|
||||
CodeError = http.StatusInternalServerError // 失败
|
||||
CodeSuccess = http.StatusOK // 成功
|
||||
CodeEnd = http.StatusCreated // 结束
|
||||
)
|
||||
|
||||
// 每隔n秒执行一次
|
||||
const specSeconds = "*/%d * * * * *"
|
||||
|
||||
// GetSpecSeconds 每隔n秒执行一次
|
||||
var GetSpecSeconds = func(n int64) string {
|
||||
if n < 0 && n > 59 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(specSeconds, n)
|
||||
}
|
||||
|
||||
// GetFrequencySeconds 每隔n秒执行一次
|
||||
var GetFrequencySeconds = func(n int64) int64 {
|
||||
if n < 0 && n > 59 {
|
||||
return -1
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// 每隔n分钟执行一次
|
||||
const specMinutes = "0 */%d * * * *"
|
||||
|
||||
// GetSpecMinutes 每隔n分钟执行一次
|
||||
var GetSpecMinutes = func(n int64) string {
|
||||
if n < 0 && n > 59 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(specMinutes, n)
|
||||
}
|
||||
|
||||
// GetFrequencyMinutes 每隔n分钟执行一次
|
||||
var GetFrequencyMinutes = func(n int64) int64 {
|
||||
if n < 0 && n > 59 {
|
||||
return -1
|
||||
}
|
||||
return n * 60
|
||||
}
|
||||
|
||||
// 每天n点执行一次
|
||||
const specHour = "0 0 */%d * * *"
|
||||
|
||||
// GetSpecHour 每天n点执行一次
|
||||
var GetSpecHour = func(n int64) string {
|
||||
if n < 0 && n > 23 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(specHour, n)
|
||||
}
|
||||
|
||||
// GetFrequencyHour 每天n点执行一次
|
||||
var GetFrequencyHour = func(n int64) int64 {
|
||||
if n < 0 && n > 23 {
|
||||
return -1
|
||||
}
|
||||
return n * 60 * 60
|
||||
}
|
@ -1,31 +1,69 @@
|
||||
package kashangwl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// App 卡商网服务
|
||||
type App struct {
|
||||
CustomerId int // 商家编号
|
||||
CustomerKey string // 商家密钥
|
||||
Mongo gomongo.App // 日志数据库
|
||||
customerId int // 商家编号
|
||||
customerKey string // 商家密钥
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) ([]byte, error) {
|
||||
func NewApp(customerId int, customerKey string, pgsql *gorm.DB) *App {
|
||||
app := &App{customerId: customerId, customerKey: customerKey}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "kashangwl"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
|
||||
|
||||
// 公共参数
|
||||
params["timestamp"] = time.Now().UnixNano() / 1e6
|
||||
params["customer_id"] = app.CustomerId
|
||||
params["customer_id"] = app.customerId
|
||||
|
||||
// 签名参数
|
||||
params["sign"] = app.getSign(app.CustomerKey, params)
|
||||
// 请求参数
|
||||
paramsStr, err := json.Marshal(params)
|
||||
// 请求
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
params["sign"] = app.getSign(app.customerKey, params)
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Post()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
go app.mongoLog(url, params, http.MethodPost, postJson)
|
||||
return postJson.Body, err
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
package kashangwl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "kashangwl_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package kashangwl
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"go.dtapp.net/library/utils/gojson"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
ua string
|
||||
mongo *gomongo.Client // 日志数据库
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func NewApp(pgsql *gorm.DB) *App {
|
||||
app := &App{ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "kuaishou"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package kuaishou
|
||||
|
||||
import "regexp"
|
||||
|
||||
func (app *App) ExtractImageLink(content string) []string {
|
||||
|
||||
//解析正则表达式,如果成功返回解释器
|
||||
reg := regexp.MustCompile(`\{"path":"(.*?)","width":\d+,"height":\d*}`)
|
||||
|
||||
//根据规则提取关键信息
|
||||
result := reg.FindAllStringSubmatch(content, -1)
|
||||
var imageLinks []string
|
||||
|
||||
if len(result) > 0 {
|
||||
for _, link := range result {
|
||||
imageLinks = append(imageLinks, "https://tx2.a.yximgs.com"+link[1])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return imageLinks
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package kuaishou
|
||||
|
||||
import "regexp"
|
||||
|
||||
func (app *App) ExtractVideoLink(content string) string {
|
||||
|
||||
//解析正则表达式,如果成功返回解释器
|
||||
reg := regexp.MustCompile(`"srcNoMark":"(.*?)"`)
|
||||
|
||||
//根据规则提取关键信息
|
||||
result := reg.FindAllStringSubmatch(content, -1)
|
||||
var videoLink string
|
||||
|
||||
if len(result) > 0 {
|
||||
videoLink = result[0][1]
|
||||
return videoLink
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (app *App) GetVideoHtml(url string, cookieStr string) (string, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
request, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
request.Header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")
|
||||
request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
||||
request.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
|
||||
// request.Header.Add("Host", "c.kuaishou.com")
|
||||
request.Header.Add("Cookie", cookieStr)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
response, _ := client.Do(request)
|
||||
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
return string(body), nil
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Link string
|
||||
Cookies string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (app *App) GetVideoLink(url string) Response {
|
||||
|
||||
result := Response{}
|
||||
|
||||
jar, err := cookiejar.New(&cookiejar.Options{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Jar: jar,
|
||||
}
|
||||
request, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
request.Header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1")
|
||||
request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
||||
request.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
|
||||
// request.Header.Add("Host", "c.kuaishou.com")
|
||||
// request.Header.Add("Host", "v.kuaishouapp.com")
|
||||
|
||||
result.Err = err
|
||||
var cookieList []string
|
||||
|
||||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||
|
||||
if len(via) > 10 {
|
||||
return errors.New("too many redirects")
|
||||
}
|
||||
|
||||
result.Link = req.URL.String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
response, _ := client.Do(request)
|
||||
|
||||
cookies := jar.Cookies(request.URL)
|
||||
for _, cookie := range cookies {
|
||||
cookieList = append(cookieList, cookie.String())
|
||||
}
|
||||
|
||||
result.Cookies = strings.Join(cookieList, ";")
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
return result
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "kuaishou"
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(request gorequest.Response) {
|
||||
_, _ = app.mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: request.RequestParams, //【请求】参数
|
||||
RequestHeader: request.RequestHeader, //【请求】头部
|
||||
ResponseHeader: request.ResponseHeader, //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: gomongo.JsonDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: golog.TimeString{Time: request.ResponseTime}, //【返回】时间
|
||||
})
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package leshuazf
|
||||
|
||||
import (
|
||||
"go.dtapp.net/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
RequestTime gomongo.BsonTime `json:"request_time" bson:"request_time"` //【请求】时间
|
||||
RequestUri string `json:"request_uri" bson:"request_uri"` //【请求】链接
|
||||
RequestUrl string `json:"request_url" bson:"request_url"` //【请求】链接
|
||||
RequestApi string `json:"request_api" bson:"request_api"` //【请求】接口
|
||||
RequestMethod string `json:"request_method" bson:"request_method"` //【请求】方式
|
||||
RequestParams gorequest.Params `json:"request_params" bson:"request_params"` //【请求】参数
|
||||
RequestHeader gorequest.Headers `json:"request_header" bson:"request_header"` //【请求】头部
|
||||
ResponseHeader http.Header `json:"response_header" bson:"response_header"` //【返回】头部
|
||||
ResponseStatusCode int `json:"response_status_code" bson:"response_status_code"` //【返回】状态码
|
||||
ResponseBody map[string]interface{} `json:"response_body" bson:"response_body"` //【返回】内容
|
||||
ResponseContentLength int64 `json:"response_content_length" bson:"response_content_length"` //【返回】大小
|
||||
ResponseTime gomongo.BsonTime `json:"response_time" bson:"response_time"` //【返回】时间
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_log"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "leshuazf"
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(request gorequest.Response) {
|
||||
_, _ = app.mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
RequestTime: gomongo.BsonTime(request.RequestTime), //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: request.RequestParams, //【请求】参数
|
||||
RequestHeader: request.RequestHeader, //【请求】头部
|
||||
ResponseHeader: request.ResponseHeader, //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: gomongo.JsonDecodeNoError(request.ResponseBody), //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: gomongo.BsonTime(request.ResponseTime), //【返回】时间
|
||||
})
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package leshuazf
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "leshuazf_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package leshuazf
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gojson"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 记录日志
|
||||
func (app *App) postgresqlLog(request gorequest.Response) {
|
||||
app.log.Api.Record(golog.ApiPostgresqlLog{
|
||||
RequestTime: request.RequestTime, //【请求】时间
|
||||
RequestUri: request.RequestUri, //【请求】链接
|
||||
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接
|
||||
RequestApi: gorequest.UriParse(request.RequestUri).Path, //【请求】接口
|
||||
RequestMethod: request.RequestMethod, //【请求】方式
|
||||
RequestParams: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestParams)), //【请求】参数
|
||||
RequestHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.RequestHeader)), //【返回】头部
|
||||
ResponseHeader: datatypes.JSON(gojson.JsonEncodeNoError(request.ResponseHeader)), //【返回】头部
|
||||
ResponseStatusCode: request.ResponseStatusCode, //【返回】状态码
|
||||
ResponseBody: request.ResponseBody, //【返回】内容
|
||||
ResponseContentLength: request.ResponseContentLength, //【返回】大小
|
||||
ResponseTime: request.ResponseTime, //【返回】时间
|
||||
})
|
||||
}
|
@ -1,36 +1,68 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"net/http"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// App 美团联盟
|
||||
type App struct {
|
||||
Secret string // 秘钥
|
||||
AppKey string // 渠道标记
|
||||
Mongo gomongo.App // 日志数据库
|
||||
secret string // 秘钥
|
||||
appKey string // 渠道标记
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
// 请求
|
||||
get, err := gohttp.Get(url, params)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, get)
|
||||
return get.Body, err
|
||||
case http.MethodPost:
|
||||
// 请求
|
||||
paramsStr, err := json.Marshal(params)
|
||||
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||
// 日志
|
||||
go app.mongoLog(url, params, method, postJson)
|
||||
return postJson.Body, err
|
||||
default:
|
||||
return nil, errors.New("请求类型不支持")
|
||||
func NewApp(secret string, appKey string, pgsql *gorm.DB) *App {
|
||||
app := &App{secret: secret, appKey: appKey}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "meituan"
|
||||
app.log = golog.NewApi(&golog.ApiConfig{
|
||||
Db: pgsql,
|
||||
TableName: app.logTableName,
|
||||
})
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
||||
|
||||
func (app *App) GetAppKey() string {
|
||||
return app.appKey
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go.dtapp.net/library/utils/gohttp"
|
||||
"go.dtapp.net/library/utils/gotime"
|
||||
)
|
||||
|
||||
// 日志
|
||||
type mongoZap struct {
|
||||
Url string `json:"url" bson:"url"`
|
||||
Params interface{} `json:"params" bson:"params"`
|
||||
Method string `json:"method" bson:"method"`
|
||||
Header interface{} `json:"header" bson:"header"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
StatusCode int `json:"status_code" bson:"status_code"`
|
||||
Body interface{} `json:"body" bson:"body"`
|
||||
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||
CreateTime string `json:"create_time" bson:"create_time"`
|
||||
}
|
||||
|
||||
func (m *mongoZap) Database() string {
|
||||
return "zap_logs"
|
||||
}
|
||||
|
||||
func (m *mongoZap) TableName() string {
|
||||
return "meituan_" + gotime.Current().SetFormat("200601")
|
||||
}
|
||||
|
||||
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||
if app.Mongo.Db == nil {
|
||||
return
|
||||
}
|
||||
var body map[string]interface{}
|
||||
_ = json.Unmarshal(request.Body, &body)
|
||||
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||
Url: url,
|
||||
Params: params,
|
||||
Method: method,
|
||||
Header: request.Header,
|
||||
Status: request.Status,
|
||||
StatusCode: request.StatusCode,
|
||||
Body: body,
|
||||
ContentLength: request.ContentLength,
|
||||
CreateTime: gotime.Current().Format(),
|
||||
})
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue