feat(all): v1.0

This commit is contained in:
2024-11-21 12:14:34 +08:00
parent d09e7a08cf
commit 6ce1a303f1
61 changed files with 3106 additions and 1046 deletions

View File

@@ -1,6 +0,0 @@
root = "."
[build]
cmd = "go build -o ./tmp/main ./app/user/cmd/api/user.go" # 指定 user-api 的入口文件
bin = "./tmp/main"
include_ext = ["go", "tmpl", "html"]
exclude_dir = ["tmp", "deploy", "data"]

View File

@@ -10,7 +10,7 @@ info (
type (
sendSmsReq {
Mobile string `json:"mobile" validate:"required,mobile"`
ActionType string `json:"actionType" validate:"required,oneof=loginCode registerCode QueryCode"`
ActionType string `json:"actionType" validate:"required,oneof=login register query"`
}
)

View File

@@ -0,0 +1,14 @@
syntax = "v1"
info (
title: "单体服务中心"
desc: "单体服务中心"
author: "Liangzai"
email: "2440983361@qq.com"
version: "v1"
)
import "user.api"
import "query.api"
import "pay.api"
import "product.api"

View File

@@ -0,0 +1,28 @@
syntax = "v1"
info (
title: "支付服务"
desc: "支付服务"
author: "Liangzai"
email: "2440983361@qq.com"
version: "v1"
)
@server (
prefix: api/v1
group: pay
)
service main {
// 微信支付回调
@handler WechatPayCallback
post /pay/wechat/callback
// 支付宝支付回调
@handler AlipayCallback
post /pay/alipay/callback
// 微信退款回调
@handler WechatPayRefundCallback
post /pay/wechat/refund_callback
}

View File

@@ -0,0 +1,25 @@
syntax = "v1"
info (
title: "产品服务"
desc: "产品服务"
author: "Liangzai"
email: "2440983361@qq.com"
version: "v1"
)
import (
"product/product.api"
)
@server (
prefix: api/v1/product
group: product
jwt: JwtAuth
)
service main {
@handler GetProductByID
get /:id (GetProductByIDRequest) returns (ProductResponse)
@handler GetProductByEn
get /en/:product_en (GetProductByEnRequest) returns (ProductResponse)
}

View File

@@ -0,0 +1,36 @@
syntax = "v1"
info (
title: "产品查询服务"
desc: "产品查询服务"
author: "Liangzai"
email: "2440983361@qq.com"
)
type Product {
ProductName string `json:"product_name"`
ProductEn string `json:"product_en"`
Description string `json:"description"`
Notes string `json:"notes,optional"`
SellPrice float64 `json:"sell_price"`
Features []Feature `json:"features"` // 关联功能列表
}
type Feature {
ID int64 `json:"id"` // 功能ID
ApiID string `json:"api_id"` // API标识
Name string `json:"name"` // 功能描述
}
type GetProductByIDRequest {
Id int64 `path:"id"`
}
type GetProductByEnRequest {
ProductEn string `path:"product_en"`
}
type ProductResponse {
Product
}

View File

@@ -0,0 +1,84 @@
syntax = "v1"
info (
title: "产品查询服务"
desc: "产品查询服务"
author: "Liangzai"
email: "2440983361@qq.com"
version: "v1"
)
import (
"query/query.api"
)
//============================> query v1 <============================
@server (
prefix: api/v1
group: query
jwt: JwtAuth
)
service main {
@doc "query marriage"
@handler marriage
post /query/marriage (QueryReq) returns (QueryResp)
// 家政服务查询
@doc "query home service"
@handler homeService
post /query/homeService (QueryReq) returns (QueryResp)
// 风险评估查询
@doc "query risk assessment"
@handler riskAssessment
post /query/riskAssessment (QueryReq) returns (QueryResp)
// 企业信息查询
@doc "query company info"
@handler companyInfo
post /query/companyInfo (QueryReq) returns (QueryResp)
// 租赁信息查询
@doc "query rental info"
@handler rentalInfo
post /query/rentalInfo (QueryReq) returns (QueryResp)
// 贷前背景调查
@doc "query pre-loan background check"
@handler preLoanBackgroundCheck
post /query/preLoanBackgroundCheck (QueryReq) returns (QueryResp)
// 一般背景调查
@doc "query general background check"
@handler backgroundCheck
post /query/backgroundCheck (QueryReq) returns (QueryResp)
}
@server (
prefix: api/v1
group: query
jwt: JwtAuth
)
service main {
@doc "查询示例"
@handler queryExample
get /query/example (QueryExampleReq) returns (QueryExampleResp)
@doc "查询列表"
@handler queryList
get /query/list (QueryListReq) returns (QueryListResp)
@doc "查询详情 按订单号 付款查询时"
@handler queryDetailByOrderId
get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (QueryDetailByOrderIdResp)
@doc "查询详情"
@handler queryDetail
get /query/:id (QueryDetailReq) returns (QueryDetailResp)
@doc "重试查询"
@handler queryRetry
post /query/retry/:id (QueryRetryReq) returns (QueryRetryResp)
}

View File

@@ -0,0 +1,75 @@
syntax = "v1"
info (
title: "产品查询服务"
desc: "产品查询服务"
author: "Liangzai"
email: "2440983361@qq.com"
)
type (
QueryReq {
Data string `json:"data" validate:"required"`
}
QueryResp {
prepayID string `json:"prepay_id"`
OrderID int64 `json:"order_id"`
}
)
type Query {
Id int64 `json:"id"` // 主键ID
OrderId int64 `json:"order_id"` // 订单ID
UserId int64 `json:"user_id"` // 用户ID
ProductId int64 `json:"product_id"` // 产品ID
QueryData []map[string]interface{} `json:"query_data"`
CreateTime string `json:"create_time"` // 创建时间
UpdateTime string `json:"update_time"` // 更新时间
QueryState string `json:"query_state"` // 查询状态
}
type (
QueryListReq {
Page int64 `form:"page"` // 页码
PageSize int64 `form:"page_size"` // 每页数据量
}
QueryListResp {
Total int64 `json:"total"` // 总记录数
List []Query `json:"list"` // 查询列表
}
)
type (
QueryExampleReq {
feature string `form:"feature"`
}
QueryExampleResp {
Query
}
)
type (
QueryDetailReq {
Id int64 `path:"id"`
}
QueryDetailResp {
Query
}
)
type (
QueryDetailByOrderIdReq {
OrderId int64 `path:"order_id"`
}
QueryDetailByOrderIdResp {
Query
}
)
type (
QueryRetryReq {
Id int64 `path:"id"`
}
QueryRetryResp {}
)

View File

@@ -16,10 +16,10 @@ import (
//============================> user v1 <============================
//no need login
@server (
prefix: user/v1
prefix: api/v1
group: user
)
service user {
service main {
@doc "register"
@handler register
post /user/register (RegisterReq) returns (RegisterResp)
@@ -35,14 +35,14 @@ service user {
//need login
@server (
prefix: user/v1
prefix: api/v1
group: user
jwt: JwtAuth
)
service user {
service main {
@doc "get user info"
@handler detail
post /user/detail (UserInfoReq) returns (UserInfoResp)
get /user/detail returns (UserInfoResp)
@doc "wechat mini auth"
@handler wxMiniAuth
@@ -51,10 +51,10 @@ service user {
//============================> auth v1 <============================
@server (
prefix: auth/v1
prefix: api/v1
group: auth
)
service user {
service main {
@doc "get mobile verify code"
@handler sendSms
post /auth/sendSms (sendSmsReq)

View File

@@ -64,7 +64,6 @@ type (
)
type (
UserInfoReq {}
UserInfoResp {
UserInfo User `json:"userInfo"`
}

View File

@@ -1,19 +0,0 @@
Name: user
Host: 0.0.0.0
Port: 8888
DataSource: "qnc:5vg67b3UNHu8@tcp(127.0.0.1:20001)/qnc?charset=utf8mb4&parseTime=True&loc=Local"
CacheRedis:
- Host: "127.0.0.1:20002"
Pass: "3m3WsgyCKWqz" # Redis 密码,如果未设置则留空
Type: "node" # 单节点模式
JwtAuth:
AccessSecret: "WUvoIwL-FK0qnlxhvxR9tV6SjfOpeJMpKmY2QvT99lA"
AccessExpire: 86400 # JWT过期时间
RefreshAfter: 43200 # 更新时间
VerifyCode:
AccessKeyID: "LTAI5tKGB3TVJbMHSoZN3yr9"
AccessKeySecret: "OCQ30GWp4yENMjmfOAaagksE18bp65"
EndpointURL: "dysmsapi.aliyuncs.com"
SignName: "天远数据"
TemplateCode: "SMS_474525324"
ValidTime: 300

View File

@@ -11,6 +11,11 @@ type Config struct {
CacheRedis cache.CacheConf
JwtAuth JwtAuth // JWT 鉴权相关配置
VerifyCode VerifyCode
Encrypt Encrypt
Alipay AlipayConfig
Wxpay WxpayConfig
Ali AliConfig
WestConfig WestConfig
}
// JwtAuth 用于 JWT 鉴权配置
@@ -27,3 +32,32 @@ type VerifyCode struct {
TemplateCode string
ValidTime int
}
type Encrypt struct {
SecretKey string
}
type AlipayConfig struct {
AppID string
PrivateKey string
AlipayPublicKey string
IsProduction bool
NotifyUrl string
}
type WxpayConfig struct {
AppID string
MchID string
MchCertificateSerialNumber string
MchApiv3Key string
MchPrivateKeyPath string
NotifyUrl string
RefundNotifyUrl string
}
type AliConfig struct {
Code string
}
type WestConfig struct {
Url string
Key string
SecretId string
SecretSecondId string
}

View File

@@ -5,6 +5,9 @@ import (
"net/http"
auth "qnc-server/app/user/cmd/api/internal/handler/auth"
pay "qnc-server/app/user/cmd/api/internal/handler/pay"
product "qnc-server/app/user/cmd/api/internal/handler/product"
query "qnc-server/app/user/cmd/api/internal/handler/query"
user "qnc-server/app/user/cmd/api/internal/handler/user"
"qnc-server/app/user/cmd/api/internal/svc"
@@ -21,7 +24,131 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: auth.SendSmsHandler(serverCtx),
},
},
rest.WithPrefix("/auth/v1"),
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/pay/alipay/callback",
Handler: pay.AlipayCallbackHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/pay/wechat/callback",
Handler: pay.WechatPayCallbackHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/pay/wechat/refund_callback",
Handler: pay.WechatPayRefundCallbackHandler(serverCtx),
},
},
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/:id",
Handler: product.GetProductByIDHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/en/:product_en",
Handler: product.GetProductByEnHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/api/v1/product"),
)
server.AddRoutes(
[]rest.Route{
{
// query general background check
Method: http.MethodPost,
Path: "/query/backgroundCheck",
Handler: query.BackgroundCheckHandler(serverCtx),
},
{
// query company info
Method: http.MethodPost,
Path: "/query/companyInfo",
Handler: query.CompanyInfoHandler(serverCtx),
},
{
// query home service
Method: http.MethodPost,
Path: "/query/homeService",
Handler: query.HomeServiceHandler(serverCtx),
},
{
// query marriage
Method: http.MethodPost,
Path: "/query/marriage",
Handler: query.MarriageHandler(serverCtx),
},
{
// query pre-loan background check
Method: http.MethodPost,
Path: "/query/preLoanBackgroundCheck",
Handler: query.PreLoanBackgroundCheckHandler(serverCtx),
},
{
// query rental info
Method: http.MethodPost,
Path: "/query/rentalInfo",
Handler: query.RentalInfoHandler(serverCtx),
},
{
// query risk assessment
Method: http.MethodPost,
Path: "/query/riskAssessment",
Handler: query.RiskAssessmentHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// 查询详情
Method: http.MethodGet,
Path: "/query/:id",
Handler: query.QueryDetailHandler(serverCtx),
},
{
// 查询示例
Method: http.MethodGet,
Path: "/query/example",
Handler: query.QueryExampleHandler(serverCtx),
},
{
// 查询列表
Method: http.MethodGet,
Path: "/query/list",
Handler: query.QueryListHandler(serverCtx),
},
{
// 查询详情 按订单号 付款查询时
Method: http.MethodGet,
Path: "/query/orderId/:order_id",
Handler: query.QueryDetailByOrderIdHandler(serverCtx),
},
{
// 重试查询
Method: http.MethodPost,
Path: "/query/retry/:id",
Handler: query.QueryRetryHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
@@ -45,14 +172,14 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: user.RegisterHandler(serverCtx),
},
},
rest.WithPrefix("/user/v1"),
rest.WithPrefix("/api/v1"),
)
server.AddRoutes(
[]rest.Route{
{
// get user info
Method: http.MethodPost,
Method: http.MethodGet,
Path: "/user/detail",
Handler: user.DetailHandler(serverCtx),
},
@@ -64,6 +191,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/user/v1"),
rest.WithPrefix("/api/v1"),
)
}

View File

@@ -34,8 +34,8 @@ func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLo
func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
// 检查手机号是否在一分钟内已发送过验证码
redisKey := fmt.Sprintf("%s:%s", req.ActionType, req.Mobile)
exists, err := l.svcCtx.Redis.Exists(redisKey)
limitCodeKey := fmt.Sprintf("limit:%s:%s", req.ActionType, req.Mobile)
exists, err := l.svcCtx.Redis.Exists(limitCodeKey)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "短信发送, 读取redis缓存失败: %s", req.Mobile)
}
@@ -55,14 +55,14 @@ func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
if *smsResp.Body.Code != "OK" {
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "短信发送, 阿里客户端响应失败: %s", *smsResp.Body.Message)
}
codeKey := fmt.Sprintf("%s:%s", req.ActionType, req.Mobile)
// 将验证码保存到 Redis设置过期时间
err = l.svcCtx.Redis.Setex(req.Mobile, code, l.svcCtx.Config.VerifyCode.ValidTime) // 验证码有效期5分钟
err = l.svcCtx.Redis.Setex(codeKey, code, l.svcCtx.Config.VerifyCode.ValidTime) // 验证码有效期5分钟
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "短信发送, 验证码设置过期时间失败: %+v", err)
}
// 在 Redis 中设置 1 分钟的标记,限制重复请求
err = l.svcCtx.Redis.Setex(redisKey, code, 60) // 标记 1 分钟内不能重复请求
err = l.svcCtx.Redis.Setex(limitCodeKey, code, 60) // 标记 1 分钟内不能重复请求
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "短信发送, 验证码设置限制重复请求失败: %+v", err)
}

