|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "mtp2_if/config"
|
|
|
"mtp2_if/db"
|
|
|
"mtp2_if/logger"
|
|
|
"mtp2_if/models"
|
|
|
@@ -21,34 +22,53 @@ type BankCard4Rsp struct {
|
|
|
Description string `json:"description"` // 业务结果描述。
|
|
|
}
|
|
|
|
|
|
-func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err error) {
|
|
|
+func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp) {
|
|
|
+ var err error
|
|
|
+
|
|
|
+ var authinfo []byte
|
|
|
+ if req.Type == 1 {
|
|
|
+ if authinfo, err = json.Marshal(req.Person); err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if authinfo, err = json.Marshal(req.Company); err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if utils.TencenCloudFaceIdClient == nil {
|
|
|
err = fmt.Errorf("腾讯云FaceId客户端未初始化")
|
|
|
logger.GetLogger().Errorf("CreateConsoleLoginUrl failed: %s", err.Error())
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 校验入参
|
|
|
if req.Type == 1 && req.Person == nil {
|
|
|
err = errors.New("缺少参数")
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if req.Type == 2 && req.Company == nil {
|
|
|
err = errors.New("缺少参数")
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 从交易库中获取类型为实名认证的电子签信息
|
|
|
- var authinfo []byte
|
|
|
var record models.Useresignrecord
|
|
|
var has bool
|
|
|
has, err = db.GetEngine().Where("TEMPLATETYPE = 5 AND USERID = ?", req.UserId).Get(&record)
|
|
|
if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if !has {
|
|
|
- err = errors.New("无对应实名认证记录信息")
|
|
|
- logger.GetLogger().Error("无对应实名认证记录信息, userId:", req.UserId)
|
|
|
+ // err = errors.New("无对应实名认证记录信息")
|
|
|
+ // logger.GetLogger().Error("无对应实名认证记录信息, userId:", req.UserId)
|
|
|
+ rsp = BankCard4Rsp{Code: "0", Description: "认证通过"}
|
|
|
return
|
|
|
}
|
|
|
if record.RECORDSTATUS == 3 {
|
|
|
@@ -56,6 +76,7 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
if record.AUTHINFO == "" {
|
|
|
err = errors.New("实名认证记录信息异常")
|
|
|
logger.GetLogger().Error("实名认证记录信息异常, userId:", req.UserId)
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if req.Type == 1 {
|
|
|
@@ -63,6 +84,7 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
var oriAuthInfo reqModels.PersonBankCard4
|
|
|
err = json.Unmarshal([]byte(record.AUTHINFO), &oriAuthInfo)
|
|
|
if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if oriAuthInfo.RealName == req.Person.RealName &&
|
|
|
@@ -70,14 +92,12 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
oriAuthInfo.BankCard == req.Person.BankCard &&
|
|
|
oriAuthInfo.Mobile == req.Person.Mobile {
|
|
|
// 信息一致,则直接返回已实名
|
|
|
- err = errors.New("账户已实名")
|
|
|
- logger.GetLogger().Error("账户已实名, userId:", req.UserId)
|
|
|
+ // err = errors.New("账户已实名")
|
|
|
+ // logger.GetLogger().Error("账户已实名, userId:", req.UserId)
|
|
|
+ rsp = BankCard4Rsp{Code: "0", Description: "认证通过"}
|
|
|
return
|
|
|
} else {
|
|
|
// 信息不一致,重新进行实名认证
|
|
|
- if authinfo, err = json.Marshal(req.Person); err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
SET RECORDSTATUS = 1,
|
|
|
@@ -87,6 +107,7 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
`, string(authinfo), req.UserId)
|
|
|
_, err = db.GetEngine().Exec(sql)
|
|
|
if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
@@ -95,6 +116,7 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
var oriAuthInfo reqModels.CompanyBankCard4
|
|
|
err = json.Unmarshal([]byte(record.AUTHINFO), &oriAuthInfo)
|
|
|
if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if oriAuthInfo.CompanyName == req.Company.CompanyName &&
|
|
|
@@ -104,14 +126,12 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
oriAuthInfo.BankCard == req.Company.BankCard &&
|
|
|
oriAuthInfo.Mobile == req.Company.Mobile {
|
|
|
// 信息一致,则直接返回已实名
|
|
|
- err = errors.New("账户已实名")
|
|
|
- logger.GetLogger().Error("账户已实名, userId:", req.UserId)
|
|
|
+ // err = errors.New("账户已实名")
|
|
|
+ // logger.GetLogger().Error("账户已实名, userId:", req.UserId)
|
|
|
+ rsp = BankCard4Rsp{Code: "0", Description: "认证通过"}
|
|
|
return
|
|
|
} else {
|
|
|
// 信息不一致,重新进行实名认证
|
|
|
- if authinfo, err = json.Marshal(req.Company); err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
SET RECORDSTATUS = 1,
|
|
|
@@ -121,6 +141,7 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
`, string(authinfo), req.UserId)
|
|
|
_, err = db.GetEngine().Exec(sql)
|
|
|
if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
@@ -133,14 +154,35 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
SET RECORDSTATUS = 3,
|
|
|
- UPDATETIME = SYSDATE
|
|
|
+ UPDATETIME = SYSDATE,
|
|
|
+ AUTHINFO = '%v'
|
|
|
WHERE USERID = %v AND TEMPLATETYPE = 5
|
|
|
- `, req.UserId)
|
|
|
+ `, string(authinfo), req.UserId)
|
|
|
_, err = db.GetEngine().Exec(sql)
|
|
|
if err == nil {
|
|
|
rsp = BankCard4Rsp{Code: "0", Description: "认证通过"}
|
|
|
}
|
|
|
} else {
|
|
|
+ // 判断当日是否已经超过配额
|
|
|
+ type FeeCount struct {
|
|
|
+ FeeCount int `xorm:"FEECOUNT"`
|
|
|
+ }
|
|
|
+ feeCount := FeeCount{}
|
|
|
+ sql := fmt.Sprintf(`select count(t.logid) FEECOUNT
|
|
|
+ from USERESIGNRECORDLOG t
|
|
|
+ where t.userid = %d and trunc(t.createtime) = trunc(sysdate) and t.feeflag = 1`, req.UserId)
|
|
|
+ has, err = db.GetEngine().SQL(sql).Get(&feeCount)
|
|
|
+ if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if has {
|
|
|
+ if feeCount.FeeCount >= config.SerCfg.TencentCloudCfg.DailyQuota {
|
|
|
+ rsp = BankCard4Rsp{Code: "3", Description: "次数超过每日配额"}
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 个人
|
|
|
// 调用腾讯云接口
|
|
|
// request := &v20180301.BankCard4EVerificationRequest{
|
|
|
@@ -159,11 +201,13 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
response, err = utils.TencenCloudFaceIdClient.BankCard4EVerification(request)
|
|
|
if err != nil {
|
|
|
logger.GetLogger().Error("调用腾讯云实名认证接口发生错误:", err.Error())
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
if response.Response.Result == nil {
|
|
|
err = errors.New("返回结果为空")
|
|
|
logger.GetLogger().Error("调用腾讯云实名认证接口发生错误:", err.Error())
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -197,7 +241,6 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
case "0", "-1", "-6", "-7", "-8", "-9", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17":
|
|
|
feeFlag = 1
|
|
|
}
|
|
|
- var sql string
|
|
|
sql, _ = builder.Insert(
|
|
|
builder.Eq{
|
|
|
"LOGID": "SEQ_USERESIGNRECORDLOG.nextval",
|
|
|
@@ -215,23 +258,23 @@ func BankCard4EVerification(req reqModels.BankCard4Req) (rsp BankCard4Rsp, err e
|
|
|
sql = strings.ReplaceAll(sql, "'SYSDATE'", "SYSDATE")
|
|
|
db.GetEngine().Exec(sql)
|
|
|
|
|
|
- if *response.Response.Result != "0" {
|
|
|
- err = errors.New("返回结果失败,错误码(" + *response.Response.Result + "),返回信息(" + response.ToJsonString() + ")")
|
|
|
- logger.GetLogger().Error("调用腾讯云实名认证接口返回结果不成功:", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 返回结果结果,更新记录状态
|
|
|
- sql = fmt.Sprintf(`
|
|
|
+ if *response.Response.Result == "0" {
|
|
|
+ // 返回结果结果,更新记录状态
|
|
|
+ sql = fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
SET RECORDSTATUS = 3,
|
|
|
- UPDATETIME = SYSDATE
|
|
|
+ UPDATETIME = SYSDATE,
|
|
|
+ AUTHINFO = '%v'
|
|
|
WHERE USERID = %v AND TEMPLATETYPE = 5
|
|
|
- `, req.UserId)
|
|
|
- _, err = db.GetEngine().Exec(sql)
|
|
|
- if err == nil {
|
|
|
- rsp = BankCard4Rsp{Code: "0", Description: "认证通过"}
|
|
|
+ `, string(authinfo), req.UserId)
|
|
|
+ _, err = db.GetEngine().Exec(sql)
|
|
|
+ if err != nil {
|
|
|
+ rsp = BankCard4Rsp{Code: "1", Description: err.Error()}
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ rsp = BankCard4Rsp{Code: *response.Response.Result, Description: *response.Response.Description}
|
|
|
}
|
|
|
|
|
|
return
|