realname.go 774 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // http client
  10. const (
  11. smsURL = "http://api.bilibili.co/x/internal/sms/send"
  12. )
  13. // SendCapture is
  14. func (d *Dao) SendCapture(c context.Context, mid int64, code int) (err error) {
  15. var (
  16. params = url.Values{}
  17. )
  18. params.Set("mid", fmt.Sprintf("%d", mid))
  19. params.Set("tcode", "acc_01")
  20. params.Set("tparam", fmt.Sprintf(`{"identify_code":"%d"}`, code))
  21. var resp struct {
  22. Code int `json:"code"`
  23. }
  24. for i := 0; i < 3; i++ {
  25. err = d.client.Post(c, smsURL, "", params, &resp)
  26. if err != nil || resp.Code != 0 {
  27. log.Error("d.client.Post(%s,%+v) resp.Code(%d)", smsURL, params, resp.Code)
  28. err = ecode.RealnameCaptureErr
  29. } else {
  30. break
  31. }
  32. }
  33. return
  34. }