View File

@@ -26,7 +26,7 @@ func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogi
}
}
func (l *DetailLogic) Detail(req *types.UserInfoReq) (resp *types.UserInfoResp, err error) {
func (l *DetailLogic) Detail() (resp *types.UserInfoResp, err error) {
userID, err := ctxdata.GetUidFromCtx(l.ctx)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, %+v", err)

View File

@@ -12,6 +12,7 @@ import (
jwtx "qnc-server/common/jwt"
"qnc-server/common/tool"
"qnc-server/common/xerr"
"qnc-server/pkg/lzkit/lzUtils"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -32,7 +33,7 @@ func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Register
func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterResp, err error) {
// 检查手机号是否在一分钟内已发送过验证码
redisKey := fmt.Sprintf("%s:%s", "registerCode", req.Mobile)
redisKey := fmt.Sprintf("%s:%s", "register", req.Mobile)
cacheCode, err := l.svcCtx.Redis.Get(redisKey)
if err != nil {
if errors.Is(err, redis.Nil) {
@@ -58,7 +59,7 @@ func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterRe
user.Nickname = req.Mobile
}
if len(req.Password) > 0 {
user.Password = tool.Md5ByString(req.Password)
user.Password = lzUtils.StringToNullString(tool.Md5ByString(req.Password))
}
insertResult, userInsertErr := l.svcCtx.UserModel.Insert(ctx, session, user)
if userInsertErr != nil {

View File

@@ -0,0 +1,179 @@
package queue
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/hibiken/asynq"
"github.com/zeromicro/go-zero/core/logx"
"qnc-server/app/user/cmd/api/internal/svc"
"qnc-server/app/user/cmd/api/internal/types"
"qnc-server/app/user/model"
"qnc-server/pkg/lzkit/crypto"
"qnc-server/pkg/lzkit/lzUtils"
)
type PaySuccessNotifyUserHandler struct {
svcCtx *svc.ServiceContext
}
func NewPaySuccessNotifyUserHandler(svcCtx *svc.ServiceContext) *PaySuccessNotifyUserHandler {
return &PaySuccessNotifyUserHandler{
svcCtx: svcCtx,
}
}
var payload struct {
OrderID int64 `json:"order_id"`
}
func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
// 从任务的负载中解码数据
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
return fmt.Errorf("解析任务负载失败: %w", err)
}
order, err := l.svcCtx.OrderModel.FindOne(ctx, payload.OrderID)
if err != nil {
return fmt.Errorf("无效的订单ID: %d, %v", payload.OrderID, err)
}
if order.Status != "paid" {
err = fmt.Errorf("无效的订单: %d", payload.OrderID)
logx.Errorf("处理任务失败,原因: %v", err)
return asynq.SkipRetry
}
product, err := l.svcCtx.ProductModel.FindOne(ctx, order.ProductId)
if err != nil {
return fmt.Errorf("找不到相关产品: orderID: %d, productID: %d", payload.OrderID, order.ProductId)
}
query, findQueryErr := l.svcCtx.QueryModel.FindOneByOrderId(ctx, order.Id)
if findQueryErr != nil {
findQueryErr = fmt.Errorf("获取任务请求参数失败: %v", findQueryErr)
logx.Errorf("处理任务失败,原因: %v", findQueryErr)
return asynq.SkipRetry
}
if query.QueryState != "pending" {
err = fmt.Errorf("查询已处理: %d", query.Id)
logx.Errorf("处理任务失败,原因: %v", err)
return asynq.SkipRetry
}
secretKey := l.svcCtx.Config.Encrypt.SecretKey
key, decodeErr := hex.DecodeString(secretKey)
if decodeErr != nil {
err = fmt.Errorf("获取AES密钥失败: %v", decodeErr)
return l.handleError(ctx, err, order, query)
}
decryptData, aesdecryptErr := crypto.AesDecrypt(query.QueryParams, key)
if aesdecryptErr != nil {
aesdecryptErr = fmt.Errorf("加密响应信息失败: %v", aesdecryptErr)
return l.handleError(ctx, aesdecryptErr, order, query)
}
requests, exists := types.WestDexParams[product.ProductEn]
if !exists {
err = fmt.Errorf("未找到有效的参数配置: productEn: %s", product.ProductEn)
return l.handleError(ctx, err, order, query)
}
// 根据产品类型选择结构体类型
var requestData interface{}
switch product.ProductEn {
case "marriage":
requestData = &types.MarriageReq{}
case "homeservice":
requestData = &types.HomeServiceReq{}
case "riskassessment":
requestData = &types.RiskAssessmentReq{}
case "companyinfo":
requestData = &types.CompanyInfoReq{}
case "rentalinfo":
requestData = &types.RentalInfoReq{}
case "preloanbackgroundcheck":
requestData = &types.PreLoanBackgroundCheckReq{}
case "backgroundcheck":
requestData = &types.BackgroundCheckReq{}
default:
err = fmt.Errorf("未支持的产品类型: productEn: %s", product.ProductEn)
return l.handleError(ctx, err, order, query)
}
unmarshalErr := json.Unmarshal(decryptData, &requestData)
if unmarshalErr != nil {
unmarshalErr = fmt.Errorf("解析参数失败: %v", unmarshalErr)
return l.handleError(ctx, unmarshalErr, order, query)
}
combinedResponse, err := l.svcCtx.WestDexService.ProcessRequests(requestData, requests)
if err != nil {
return l.handleError(ctx, err, order, query)
}
// 加密返回响应
encryptData, aesEncryptErr := crypto.AesEncrypt(combinedResponse, key)
if aesEncryptErr != nil {
err = fmt.Errorf("加密响应信息失败: %v", aesEncryptErr)
return l.handleError(ctx, aesEncryptErr, order, query)
}
query.QueryData = lzUtils.StringToNullString(encryptData)
updateErr := l.svcCtx.QueryModel.UpdateWithVersion(ctx, nil, query)
if updateErr != nil {
err = fmt.Errorf("保存响应数据失败: %v", updateErr)
return l.handleError(ctx, updateErr, order, query)
}
query.QueryState = "success"
updateQueryErr := l.svcCtx.QueryModel.UpdateWithVersion(ctx, nil, query)
if updateQueryErr != nil {
updateQueryErr = fmt.Errorf("修改查询状态失败: %v", updateQueryErr)
return l.handleError(ctx, updateQueryErr, order, query)
}
return nil
}
// 定义一个中间件函数
func (l *PaySuccessNotifyUserHandler) handleError(ctx context.Context, err error, order *model.Order, query *model.Query) error {
logx.Errorf("处理任务失败,原因: %v", err)
if order.Status == "paid" && query.QueryState == "pending" {
// 更新查询状态为失败
query.QueryState = "failed"
updateQueryErr := l.svcCtx.QueryModel.UpdateWithVersion(ctx, nil, query)
if updateQueryErr != nil {
logx.Errorf("更新查询状态失败订单ID: %d, 错误: %v", order.Id, updateQueryErr)
return asynq.SkipRetry
}
// 退款
if order.PaymentPlatform == "wechat" {
refundErr := l.svcCtx.WechatPayService.WeChatRefund(ctx, order.OrderNo, order.Amount, order.Amount)
if refundErr != nil {
logx.Error(refundErr)
return asynq.SkipRetry
}
} else {
refund, refundErr := l.svcCtx.AlipayService.AliRefund(ctx, order.OrderNo, order.Amount)
if refundErr != nil {
logx.Error(refundErr)
return asynq.SkipRetry
}
if refund.IsSuccess() {
logx.Errorf("支付宝退款成功, orderID: %d", order.Id)
// 更新订单状态为退款
order.Status = "refunded"
updateOrderErr := l.svcCtx.OrderModel.UpdateWithVersion(ctx, nil, order)
if updateOrderErr != nil {
logx.Errorf("更新订单状态失败订单ID: %d, 错误: %v", order.Id, updateOrderErr)
return fmt.Errorf("更新订单状态失败: %v", updateOrderErr)
}
return asynq.SkipRetry
} else {
logx.Errorf("支付宝退款失败:%v", refundErr)
return asynq.SkipRetry
}
// 直接成功
}
}
return asynq.SkipRetry
}

View File

@@ -0,0 +1,28 @@
package queue
import (
"context"
"github.com/hibiken/asynq"
"qnc-server/app/user/cmd/api/internal/svc"
"qnc-server/app/user/cmd/api/internal/types"
)
type CronJob struct {
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
return &CronJob{
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CronJob) Register() *asynq.ServeMux {
mux := asynq.NewServeMux()
mux.Handle(types.MsgPaySuccessQuery, NewPaySuccessNotifyUserHandler(l.svcCtx))
return mux
}

View File

@@ -0,0 +1,137 @@
package service
import (
"context"
"fmt"
"github.com/smartwalle/alipay/v3"
mathrand "math/rand"
"net/http"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/pkg/lzkit/lzUtils"
"strconv"
"time"
)
type AliPayService struct {
config config.AlipayConfig
AlipayClient *alipay.Client
}
// NewAliPayService 是一个构造函数,用于初始化 AliPayService
func NewAliPayService(c config.Config) *AliPayService {
client, err := alipay.New(c.Alipay.AppID, c.Alipay.PrivateKey, c.Alipay.IsProduction)
if err != nil {
panic(fmt.Sprintf("创建支付宝客户端失败: %v", err))
}
// 加载支付宝公钥
err = client.LoadAliPayPublicKey(c.Alipay.AlipayPublicKey)
if err != nil {
panic(fmt.Sprintf("加载支付宝公钥失败: %v", err))
}
return &AliPayService{
config: c.Alipay,
AlipayClient: client,
}
}
func (a *AliPayService) CreateAlipayAppOrder(amount float64, subject string, outTradeNo string) (string, error) {
client := a.AlipayClient
totalAmount := lzUtils.ToAlipayAmount(amount)
// 构造移动支付请求
p := alipay.TradeAppPay{
Trade: alipay.Trade{
Subject: subject,
OutTradeNo: outTradeNo,
TotalAmount: totalAmount,
ProductCode: "QUICK_MSECURITY_PAY", // 移动端支付专用代码
NotifyURL: a.config.NotifyUrl, // 异步回调通知地址
},
}
// 获取APP支付字符串这里会签名
payStr, err := client.TradeAppPay(p)
if err != nil {
return "", fmt.Errorf("创建支付宝订单失败: %v", err)
}
return payStr, nil
}
// AliRefund 发起支付宝退款
func (a *AliPayService) AliRefund(ctx context.Context, outTradeNo string, refundAmount float64) (*alipay.TradeRefundRsp, error) {
refund := alipay.TradeRefund{
OutTradeNo: outTradeNo,
RefundAmount: lzUtils.ToAlipayAmount(refundAmount),
OutRequestNo: fmt.Sprintf("%s-refund", outTradeNo),
}
// 发起退款请求
refundResp, err := a.AlipayClient.TradeRefund(ctx, refund)
if err != nil {
return nil, fmt.Errorf("支付宝退款请求错误:%v", err)
}
return refundResp, nil
}
// HandleAliPaymentNotification 支付宝支付回调
func (a *AliPayService) HandleAliPaymentNotification(r *http.Request) (*alipay.Notification, error) {
// 解析表单
err := r.ParseForm()
if err != nil {
return nil, fmt.Errorf("解析请求表单失败:%v", err)
}
// 解析并验证通知DecodeNotification 会自动验证签名
notification, err := a.AlipayClient.DecodeNotification(r.Form)
if err != nil {
return nil, fmt.Errorf("验证签名失败: %v", err)
}
return notification, nil
}
func (a *AliPayService) QueryOrderStatus(ctx context.Context, outTradeNo string) (*alipay.TradeQueryRsp, error) {
queryRequest := alipay.TradeQuery{
OutTradeNo: outTradeNo,
}
// 发起查询请求
resp, err := a.AlipayClient.TradeQuery(ctx, queryRequest)
if err != nil {
return nil, fmt.Errorf("查询支付宝订单失败: %v", err)
}
// 返回交易状态
if resp.IsSuccess() {
return resp, nil
}
return nil, fmt.Errorf("查询支付宝订单失败: %v", resp.SubMsg)
}
// GenerateOutTradeNo 生成唯一订单号的函数
func (a *AliPayService) GenerateOutTradeNo() string {
length := 16
// 获取当前时间戳
timestamp := time.Now().UnixNano()
// 转换为字符串
timeStr := strconv.FormatInt(timestamp, 10)
// 生成随机数
mathrand.Seed(time.Now().UnixNano())
randomPart := strconv.Itoa(mathrand.Intn(1000000))
// 组合时间戳和随机数
combined := timeStr + randomPart
// 如果长度超出指定值,则截断;如果不够,则填充随机字符
if len(combined) >= length {
return combined[:length]
}
// 如果长度不够填充0
for len(combined) < length {
combined += strconv.Itoa(mathrand.Intn(10)) // 填充随机数
}
return combined
}

View File

@@ -0,0 +1,59 @@
// asynq_service.go
package service
import (
"encoding/json"
"github.com/hibiken/asynq"
"github.com/zeromicro/go-zero/core/logx"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/app/user/cmd/api/internal/types"
)
type AsynqService struct {
client *asynq.Client
config config.Config
}
// NewAsynqService 创建并初始化 Asynq 客户端
func NewAsynqService(c config.Config) *AsynqService {
client := asynq.NewClient(asynq.RedisClientOpt{
Addr: c.CacheRedis[0].Host,
Password: c.CacheRedis[0].Pass,
})
return &AsynqService{client: client, config: c}
}
// Close 关闭 Asynq 客户端
func (s *AsynqService) Close() error {
return s.client.Close()
}
func (s *AsynqService) SendQueryTask(orderID int64) error {
// 准备任务的 payload
payload := types.MsgPaySuccessQueryPayload{
OrderID: orderID,
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
logx.Errorf("发送异步任务失败 (无法编码 payload): %v, 订单号: %d", err, orderID)
return err // 直接返回错误,避免继续执行
}
options := []asynq.Option{
asynq.MaxRetry(5), // 设置最大重试次数
}
// 创建任务
task := asynq.NewTask(types.MsgPaySuccessQuery, payloadBytes, options...)
// 将任务加入队列并获取任务信息
info, err := s.client.Enqueue(task)
if err != nil {
logx.Errorf("发送异步任务失败 (加入队列失败): %+v, 订单号: %d", err, orderID)
return err
}
// 记录成功日志,带上任务 ID 和队列信息
logx.Infof("发送异步任务成功任务ID: %s, 队列: %s, 订单号: %d", info.ID, info.Queue, orderID)
return nil
}

View File

@@ -0,0 +1,116 @@
package service
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"qnc-server/app/user/cmd/api/internal/config"
"strings"
)
type VerificationService struct {
c config.Config
}
func NewVerificationService(c config.Config) *VerificationService {
return &VerificationService{
c: c,
}
}
type TwoFactorVerificationRequest struct {
Name string
IDCard string
}
type TwoFactorVerificationResp struct {
Msg string `json:"msg"`
Success bool `json:"success"`
Code int `json:"code"`
Data *TwoFactorVerificationData `json:"data"` //
}
type TwoFactorVerificationData struct {
Birthday string `json:"birthday"`
Result int `json:"result"`
Address string `json:"address"`
OrderNo string `json:"orderNo"`
Sex string `json:"sex"`
Desc string `json:"desc"`
}
// VerificationResult 定义校验结果结构体
type VerificationResult struct {
Passed bool
Err error
}
// ValidationError 定义校验错误类型
type ValidationError struct {
Message string
}
func (e *ValidationError) Error() string {
return e.Message
}
func (r *VerificationService) TwoFactorVerification(request TwoFactorVerificationRequest) (*VerificationResult, error) {
appCode := r.c.Ali.Code
requestUrl := "https://kzidcardv1.market.alicloudapi.com/api-mall/api/id_card/check"
// 构造查询参数
data := url.Values{}
data.Add("name", request.Name)
data.Add("idcard", request.IDCard)
req, err := http.NewRequest(http.MethodPost, requestUrl, strings.NewReader(data.Encode()))
if err != nil {
return nil, fmt.Errorf("创建请求失败: %+v", err)
}
req.Header.Set("Authorization", "APPCODE "+appCode)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("请求失败: %+v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("请求失败, 状态码: %d", resp.StatusCode)
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("响应体读取失败:%v", err)
}
var twoFactorVerificationResp TwoFactorVerificationResp
err = json.Unmarshal(respBody, &twoFactorVerificationResp)
if err != nil {
return nil, fmt.Errorf("二要素解析错误: %v", err)
}
if !twoFactorVerificationResp.Success {
return &VerificationResult{
Passed: false,
Err: &ValidationError{Message: "请输入有效的身份证号码"},
}, nil
}
if twoFactorVerificationResp.Code != 200 {
return &VerificationResult{
Passed: false,
Err: &ValidationError{Message: twoFactorVerificationResp.Msg},
}, nil
}
if twoFactorVerificationResp.Data.Result == 1 {
return &VerificationResult{
Passed: false,
Err: &ValidationError{Message: "姓名与身份证不一致"},
}, nil
}
return &VerificationResult{Passed: true, Err: nil}, nil
}

View File

@@ -0,0 +1,188 @@
package service
import (
"context"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
"github.com/wechatpay-apiv3/wechatpay-go/core/downloader"
"github.com/wechatpay-apiv3/wechatpay-go/core/notify"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/app"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
"github.com/zeromicro/go-zero/core/logx"
"net/http"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/pkg/lzkit/lzUtils"
"strconv"
"time"
)
const (
TradeStateSuccess = "SUCCESS" // 支付成功
TradeStateRefund = "REFUND" // 转入退款
TradeStateNotPay = "NOTPAY" // 未支付
TradeStateClosed = "CLOSED" // 已关闭
TradeStateRevoked = "REVOKED" // 已撤销(付款码支付)
TradeStateUserPaying = "USERPAYING" // 用户支付中(付款码支付)
TradeStatePayError = "PAYERROR" // 支付失败(其他原因,如银行返回失败)
)
type WechatPayService struct {
config config.WxpayConfig
wechatClient *core.Client
notifyHandler *notify.Handler
}
// NewWechatPayService 初始化微信支付服务
func NewWechatPayService(c config.Config) *WechatPayService {
// 从配置中加载商户信息
mchID := c.Wxpay.MchID
mchCertificateSerialNumber := c.Wxpay.MchCertificateSerialNumber
mchAPIv3Key := c.Wxpay.MchApiv3Key
// 从文件中加载商户私钥
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(c.Wxpay.MchPrivateKeyPath)
if err != nil {
logx.Errorf("加载商户私钥失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
}
// 使用商户私钥和其他参数初始化微信支付客户端
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(context.Background(), opts...)
if err != nil {
logx.Errorf("创建微信支付客户端失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
}
// 在初始化时获取证书访问器并创建 notifyHandler
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
notifyHandler, err := notify.NewRSANotifyHandler(mchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certificateVisitor))
if err != nil {
logx.Errorf("获取证书访问器失败: %v", err)
panic(fmt.Sprintf("初始化失败,服务停止: %v", err)) // 记录错误并停止程序
}
return &WechatPayService{
config: c.Wxpay,
wechatClient: client,
notifyHandler: notifyHandler,
}
}
// CreateWechatAppOrder 创建微信APP支付订单
func (w *WechatPayService) CreateWechatAppOrder(ctx context.Context, amount float64, description string, outTradeNo string) (string, error) {
totalAmount := lzUtils.ToWechatAmount(amount)
// 构建支付请求参数
payRequest := app.PrepayRequest{
Appid: core.String(w.config.AppID),
Mchid: core.String(w.config.MchID),
Description: core.String(description),
OutTradeNo: core.String(outTradeNo),
NotifyUrl: core.String(w.config.NotifyUrl),
Amount: &app.Amount{
Total: core.Int64(totalAmount),
},
}
// 初始化 AppApiService
svc := app.AppApiService{Client: w.wechatClient}
// 发起预支付请求
resp, result, err := svc.Prepay(ctx, payRequest)
if err != nil {
return "", fmt.Errorf("微信支付订单创建失败: %v, 状态码: %d", err, result.Response.StatusCode)
}
// 返回预支付交易会话标识
return *resp.PrepayId, nil
}
// HandleWechatPayNotification 处理微信支付回调
func (w *WechatPayService) HandleWechatPayNotification(ctx context.Context, req *http.Request) (*payments.Transaction, error) {
transaction := new(payments.Transaction)
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, transaction)
if err != nil {
return nil, fmt.Errorf("微信支付通知处理失败: %v", err)
}
// 返回交易信息
return transaction, nil
}
// HandleRefundNotification 处理微信退款回调
func (w *WechatPayService) HandleRefundNotification(ctx context.Context, req *http.Request) (*refunddomestic.Refund, error) {
refund := new(refunddomestic.Refund)
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, refund)
if err != nil {
return nil, fmt.Errorf("微信退款回调通知处理失败: %v", err)
}
return refund, nil
}
// QueryOrderStatus 主动查询订单状态
func (w *WechatPayService) QueryOrderStatus(ctx context.Context, transactionID string) (*payments.Transaction, error) {
svc := jsapi.JsapiApiService{Client: w.wechatClient}
// 调用 QueryOrderById 方法查询订单状态
resp, result, err := svc.QueryOrderById(ctx, jsapi.QueryOrderByIdRequest{
TransactionId: core.String(transactionID),
Mchid: core.String(w.config.MchID),
})
if err != nil {
return nil, fmt.Errorf("订单查询失败: %v, 状态码: %d", err, result.Response.StatusCode)
}
return resp, nil
}
// WeChatRefund 申请微信退款
func (w *WechatPayService) WeChatRefund(ctx context.Context, outTradeNo string, refundAmount float64, totalAmount float64) error {
// 生成唯一的退款单号
outRefundNo := fmt.Sprintf("%s-refund", outTradeNo)
// 初始化退款服务
svc := refunddomestic.RefundsApiService{Client: w.wechatClient}
// 创建退款请求
resp, result, err := svc.Create(ctx, refunddomestic.CreateRequest{
OutTradeNo: core.String(outTradeNo),
OutRefundNo: core.String(outRefundNo),
NotifyUrl: core.String(w.config.RefundNotifyUrl),
Amount: &refunddomestic.AmountReq{
Currency: core.String("CNY"),
Refund: core.Int64(lzUtils.ToWechatAmount(refundAmount)),
Total: core.Int64(lzUtils.ToWechatAmount(totalAmount)),
},
})
if err != nil {
return fmt.Errorf("微信订单申请退款错误: %v", err)
}
// 打印退款结果
logx.Infof("退款申请成功,状态码=%d退款单号=%s微信退款单号=%s", result.Response.StatusCode, *resp.OutRefundNo, *resp.RefundId)
return nil
}
// GenerateOutTradeNo 生成唯一订单号
func (w *WechatPayService) GenerateOutTradeNo() string {
length := 16
timestamp := time.Now().UnixNano()
timeStr := strconv.FormatInt(timestamp, 10)
randomPart := strconv.Itoa(int(timestamp % 1e6))
combined := timeStr + randomPart
if len(combined) >= length {
return combined[:length]
}
for len(combined) < length {
combined += strconv.Itoa(int(timestamp % 10))
}
return combined
}

View File

@@ -0,0 +1,707 @@
package service
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
"github.com/zeromicro/go-zero/core/logx"
"io"
"net/http"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/app/user/cmd/api/internal/types"
"qnc-server/pkg/lzkit/crypto"
"reflect"
"strconv"
"sync"
"sync/atomic"
"time"
)
type WestResp struct {
Message string `json:"message"`
Code string `json:"code"`
Data string `json:"data"`
ID string `json:"id"`
ErrorCode *int `json:"error_code"`
Reason string `json:"reason"`
}
type G05HZ01WestResp struct {
Message string `json:"message"`
Code string `json:"code"`
Data json.RawMessage `json:"data"`
ID string `json:"id"`
ErrorCode *int `json:"error_code"`
Reason string `json:"reason"`
}
type WestDexService struct {
config config.WestConfig
}
type APIResponseData struct {
ApiID string `json:"apiID"`
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
Success bool `json:"success"`
Timestamp string `json:"timestamp"`
Error string `json:"error,omitempty"`
}
// NewWestDexService 是一个构造函数,用于初始化 WestDexService
func NewWestDexService(c config.Config) *WestDexService {
return &WestDexService{
config: c.WestConfig,
}
}
// CallAPI 调用西部数据的 API
func (w *WestDexService) CallAPI(code string, reqData map[string]interface{}) (resp []byte, err error) {
// 生成当前的13位时间戳
timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
// 构造请求URL
reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, w.config.SecretId, code, timestamp)
jsonData, marshalErr := json.Marshal(reqData)
if marshalErr != nil {
return nil, marshalErr
}
// 创建HTTP POST请求
req, newRequestErr := http.NewRequest("POST", reqUrl, bytes.NewBuffer(jsonData))
if newRequestErr != nil {
return nil, newRequestErr
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
httpResp, clientDoErr := client.Do(req)
if clientDoErr != nil {
return nil, clientDoErr
}
defer func(Body io.ReadCloser) {
closeErr := Body.Close()
if closeErr != nil {
}
}(httpResp.Body)
// 检查请求是否成功
if httpResp.StatusCode == 200 {
// 读取响应体
bodyBytes, ReadErr := io.ReadAll(httpResp.Body)
if ReadErr != nil {
return nil, ReadErr
}
// 手动调用 json.Unmarshal 触发自定义的 UnmarshalJSON 方法
var westDexResp WestResp
UnmarshalErr := json.Unmarshal(bodyBytes, &westDexResp)
if UnmarshalErr != nil {
return nil, UnmarshalErr
}
logx.Infof("西部数据请求响应, code: %s, response: %v", code, westDexResp)
if westDexResp.Code != "00000" {
if westDexResp.Data == "" {
return nil, errors.New(westDexResp.Message)
}
decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.config.Key)
if DecryptErr != nil {
return nil, DecryptErr
}
return decryptedData, errors.New(westDexResp.Message)
}
if westDexResp.Data == "" {
return nil, errors.New(westDexResp.Message)
}
// 解密响应数据
decryptedData, DecryptErr := crypto.WestDexDecrypt(westDexResp.Data, w.config.Key)
if DecryptErr != nil {
return nil, DecryptErr
}
// 输出解密后的数据
return decryptedData, nil
}
return nil, fmt.Errorf("西部请求失败Code: %d", httpResp.StatusCode)
}
// CallAPI 调用西部数据的 API
func (w *WestDexService) G05HZ01CallAPI(code string, reqData map[string]interface{}) (resp []byte, err error) {
// 生成当前的13位时间戳
timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
// 构造请求URL
reqUrl := fmt.Sprintf("%s/%s/%s?timestamp=%s", w.config.Url, w.config.SecretSecondId, code, timestamp)
jsonData, marshalErr := json.Marshal(reqData)
if marshalErr != nil {
return nil, marshalErr
}
// 创建HTTP POST请求
req, newRequestErr := http.NewRequest("POST", reqUrl, bytes.NewBuffer(jsonData))
if newRequestErr != nil {
return nil, newRequestErr
}
// 设置请求头
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
httpResp, clientDoErr := client.Do(req)
if clientDoErr != nil {
return nil, clientDoErr
}
defer func(Body io.ReadCloser) {
closeErr := Body.Close()
if closeErr != nil {
}
}(httpResp.Body)
// 检查请求是否成功
if httpResp.StatusCode == 200 {
// 读取响应体
bodyBytes, ReadErr := io.ReadAll(httpResp.Body)
if ReadErr != nil {
return nil, ReadErr
}
// 手动调用 json.Unmarshal 触发自定义的 UnmarshalJSON 方法
var westDexResp G05HZ01WestResp
UnmarshalErr := json.Unmarshal(bodyBytes, &westDexResp)
if UnmarshalErr != nil {
return nil, UnmarshalErr
}
logx.Infof("西部数据请求响应, code: %s, response: %v", code, westDexResp)
if westDexResp.Code != "0000" {
if westDexResp.Data == nil {
return nil, errors.New(westDexResp.Message)
}
return westDexResp.Data, errors.New(westDexResp.Message)
}
if westDexResp.Data == nil {
return nil, errors.New(westDexResp.Message)
}
return westDexResp.Data, nil
}
return nil, fmt.Errorf("西部请求失败Code: %d", httpResp.StatusCode)
}
// EncryptStructFields 加密字段的函数,处理不同类型,并跳过空值字段
func (w *WestDexService) EncryptStructFields(inputStruct interface{}) (map[string]interface{}, error) {
encryptedFields := make(map[string]interface{})
// 使用反射获取结构体的类型和值
v := reflect.ValueOf(inputStruct)
// 检查并解引用指针类型
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
if v.Kind() != reflect.Struct {
return nil, errors.New("传入的interfact不是struct")
}
// 遍历结构体字段
for i := 0; i < v.NumField(); i++ {
field := v.Type().Field(i)
fieldValue := v.Field(i)
// 检查字段的 encrypt 标签是否为 "false"
encryptTag := field.Tag.Get("encrypt")
if encryptTag == "false" {
encryptedFields[field.Name] = fieldValue.Interface()
continue
}
// 如果字段为空值,跳过
if fieldValue.IsZero() {
continue
}
// 将字段的值转换为字符串进行加密
strValue := fmt.Sprintf("%v", fieldValue.Interface())
// 执行加密操作
encryptedValue, err := crypto.WestDexEncrypt(strValue, w.config.Key)
if err != nil {
return nil, err
}
// 将加密后的值存入结果映射
encryptedFields[field.Name] = encryptedValue
}
return encryptedFields, nil
}
// MapStructToAPIRequest 字段映射
func (w *WestDexService) MapStructToAPIRequest(encryptedFields map[string]interface{}, fieldMapping map[string]string, wrapField string) map[string]interface{} {
apiRequest := make(map[string]interface{})
// 遍历字段映射表
for structField, apiField := range fieldMapping {
// 如果加密后的字段存在,才添加到请求
if structField == "InquiredAuth" {
apiRequest[apiField] = GetDateRange()
} else if structField == "TimeRange" {
apiRequest[apiField] = "5"
} else if value, exists := encryptedFields[structField]; exists {
apiRequest[apiField] = value
}
}
// 如果 wrapField 不为空,将 apiRequest 包裹到该字段下
if wrapField != "" {
return map[string]interface{}{
wrapField: apiRequest,
}
}
return apiRequest
}
// ProcessRequests 批量处理
func (w *WestDexService) ProcessRequests(data interface{}, requests []types.WestDexServiceRequestParams) ([]byte, error) {
var (
wg sync.WaitGroup
resultsCh = make(chan APIResponseData, len(requests))
errorsCh = make(chan error, len(requests))
ctx, cancel = context.WithCancel(context.Background())
errorCount int32
errorLimit = 4
)
defer cancel()
for i, req := range requests {
wg.Add(1)
go func(i int, req types.WestDexServiceRequestParams) {
defer wg.Done()
select {
case <-ctx.Done():
return
default:
}
// 请求参数预处理
apiRequest, preprocessErr := w.PreprocessRequestParams(req.ApiID, data)
if preprocessErr != nil {
errorsCh <- fmt.Errorf("请求预处理失败: %v", preprocessErr)
atomic.AddInt32(&errorCount, 1)
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
cancel()
}
return
}
var resp []byte
var callApiErr error
if req.ApiID == "G05HZ01" {
resp, callApiErr = w.G05HZ01CallAPI(req.ApiID, apiRequest)
} else {
resp, callApiErr = w.CallAPI(req.ApiID, apiRequest)
}
timestamp := time.Now().Format("2006-01-02 15:04:05")
result := APIResponseData{
ApiID: req.ApiID,
Success: false,
Timestamp: timestamp,
}
if callApiErr != nil {
errorsCh <- fmt.Errorf("西部请求, 请求失败: %+v", callApiErr)
atomic.AddInt32(&errorCount, 1)
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
cancel()
}
result.Error = callApiErr.Error()
result.Data = resp
resultsCh <- result
return
}
processedResp, processErr := processResponse(resp, req.ApiID)
if processErr != nil {
errorsCh <- fmt.Errorf("处理响应失败: %v", processErr)
atomic.AddInt32(&errorCount, 1)
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
cancel()
}
result.Error = processErr.Error()
} else {
result.Data = processedResp
result.Success = true
}
resultsCh <- result
}(i, req)
}
go func() {
wg.Wait()
close(resultsCh)
close(errorsCh)
}()
// 收集所有结果并合并
var responseData []APIResponseData
for result := range resultsCh {
responseData = append(responseData, result)
}
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
var allErrors []error
for err := range errorsCh {
allErrors = append(allErrors, err)
}
return nil, fmt.Errorf("请求失败次数超过 %d 次: %v", errorLimit, allErrors)
}
combinedResponse, err := json.Marshal(responseData)
if err != nil {
return nil, fmt.Errorf("响应数据转 JSON 失败: %+v", err)
}
return combinedResponse, nil
}
// ------------------------------------请求处理器--------------------------
var requestProcessors = map[string]func(*WestDexService, interface{}) (map[string]interface{}, error){
"G09SC02": (*WestDexService).ProcessG09SC02Request,
"G27BJ05": (*WestDexService).ProcessG27BJ05Request,
"G26BJ05": (*WestDexService).ProcessG26BJ05Request,
"G34BJ03": (*WestDexService).ProcessG34BJ03Request,
"G35SC01": (*WestDexService).ProcessG35SC01Request,
"G28BJ05": (*WestDexService).ProcessG28BJ05Request,
"G05HZ01": (*WestDexService).ProcessG05HZ01Request,
}
// PreprocessRequestParams 调用指定的请求处理函数
func (w *WestDexService) PreprocessRequestParams(apiID string, params interface{}) (map[string]interface{}, error) {
if processor, exists := requestProcessors[apiID]; exists {
return processor(w, params) // 调用 WestDexService 方法
}
var request map[string]interface{}
return request, nil
}
// / 将处理函数作为 WestDexService 的方法
func (w *WestDexService) ProcessG09SC02Request(params interface{}) (map[string]interface{}, error) {
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G09SC02FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG27BJ05Request(params interface{}) (map[string]interface{}, error) {
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G27BJ05FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG26BJ05Request(params interface{}) (map[string]interface{}, error) {
// 特殊名单 G26BJ05
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G26BJ05FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG34BJ03Request(params interface{}) (map[string]interface{}, error) {
// 个人不良 G34BJ03
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G34BJ03FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG35SC01Request(params interface{}) (map[string]interface{}, error) {
// 个人涉诉 G35SC01
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G35SC01FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG28BJ05Request(params interface{}) (map[string]interface{}, error) {
// 借贷行为 G28BJ05
encryptedFields, err := w.EncryptStructFields(params)
if err != nil {
return nil, fmt.Errorf("西部请求, 生成请求数据失败: %+v", err)
}
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G28BJ05FieldMapping, "data")
return apiRequest, nil
}
func (w *WestDexService) ProcessG05HZ01Request(params interface{}) (map[string]interface{}, error) {
// 使用 reflect 获取 params 的值和类型
val := reflect.ValueOf(params)
if val.Kind() == reflect.Ptr {
val = val.Elem() // 如果是指针,获取指向的实际值
}
if val.Kind() != reflect.Struct {
return nil, fmt.Errorf("请求参数必须是结构体类型")
}
// 初始化一个 map 来存储加密后的字段
encryptedFields := make(map[string]interface{})
// 遍历结构体字段,将其转换为 map[string]interface{}
valType := val.Type()
for i := 0; i < val.NumField(); i++ {
field := val.Field(i)
fieldName := valType.Field(i).Name
// 如果字段名为 "IDCard",对其值进行加密
if fieldName == "IDCard" {
if field.Kind() != reflect.String {
return nil, fmt.Errorf("IDCard 字段不是字符串类型")
}
idCard := field.String()
encryptedIDCard := crypto.Md5Encrypt(idCard)
encryptedFields[fieldName] = encryptedIDCard
} else {
// 否则直接将字段值添加到 map 中
encryptedFields[fieldName] = field.Interface()
}
}
// 使用字段映射表生成最终的 API 请求
apiRequest := w.MapStructToAPIRequest(encryptedFields, types.G05HZ01FieldMapping, "")
return apiRequest, nil
}
// -----------------------------------------------------------------------------
// 响应处理器
var responseProcessors = map[string]func([]byte) ([]byte, error){
"G09SC02": processG09SC02Response, // 单人婚姻
"G27BJ05": processG27BJ05Response, // 借贷意向
"G28BJ05": processG28BJ05Response, // 借贷行为
"G26BJ05": processG26BJ05Response, // 特殊名单
"G05HZ01": processG05HZ01Response, // 股东人企关系
"G34BJ03": processG34BJ03Response, // 个人不良
"G35SC01": processG35SC01Response, // 个人涉诉
}
// processResponse 处理响应数据
func processResponse(resp []byte, apiID string) ([]byte, error) {
if processor, exists := responseProcessors[apiID]; exists {
return processor(resp)
}
return resp, nil
}
func processG09SC02Response(resp []byte) ([]byte, error) {
// 使用 GJSON 递归搜索 "maritalStatus" 字段
result := gjson.GetBytes(resp, "data.0.maritalStatus")
if result.Exists() {
// 如果字段存在,构造包含 "status" 的 JSON 响应
responseMap := map[string]string{"status": result.String()}
jsonResponse, err := json.Marshal(responseMap)
if err != nil {
return nil, err
}
return jsonResponse, nil
} else {
return nil, errors.New("查询为空")
}
}
func processG27BJ05Response(resp []byte) ([]byte, error) {
// 获取 code 字段
codeResult := gjson.GetBytes(resp, "code")
if !codeResult.Exists() {
return nil, fmt.Errorf("code 字段不存在")
}
if codeResult.String() != "00" {
return nil, fmt.Errorf("未匹配到相关结果")
}
// 获取 data 字段
dataResult := gjson.GetBytes(resp, "data")
if !dataResult.Exists() {
return nil, fmt.Errorf("data 字段不存在")
}
// 将 data 字段解析为 map
var dataMap map[string]interface{}
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
}
// 删除指定字段
delete(dataMap, "swift_number")
delete(dataMap, "DataStrategy")
// 重新编码为 JSON
modifiedData, err := json.Marshal(dataMap)
if err != nil {
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
}
return modifiedData, nil
}
func processG28BJ05Response(resp []byte) ([]byte, error) {
// 处理借贷行为的响应数据
// 获取 code 字段
codeResult := gjson.GetBytes(resp, "code")
if !codeResult.Exists() {
return nil, fmt.Errorf("code 字段不存在")
}
if codeResult.String() != "00" {
return nil, fmt.Errorf("未匹配到相关结果")
}
// 获取 data 字段
dataResult := gjson.GetBytes(resp, "data")
if !dataResult.Exists() {
return nil, fmt.Errorf("data 字段不存在")
}
// 将 data 字段解析为 map
var dataMap map[string]interface{}
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
}
// 删除指定字段
delete(dataMap, "swift_number")
delete(dataMap, "DataStrategy")
// 重新编码为 JSON
modifiedData, err := json.Marshal(dataMap)
if err != nil {
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
}
return modifiedData, nil
}
func processG26BJ05Response(resp []byte) ([]byte, error) {
// 处理特殊名单的响应数据
// 获取 code 字段
codeResult := gjson.GetBytes(resp, "code")
if !codeResult.Exists() {
return nil, fmt.Errorf("code 字段不存在")
}
if codeResult.String() != "00" {
return nil, fmt.Errorf("未匹配到相关结果")
}
// 获取 data 字段
dataResult := gjson.GetBytes(resp, "data")
if !dataResult.Exists() {
return nil, fmt.Errorf("data 字段不存在")
}
// 将 data 字段解析为 map
var dataMap map[string]interface{}
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
}
// 删除指定字段
delete(dataMap, "swift_number")
delete(dataMap, "DataStrategy")
// 重新编码为 JSON
modifiedData, err := json.Marshal(dataMap)
if err != nil {
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
}
return modifiedData, nil
}
func processG05HZ01Response(resp []byte) ([]byte, error) {
// 处理股东人企关系的响应数据
code := gjson.GetBytes(resp, "code")
if !code.Exists() {
return nil, fmt.Errorf("响应中缺少 code 字段")
}
// 判断 code 是否等于 "0000"
if code.String() == "0000" {
// 获取 data 字段的值
data := gjson.GetBytes(resp, "data")
if !data.Exists() {
return nil, fmt.Errorf("响应中缺少 data 字段")
}
// 返回 data 字段的内容
return []byte(data.Raw), nil
}
// code 不等于 "0000",返回错误
return nil, fmt.Errorf("响应code错误%s", code.String())
}
func processG34BJ03Response(resp []byte) ([]byte, error) {
// 处理个人不良的响应数据
dataResult := gjson.GetBytes(resp, "negative_info.data.risk_level")
if dataResult.Exists() {
// 如果字段存在,构造包含 "status" 的 JSON 响应
responseMap := map[string]string{"risk_level": dataResult.String()}
jsonResponse, err := json.Marshal(responseMap)
if err != nil {
return nil, err
}
return jsonResponse, nil
} else {
return nil, errors.New("查询为空")
}
}
func processG35SC01Response(resp []byte) ([]byte, error) {
// 第一步:提取外层的 data 字段
dataResult := gjson.GetBytes(resp, "data")
if !dataResult.Exists() {
return nil, fmt.Errorf("外层 data 字段不存在")
}
// 第二步:解析外层 data 的 JSON 字符串
var outerDataMap map[string]interface{}
if err := json.Unmarshal([]byte(dataResult.String()), &outerDataMap); err != nil {
return nil, fmt.Errorf("解析外层 data 字段失败: %v", err)
}
// 第三步:提取内层的 data 字段
innerData, ok := outerDataMap["data"].(string)
if !ok {
return nil, fmt.Errorf("内层 data 字段不存在或类型错误")
}
// 第四步:解析内层 data 的 JSON 字符串
var finalDataMap map[string]interface{}
if err := json.Unmarshal([]byte(innerData), &finalDataMap); err != nil {
return nil, fmt.Errorf("解析内层 data 字段失败: %v", err)
}
// 将最终的 JSON 对象编码为字节数组返回
finalDataBytes, err := json.Marshal(finalDataMap)
if err != nil {
return nil, fmt.Errorf("编码最终的 JSON 对象失败: %v", err)
}
return finalDataBytes, nil
}
// GetDateRange 返回今天到明天的日期范围,格式为 "yyyyMMdd-yyyyMMdd"
func GetDateRange() string {
today := time.Now().Format("20060102") // 获取今天的日期
tomorrow := time.Now().Add(24 * time.Hour).Format("20060102") // 获取明天的日期
return fmt.Sprintf("%s-%s", today, tomorrow) // 拼接日期范围并返回
}

View File

@@ -1,30 +1,70 @@
package svc
import (
"github.com/hibiken/asynq"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/app/user/cmd/api/internal/service"
"qnc-server/app/user/model"
)
type ServiceContext struct {
Config config.Config
Redis *redis.Redis
UserModel model.UserModel
UserAuthModel model.UserAuthModel
Config config.Config
Redis *redis.Redis
UserModel model.UserModel
UserAuthModel model.UserAuthModel
ProductModel model.ProductModel
FeatureModel model.FeatureModel
ProductFeatureModel model.ProductFeatureModel
OrderModel model.OrderModel
QueryModel model.QueryModel
AlipayService *service.AliPayService
WechatPayService *service.WechatPayService
WestDexService *service.WestDexService
AsynqServer *asynq.Server // 服务端
AsynqService *service.AsynqService // 客户端
VerificationService *service.VerificationService
}
func NewServiceContext(c config.Config) *ServiceContext {
db := sqlx.NewMysql(c.DataSource) // 创建数据库连接
db := sqlx.NewMysql(c.DataSource)
redisConf := redis.RedisConf{
Host: c.CacheRedis[0].Host,
Pass: c.CacheRedis[0].Pass,
Type: c.CacheRedis[0].Type, // Redis 节点类型,如 "node"
Type: c.CacheRedis[0].Type,
}
asynqServer := asynq.NewServer(
asynq.RedisClientOpt{Addr: c.CacheRedis[0].Host, Password: c.CacheRedis[0].Pass},
asynq.Config{
IsFailure: func(err error) bool {
logx.Errorf("异步任务失败: %+v \n", err)
return true
},
Concurrency: 10,
},
)
return &ServiceContext{
Config: c,
Redis: redis.MustNewRedis(redisConf),
UserModel: model.NewUserModel(db, c.CacheRedis),
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
Config: c,
Redis: redis.MustNewRedis(redisConf),
AlipayService: service.NewAliPayService(c),
WechatPayService: service.NewWechatPayService(c),
WestDexService: service.NewWestDexService(c),
VerificationService: service.NewVerificationService(c),
AsynqServer: asynqServer,
AsynqService: service.NewAsynqService(c),
UserModel: model.NewUserModel(db, c.CacheRedis),
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
ProductModel: model.NewProductModel(db, c.CacheRedis),
OrderModel: model.NewOrderModel(db, c.CacheRedis),
QueryModel: model.NewQueryModel(db, c.CacheRedis),
FeatureModel: model.NewFeatureModel(db, c.CacheRedis),
ProductFeatureModel: model.NewProductFeatureModel(db, c.CacheRedis),
}
}
func (s *ServiceContext) Close() {
if s.AsynqService != nil {
s.AsynqService.Close()
}
}

View File

@@ -0,0 +1,5 @@
package types
type MsgPaySuccessQueryPayload struct {
OrderID int64 `json:"order_id"`
}

View File

@@ -0,0 +1,61 @@
package types
type MarriageReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
type HomeServiceReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
// RiskAssessment 查询请求结构
type RiskAssessmentReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
// CompanyInfo 查询请求结构
type CompanyInfoReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
// RentalInfo 查询请求结构
type RentalInfoReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
// PreLoanBackgroundCheck 查询请求结构
type PreLoanBackgroundCheckReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}
// BackgroundCheck 查询请求结构
type BackgroundCheckReq struct {
Name string `json:"name" validate:"required,name"`
IDCard string `json:"id_card" validate:"required,idCard"`
Mobile string `json:"mobile" validate:"required,mobile"`
Code string `json:"code" validate:"required"`
PayMethod string `json:"pay_method" validate:"required,payMethod"`
}

