Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjiang.liu committed Jul 11, 2022
1 parent c87ff5a commit cbf95e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
17 changes: 7 additions & 10 deletions server/api/v1/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,19 @@ func (b *BaseApi) ResetPassword(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}"
// @Router /base/login [post]
func (b *BaseApi) SendEmail(c *gin.Context) {

codestr := c.Query("codes")
codes := strings.Split(codestr, ",")
content := ""

// create allocator context for use with creating a browser context later
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
allocatorContext, cancel := chromedp.NewRemoteAllocator(ctx, "ws://"+global.GVA_CONFIG.Chromedp.Host+":9222")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
allocatorContext, cancel2 := chromedp.NewRemoteAllocator(ctx, "ws://"+global.GVA_CONFIG.Chromedp.Host+":9222")
defer cancel2()

// create context
ctxt, cancel := chromedp.NewContext(allocatorContext)
defer cancel()

content := ""
for _, code := range codes {
code, _ := strconv.Atoi(code)
stockinfo, err := userService.GetTTJiJinStockInfo(ctxt, (int(code)))
Expand All @@ -417,14 +416,12 @@ func (b *BaseApi) SendEmail(c *gin.Context) {
content += fmt.Sprintf("基金名称: %s 代码: %d 涨幅: %s <br>", stockinfo.Name, stockinfo.Code, stockinfo.Estimate)
}

emailtitle := fmt.Sprintf("天天基金-%s", time.Now().Format("2006/1/02 15:04"))
log.Println(emailtitle)
//发送邮件
if err := email.Email("[email protected],[email protected]", emailtitle, content); err != nil {
if err := email.Email("[email protected],[email protected]",
fmt.Sprintf("天天基金-%s", time.Now().Format("2006/1/02 15:04")), content); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Error(err))
response.FailWithMessage("发送失败", c)
return
}

response.Ok(c)
}
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/chromedp/cdproto v0.0.0-20220515234810-83d799542a04 // indirect
github.com/chromedp/chromedp v0.8.2
github.com/flipped-aurora/ws v1.0.2
github.com/fsnotify/fsnotify v1.4.9
Expand Down
27 changes: 26 additions & 1 deletion server/service/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"log"
"time"

"github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
"github.com/liujianjiang/goadmin/server/global"
"github.com/liujianjiang/goadmin/server/model/common/request"
Expand All @@ -20,6 +22,14 @@ import (
//@description: 用户注册
//@param: u model.SysUser
//@return: userInter system.SysUser, err error
const (
makeVisibleScript = `
var on = document.querySelector(".ip_tips_btn > span");
if (on) {
on.click();
}
`
)

type UserService struct{}

Expand Down Expand Up @@ -265,14 +275,29 @@ func (userService *UserService) ResetPassword(ID uint) (err error) {
func (userService *UserService) GetTTJiJinStockInfo(ctx context.Context, code int) (stock system.Stock, err error) {
stockinfo := system.Stock{}
url := fmt.Sprintf("http://fund.eastmoney.com/%d.html?spm=search", code)
log.Printf("get url: %s", url)
var html string
if err := chromedp.Run(ctx,
chromedp.Navigate(url),
chromedp.WaitVisible(`#gz_gszzl`),
chromedp.Sleep(1*time.Second),
//点击页面立即开启按钮
chromedp.ActionFunc(func(ctx context.Context) error {
_, exp, err := runtime.Evaluate(makeVisibleScript).Do(ctx)
if err != nil {
return err
}
if exp != nil {
return exp
}
return nil
}),
chromedp.Sleep(1*time.Second),
chromedp.TextContent(`#gz_gszzl`, &stockinfo.Estimate, chromedp.ByQuery),
chromedp.TextContent(`.fundDetail-tit`, &stockinfo.Name, chromedp.ByQuery),
); err != nil {
log.Printf("url: %s ,error: %s", url, err)
}
log.Println(html)

stockinfo.Code = code
return stockinfo, nil
Expand Down

0 comments on commit cbf95e4

Please sign in to comment.