add ali captcha
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"tyc-server/common/ctxdata"
|
||||
"tyc-server/common/globalkey"
|
||||
"tyc-server/common/xerr"
|
||||
"tyc-server/pkg/captcha"
|
||||
"tyc-server/pkg/lzkit/crypto"
|
||||
"tyc-server/pkg/lzkit/validator"
|
||||
|
||||
@@ -109,7 +110,52 @@ var productHandlers = map[string]queryHandlerFunc{
|
||||
"toc_BankcardBlacklist": runVerifyBankBlackReq,
|
||||
}
|
||||
|
||||
// productHasSmsCode 表示该 product 解密后的请求结构体中是否包含必填短信验证码 Code。
|
||||
// 有 Code 的产品在「获取验证码」时已经做了滑块,这里不再强制要求 CaptchaVerifyParam。
|
||||
// 其他产品(无 Code)在查询时必须传并校验 CaptchaVerifyParam,防止跳过图形验证。
|
||||
func productHasSmsCode(product string) bool {
|
||||
switch product {
|
||||
case "marriage",
|
||||
"homeservice",
|
||||
"riskassessment",
|
||||
"companyinfo",
|
||||
"rentalinfo",
|
||||
"preloanbackgroundcheck",
|
||||
"backgroundcheck",
|
||||
"personalData",
|
||||
"toc_PersonalLawsuit",
|
||||
"toc_EnterpriseLawsuit",
|
||||
"toc_Marriage",
|
||||
"toc_PersonalMarriageStatus",
|
||||
"toc_MarriageStatusRegisterTime",
|
||||
"toc_MarriageStatusSupplement",
|
||||
"toc_MarriageStatusVerify",
|
||||
"toc_DualMarriageStatusRegisterTime",
|
||||
"toc_VehiclesUnderName",
|
||||
"toc_VehiclesUnderNamePlate":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) {
|
||||
// 无短信验证码 Code 的 product:查询前必须传并校验滑块,否则不允许跳过
|
||||
if !productHasSmsCode(product) {
|
||||
if req.CaptchaVerifyParam == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("请完成图形验证"), "product %s requires captcha", product)
|
||||
}
|
||||
cfg := l.svcCtx.Config.Captcha
|
||||
if err := captcha.Verify(captcha.Config{
|
||||
AccessKeyID: cfg.AccessKeyID,
|
||||
AccessKeySecret: cfg.AccessKeySecret,
|
||||
EndpointURL: cfg.EndpointURL,
|
||||
SceneID: cfg.SceneID,
|
||||
}, req.CaptchaVerifyParam); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
decryptData, err := l.DecryptData(req.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user