View File

@@ -0,0 +1,47 @@
package types
// 特殊名单 G26BJ05
var G26BJ05FieldMapping = map[string]string{
"IDCard": "id",
"Name": "name",
"Mobile": "cell",
"TimeRange": "time_range",
}
// 个人不良
var G34BJ03FieldMapping = map[string]string{
"IDCard": "id_card",
"Name": "name",
}
// 个人涉诉 G35SC01
var G35SC01FieldMapping = map[string]string{
"Name": "name",
"IDCard": "idcard",
"InquiredAuth": "inquired_auth",
}
// 单人婚姻 G09SC02
var G09SC02FieldMapping = map[string]string{
"IDCard": "certNumMan",
"Name": "nameMan",
}
// 借贷意向 G27BJ05
var G27BJ05FieldMapping = map[string]string{
"IDCard": "id",
"Name": "name",
"Mobile": "cell",
}
// 借贷行为 G28BJ05
var G28BJ05FieldMapping = map[string]string{
"IDCard": "id",
"Name": "name",
"Mobile": "cell",
}
// 股东人企关系精准版 G05HZ01
var G05HZ01FieldMapping = map[string]string{
"IDCard": "pid",
}

View File

@@ -0,0 +1,73 @@
package types
type WestDexServiceRequestParams struct {
FieldMapping map[string]string
ApiID string
}
var WestDexParams = map[string][]WestDexServiceRequestParams{
"marriage": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
},
"backgroundcheck": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
"companyinfo": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
"homeservice": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
"preloanbackgroundcheck": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
"rentalinfo": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
"riskassessment": {
{FieldMapping: G09SC02FieldMapping, ApiID: "G09SC02"}, // 单人婚姻
{FieldMapping: G27BJ05FieldMapping, ApiID: "G27BJ05"}, // 借贷意向
{FieldMapping: G28BJ05FieldMapping, ApiID: "G28BJ05"}, // 借贷行为
{FieldMapping: G26BJ05FieldMapping, ApiID: "G26BJ05"}, // 特殊名单
{FieldMapping: G05HZ01FieldMapping, ApiID: "G05HZ01"}, // 股东人企关系
{FieldMapping: G34BJ03FieldMapping, ApiID: "G34BJ03"}, // 个人不良
{FieldMapping: G35SC01FieldMapping, ApiID: "G35SC01"}, // 个人涉诉
},
}

