44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package Netease
|
|
|
|
import (
|
|
"servicebase/pkg/log"
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/viper"
|
|
captcha "github.com/yidun/yidun-golang-sdk/yidun/service/captcha"
|
|
)
|
|
|
|
var (
|
|
CaptchaId = "28a052c000324d2e992e9e184291c92d"
|
|
)
|
|
|
|
// CaptchaSecondVerify 验证码二次校验请求
|
|
func CaptchaSecondVerify(captchaId, validate string) (bool, error) {
|
|
request := captcha.NewCaptchaVerifyRequest()
|
|
var user string = ""
|
|
request.SetCaptchaId(captchaId).SetValidate(validate).SetUser(user)
|
|
secretId := viper.GetString("netease.captcha.secretId")
|
|
secretKey := viper.GetString("netease.captcha.secretKey")
|
|
captchaClient := captcha.NewCaptchaVerifyClientWithAccessKey(secretId, secretKey)
|
|
response, err := captchaClient.Verify(request)
|
|
if err != nil {
|
|
log.ErrorF("CaptchaSecondVerify err: %+v", err)
|
|
return false, err
|
|
}
|
|
if response == nil {
|
|
log.ErrorF("CaptchaSecondVerify response is nil")
|
|
return false, errors.Errorf("CaptchaSecondVerify response is nil")
|
|
}
|
|
respBody, err := json.Marshal(response)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
log.InfoF("CaptchaSecondVerify response is : %s", string(respBody))
|
|
if response.Result == nil {
|
|
log.ErrorF("CaptchaSecondVerify response.Result is nil")
|
|
return false, errors.Errorf("CaptchaSecondVerify response.Result is nil")
|
|
}
|
|
return *response.Result, nil
|
|
}
|