| 
									
										
										
										
											2024-10-02 00:57:17 +08:00
										 |  |  | package IVYZ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2024-10-12 21:35:35 +08:00
										 |  |  | 	"tianyuan-api/pkg/errs" | 
					
						
							| 
									
										
										
										
											2024-10-02 00:57:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"tianyuan-api/apps/api/internal/svc" | 
					
						
							|  |  |  | 	"tianyuan-api/apps/api/internal/types" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/zeromicro/go-zero/core/logx" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type IVYZ2125Logic struct { | 
					
						
							|  |  |  | 	logx.Logger | 
					
						
							|  |  |  | 	ctx    context.Context | 
					
						
							|  |  |  | 	svcCtx *svc.ServiceContext | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func NewIVYZ2125Logic(ctx context.Context, svcCtx *svc.ServiceContext) *IVYZ2125Logic { | 
					
						
							|  |  |  | 	return &IVYZ2125Logic{ | 
					
						
							|  |  |  | 		Logger: logx.WithContext(ctx), | 
					
						
							|  |  |  | 		ctx:    ctx, | 
					
						
							|  |  |  | 		svcCtx: svcCtx, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | // IVYZ2125 活体+人像核验组件 | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | func (l *IVYZ2125Logic) IVYZ2125(req *types.Request) (resp string, err *errs.AppError) { | 
					
						
							| 
									
										
										
										
											2024-10-02 00:57:17 +08:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//var status string | 
					
						
							|  |  |  | 	//var charges bool | 
					
						
							|  |  |  | 	//var remark = "" | 
					
						
							|  |  |  | 	//secretKey, ok := l.ctx.Value("secretKey").(string) | 
					
						
							|  |  |  | 	//if !ok { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	//transactionID, ok := l.ctx.Value("transactionID").(string) | 
					
						
							|  |  |  | 	//if !ok { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	//userId, userIdOk := l.ctx.Value("userId").(int64) | 
					
						
							|  |  |  | 	//if !userIdOk { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	//productCode, productCodeOk := l.ctx.Value("productCode").(string) | 
					
						
							|  |  |  | 	//if !productCodeOk || productCode == "" { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	//defer func() { | 
					
						
							|  |  |  | 	//	if err != nil { | 
					
						
							|  |  |  | 	//		status = "failed" | 
					
						
							|  |  |  | 	//		charges = false | 
					
						
							|  |  |  | 	//	} else { | 
					
						
							|  |  |  | 	//		status = "success" | 
					
						
							|  |  |  | 	//		charges = true | 
					
						
							|  |  |  | 	//	} | 
					
						
							|  |  |  | 	//	sendApiRequestMessageErr := l.svcCtx.ApiRequestMqsService.SendApiRequestMessage(l.ctx, transactionID, userId, productCode, status, charges, remark) | 
					
						
							|  |  |  | 	//	if sendApiRequestMessageErr != nil { | 
					
						
							|  |  |  | 	//		logx.Errorf("发送 API 请求消息失败: %v", err) | 
					
						
							|  |  |  | 	//	} | 
					
						
							|  |  |  | 	//}() | 
					
						
							|  |  |  | 	//// 1、解密 | 
					
						
							|  |  |  | 	//key, decodeErr := hex.DecodeString(secretKey) | 
					
						
							|  |  |  | 	//if decodeErr != nil { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	//decryptData, aesDecryptErr := crypto.AesDecrypt(req.Data, key) | 
					
						
							|  |  |  | 	//if aesDecryptErr != nil || len(decryptData) == 0 { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrParamDecryption | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	//// 2、校验 | 
					
						
							|  |  |  | 	//var data validator.FLXGDEC7Request | 
					
						
							|  |  |  | 	//if validatorErr := validator.ValidateAndParse(decryptData, &data); validatorErr != nil { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrParamValidation | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	//// 3、西部加密 | 
					
						
							|  |  |  | 	//westConfig := l.svcCtx.Config.WestConfig | 
					
						
							|  |  |  | 	//encryptedFields, encryptStructFieldsErr := common.EncryptStructFields(data, westConfig.Key) | 
					
						
							|  |  |  | 	//if encryptStructFieldsErr != nil { | 
					
						
							|  |  |  | 	//	logx.Errorf("西部加密错误:%v", encryptStructFieldsErr) | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	//// 4、发送请求到西部 | 
					
						
							|  |  |  | 	//logx.Infof("交易号:%s", transactionID) | 
					
						
							|  |  |  | 	//apiRequest := common.MapStructToAPIRequest(encryptedFields, westmodel.FLXGDEC7FieldMapping, "data") | 
					
						
							|  |  |  | 	// | 
					
						
							| 
									
										
										
										
											2024-10-24 18:05:13 +08:00
										 |  |  | 	//westResp, callAPIErr := l.svcCtx.WestDexService.CallAPI("G23BJ03", apiRequest, l.svcCtx.Config.WestConfig.SecretId) | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//if callAPIErr != nil { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	//	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	//} | 
					
						
							|  |  |  | 	// | 
					
						
							|  |  |  | 	//// 5、响应解析 | 
					
						
							|  |  |  | 	////var respData westmodel.G32BJ05Response | 
					
						
							|  |  |  | 	////unmarshalErr := json.Unmarshal(westResp, &respData) | 
					
						
							|  |  |  | 	////if unmarshalErr != nil { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	////	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	////} | 
					
						
							|  |  |  | 	//// | 
					
						
							|  |  |  | 	////if respData.Data.Code == "00" || respData.Data.Code == "100002" { | 
					
						
							|  |  |  | 	////	l.ctx = context.WithValue(l.ctx, "Charges", true) | 
					
						
							|  |  |  | 	////} else { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	////	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	////} | 
					
						
							|  |  |  | 	////encryptData, aesEncrypt := crypto.AesEncrypt(westResp, key) | 
					
						
							|  |  |  | 	////if aesEncrypt != nil { | 
					
						
							| 
									
										
										
										
											2024-10-13 22:17:25 +08:00
										 |  |  | 	////	return "", errs.ErrSystem | 
					
						
							| 
									
										
										
										
											2024-10-13 20:52:47 +08:00
										 |  |  | 	////} | 
					
						
							|  |  |  | 	//return &types.Response{ | 
					
						
							|  |  |  | 	//	Data: string(westResp), | 
					
						
							|  |  |  | 	//}, nil | 
					
						
							| 
									
										
										
										
											2024-10-02 00:57:17 +08:00
										 |  |  | } |