View File

@@ -0,0 +1,3 @@
package types
const MsgPaySuccessQuery = "msg:pay_success:query"

View File

@@ -1,6 +1,20 @@
// Code generated by goctl. DO NOT EDIT.
package types
type Feature struct {
ID int64 `json:"id"` // 功能ID
ApiID string `json:"api_id"` // API标识
Name string `json:"name"` // 功能描述
}
type GetProductByEnRequest struct {
ProductEn string `path:"product_en"`
}
type GetProductByIDRequest struct {
Id int64 `path:"id"`
}
type MobileCodeLoginReq struct {
Mobile string `json:"mobile"`
Code string `json:"code" validate:"required"`
@@ -23,6 +37,80 @@ type MobileLoginResp struct {
RefreshAfter int64 `json:"refreshAfter"`
}
type Product struct {
ProductName string `json:"product_name"`
ProductEn string `json:"product_en"`
Description string `json:"description"`
Notes string `json:"notes,optional"`
SellPrice float64 `json:"sell_price"`
Features []Feature `json:"features"` // 关联功能列表
}
type ProductResponse struct {
Product
}
type Query struct {
Id int64 `json:"id"` // 主键ID
OrderId int64 `json:"order_id"` // 订单ID
UserId int64 `json:"user_id"` // 用户ID
ProductId int64 `json:"product_id"` // 产品ID
QueryData []map[string]interface{} `json:"query_data"`
CreateTime string `json:"create_time"` // 创建时间
UpdateTime string `json:"update_time"` // 更新时间
QueryState string `json:"query_state"` // 查询状态
}
type QueryDetailByOrderIdReq struct {
OrderId int64 `path:"order_id"`
}
type QueryDetailByOrderIdResp struct {
Query
}
type QueryDetailReq struct {
Id int64 `path:"id"`
}
type QueryDetailResp struct {
Query
}
type QueryExampleReq struct {
Feature string `form:"feature"`
}
type QueryExampleResp struct {
Query
}
type QueryListReq struct {
Page int64 `form:"page"` // 页码
PageSize int64 `form:"page_size"` // 每页数据量
}
type QueryListResp struct {
Total int64 `json:"total"` // 总记录数
List []Query `json:"list"` // 查询列表
}
type QueryReq struct {
Data string `json:"data" validate:"required"`
}
type QueryResp struct {
PrepayID string `json:"prepay_id"`
OrderID int64 `json:"order_id"`
}
type QueryRetryReq struct {
Id int64 `path:"id"`
}
type QueryRetryResp struct {
}
type RegisterReq struct {
Mobile string `json:"mobile" validate:"required,mobile"`
Password string `json:"password" validate:"required,min=11,max=11,password"`
@@ -41,9 +129,6 @@ type User struct {
NickName string `json:"nickName"`
}
type UserInfoReq struct {
}
type UserInfoResp struct {
UserInfo User `json:"userInfo"`
}
@@ -62,5 +147,5 @@ type WXMiniAuthResp struct {
type SendSmsReq struct {
Mobile string `json:"mobile" validate:"required,mobile"`
ActionType string `json:"actionType" validate:"required,oneof=loginCode registerCode QueryCode"`
ActionType string `json:"actionType" validate:"required,oneof=login register query"`
}

View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCP6fWm1vXXybH
m3Ne6PjacGrN2+iMrzWZlzdHCZ31udDPqSUYaZ+78b441KZK/CJFQWeSJ/1h//A+
BGsQDKvE/fj2QzN1KkOuQ8WJXNGpixE5uu5bv/QTN/ukurGdA1aO2aFCANumlOmB
HkB/B2so57ii8iQQjwK2xM4r3oOU/IfcFGKL+9/QjLGFFp9PJXCDBCgrxxlZGaj1
3wowlfVOzlaX94gemQsCYVkuAFIYMAnFHs9cKNZQIU80somW/yy2Gy38N6n7NnbD
nvFSaq4GoDROqRgKbRZ5e706d/p7A3aS/2oRqq1jomUIugK8g++LmoHFTgfhfQkI
v1aG/nPzAgMBAAECggEAD2RN31J2J42xm/V0YdviBCUOQXugZK1peN8jkSxw6Myt
gBbuCo4sCw9vvD8VYjGyYXx6QXmLuV03YyKkfSQT5EsflBvlEu6jaEaUe3rwXhfX
6JQoWPrP00oHVZk5g7CFBlK2VW2N+hgonIOSJr6mvhoGZlr7gphiZasYjx9Vm9N3
Pbnfru5ttzplYNniwH3DF6ph8VmdbD1nnbWSKLXvHCsXQT2wBcnsIagIH3vyq6K1
pc5abWsQJrixOPebpI8jD5w0HxHAqVLx58H/OC2zW/roAw1WS2AkueJ1j7dQ7Z0C
mc9Xexz5gcAP0nMAQv+LP7iYqsa/niFhfcTFWfdxkQKBgQD5JkKNmInU2/IVYCwO
c483MCSv1+MnbRXlb7vut8T0IupHTU6hCge6C3q3HsjbKSBn8bRChtPUzvw9JFxK
QWKiQqQDPLDJ08AIKhfQD2JiLtoikkZN0bF6OTL+Soney1yGx51mlfHM194+PcCJ
jF7iWdMVbcBwHbgydNxxIS5cKQKBgQDHlvQ4lw6gvLILpGK494/vNYSJP/Jmd66V
3oSGYi84YRKTSwH4NlbBVVieb3Dv+pPugbsXEuFHBif7WsivbYgNTE9++8Yvt0gh
duB1G4yh7m/ylQeSuipgQU9tozrU/15cWwmcCRV50wWXBGoVEM0kf7mzEKSxmjYk
Qzko/zxSuwKBgQCY6Bc+SViFz3qSDdTcBaXma+CIHsmlH7ipd9px1kzEvEzl95cD
FGHLl1H34qfIgUQHJvrHPXHyEBoT+CW/2MMM7DM2XV/ubctT92ln4pkxwqlTQExv
Y/s1FLesAtj8Z/hgK0/5bprYab9WmZV5lTGCXzhB1XqeFE9AgCHuODv4iQKBgQC8
g2uwd5ytXQydymokYk9klJvWNrvw5GHV1BJAC0Smb6lnzZTSqCBRAxdsrb1yLK7E
u2vGY2K7/qiM1DZw23eBd+4t9gg+0VIjqXBfq+GsoNTDvtckUwnrWER5PY831ut9
N89fvYS3SAUjmlvIAdKBAtKWusWTqiAxJ/05J7oGOQKBgB5PSr5i0LlupIbKui9t
XtXnRqGPxxrZZUpTkyrGOAnlCz/zq2QiwFpBWo/NMHOp0KmxzJpQ8yEY2LWlRZ61
Oc9m0J/HtPw3Ohi1treBosEVG/0NOI9Tq1Obny23N51MVibdW6zEIyGUp/DbFS8h
5DljdOYX9IYIHHn3Ig4GeTGe
-----END PRIVATE KEY-----

View File

@@ -1,31 +0,0 @@
package main
import (
"flag"
"fmt"
"qnc-server/app/user/cmd/api/internal/config"
"qnc-server/app/user/cmd/api/internal/handler"
"qnc-server/app/user/cmd/api/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/user.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}