liveCaptcha.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/live/captcha/api/liverpc/v0"
  5. "go-common/app/service/live/captcha/api/liverpc/v1"
  6. "go-common/library/log"
  7. )
  8. // LiveCreate call liveRpc for create captcha
  9. func (d *Dao) LiveCreate(ctx context.Context, width int64, height int64) (resp *v1.CaptchaCreateResp_Data, err error) {
  10. resp = &v1.CaptchaCreateResp_Data{}
  11. rpcReq := &v1.CaptchaCreateReq{
  12. Width: width,
  13. Height: height,
  14. }
  15. rpcResp, err := d.liveCaptcha.V1Captcha.Create(ctx, rpcReq)
  16. if err != nil {
  17. log.Error("[XCaptcha][Create][call liveCaptcha] call error, error:%s", err.Error())
  18. return
  19. }
  20. if rpcResp.Data == nil {
  21. log.Error("[XCaptcha][create][call liveCaptcha] return error, response.data is nil")
  22. return
  23. }
  24. code := rpcResp.Code
  25. msg := rpcResp.Msg
  26. if code != 0 {
  27. log.Error("[XCaptcha][Create][call liveCaptcha] create error, code:%s, msg:%s, data:%s", code, msg, resp)
  28. return
  29. }
  30. resp = rpcResp.Data
  31. return
  32. }
  33. // LiveCheck liveCaptcha check
  34. func (d *Dao) LiveCheck(ctx context.Context, token string, phrase string) (resp int64, err error) {
  35. resp = -400
  36. rpcReq := &v0.CaptchaCheckReq{
  37. Token: token,
  38. Phrase: phrase,
  39. }
  40. rpcResp, err := d.liveCaptcha.V0Captcha.Check(ctx, rpcReq)
  41. if err != nil {
  42. log.Error("[XCaptcha][verify][call liveCaptcha] call error, error:%s", err.Error())
  43. return
  44. }
  45. if rpcResp == nil {
  46. log.Error("[XCaptcha][verify][call liveCaptcha] return error, response is nil")
  47. return
  48. }
  49. resp = rpcResp.Code
  50. return
  51. }