cc
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
request2 "qnc-server/model/request"
|
||||
"qnc-server/model/response"
|
||||
"qnc-server/service"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Feature struct {
|
||||
@@ -34,44 +33,48 @@ func (f *Feature) OcrName(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.Ok(c)
|
||||
return
|
||||
|
||||
// 调用 OCRService
|
||||
ocrResult, err := featureService.OCRService(request.Base64)
|
||||
if err != nil {
|
||||
log.Printf("【OCR校验】请求错误:%v", err)
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
// 尝试解析为错误响应
|
||||
var ocrError response.OcrErrorResponse
|
||||
json.Unmarshal([]byte(ocrResult), &ocrError)
|
||||
if ocrError.ErrorCode != 0 {
|
||||
// 如果解析成功,且存在 error_code,则返回错误信息
|
||||
response.FailWithMessage("检测签名错误,请重新签名", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 尝试解析为成功响应
|
||||
var ocrSuccess response.OcrSuccessResponse
|
||||
err = json.Unmarshal([]byte(ocrResult), &ocrSuccess)
|
||||
if err != nil {
|
||||
// 如果解析失败,则返回解析错误
|
||||
response.FailWithMessage("系统错误错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 判断 words_result_num 是否等于 1
|
||||
if ocrSuccess.WordsResultNum != 1 {
|
||||
response.FailWithMessage("检测签名错误,请重新签名", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 判断 OCR 结果的第一个 words 是否与 name 匹配
|
||||
if len(ocrSuccess.WordsResult) > 0 && strings.Contains(ocrSuccess.WordsResult[0].Words, request.Name) {
|
||||
response.Ok(c)
|
||||
} else {
|
||||
response.FailWithMessage("签名不匹配,请输入签入正确的姓名", c)
|
||||
return
|
||||
}
|
||||
//ocrResult, err := featureService.OCRService(request.Base64)
|
||||
//if err != nil {
|
||||
// log.Printf("【OCR校验】请求错误:%v", err)
|
||||
// response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
// return
|
||||
//}
|
||||
//log.Printf("OCR返回:%v", ocrResult)
|
||||
//// 尝试解析为错误响应
|
||||
//var ocrError response.OcrErrorResponse
|
||||
//json.Unmarshal([]byte(ocrResult), &ocrError)
|
||||
//if ocrError.ErrorCode != 0 {
|
||||
// // 如果解析成功,且存在 error_code,则返回错误信息
|
||||
// response.FailWithMessage("检测签名错误,请重新签名", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 尝试解析为成功响应
|
||||
//var ocrSuccess response.OcrSuccessResponse
|
||||
//err = json.Unmarshal([]byte(ocrResult), &ocrSuccess)
|
||||
//if err != nil {
|
||||
// // 如果解析失败,则返回解析错误
|
||||
// response.FailWithMessage("系统错误错误,请稍后再试", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 判断 words_result_num 是否等于 1
|
||||
//if ocrSuccess.WordsResultNum != 1 {
|
||||
// response.FailWithMessage("检测签名错误,请重新签名", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 判断 OCR 结果的第一个 words 是否与 name 匹配
|
||||
//if len(ocrSuccess.WordsResult) > 0 && strings.Contains(ocrSuccess.WordsResult[0].Words, request.Name) {
|
||||
// response.Ok(c)
|
||||
//} else {
|
||||
// response.FailWithMessage("签名不匹配,签名要和查询人的名字一致", c)
|
||||
// return
|
||||
//}
|
||||
}
|
||||
|
||||
func (f *Feature) VerifyElements(c *gin.Context) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"qnc-server/config"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"qnc-server/model/types"
|
||||
"qnc-server/service"
|
||||
"qnc-server/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LawsuitQuery struct {
|
||||
@@ -97,6 +99,7 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
// 二要素核验
|
||||
twoElementsParams := map[string]any{
|
||||
"name": reqBody.Name,
|
||||
@@ -128,12 +131,14 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
}
|
||||
|
||||
} else {
|
||||
response.FailWithMessage("暂不支持企业涉诉查询", c)
|
||||
return
|
||||
// 校验企业社会统一信用代码
|
||||
isCreditCode := utils.ValidateUnifiedSocialCreditCode(reqBody.CardNo)
|
||||
if isCreditCode == false {
|
||||
response.FailWithMessage("请输入企业社会统一信用代码", c)
|
||||
return
|
||||
}
|
||||
//isCreditCode := utils.ValidateUnifiedSocialCreditCode(reqBody.CardNo)
|
||||
//if isCreditCode == false {
|
||||
// response.FailWithMessage("请输入企业社会统一信用代码", c)
|
||||
// return
|
||||
//}
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
@@ -160,8 +165,11 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
//================================================西部=============================================
|
||||
var lawsuitReq map[string]interface{}
|
||||
var reqCode string
|
||||
|
||||
authDate := GenerateDateString()
|
||||
if *reqBody.Type == types.Individual {
|
||||
encodeName, err := utils.WestDexEncrypt(reqBody.Name, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
@@ -176,10 +184,11 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"name": encodeName,
|
||||
"id_card": encodeID,
|
||||
"name": encodeName,
|
||||
"idcard": encodeID,
|
||||
"inquired_auth": authDate,
|
||||
}
|
||||
reqCode = "G22BJ03"
|
||||
reqCode = "G35SC01"
|
||||
} else {
|
||||
encodeID, err := utils.WestDexEncrypt(reqBody.CardNo, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
@@ -187,10 +196,19 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"ent_name": encodeID,
|
||||
encodeName, err := utils.WestDexEncrypt(reqBody.Name, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
log.Printf("【司法涉诉】加密错误:%v", err)
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
reqCode = "Q03BJ03"
|
||||
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"org_name": encodeName,
|
||||
"uscc": encodeID,
|
||||
"inquired_auth": authDate,
|
||||
}
|
||||
reqCode = "Q23SC01"
|
||||
}
|
||||
|
||||
// 发起请求并处理响应
|
||||
@@ -200,35 +218,74 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var resp model.LawsuitResponse
|
||||
var resp model.LawsuitPersonResponse
|
||||
err = json.Unmarshal([]byte(plainText), &resp)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.Data.ErrCode != "200" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼响应错误:%s", resp.Data.ErrMsg), c)
|
||||
if resp.ResultCode != "200" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼响应错误:%s", resp.Message), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 根据类型判断是个人信息还是公司信息
|
||||
|
||||
var respData json.RawMessage
|
||||
|
||||
if *reqBody.Type == types.Individual {
|
||||
if resp.Data.Data.PersonInfo == nil || resp.Data.Data.PersonInfo.Code == "-1000" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.PersonInfo.Msg), c)
|
||||
return
|
||||
}
|
||||
respData = resp.Data.Data.PersonInfo.Data
|
||||
} else {
|
||||
if resp.Data.Data.CompanyInfo == nil || resp.Data.Data.CompanyInfo.Code == "-1000" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.CompanyInfo.Msg), c)
|
||||
return
|
||||
}
|
||||
respData = resp.Data.Data.CompanyInfo.Data
|
||||
var respData model.LawsuitPersonData
|
||||
err = json.Unmarshal([]byte(resp.Data), &respData)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
var respDataData interface{}
|
||||
err = json.Unmarshal([]byte(respData.Data), &respDataData)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
//if checkIfEmpty(respDataData) || respData.Msg == "没有找到" {
|
||||
// handleErrorAndRefund(order, userid, "司法诉讼查询为空", c)
|
||||
// return
|
||||
//}
|
||||
|
||||
//根据类型判断是个人信息还是公司信息
|
||||
|
||||
//var respData json.RawMessage
|
||||
//
|
||||
//if *reqBody.Type == types.Individual {
|
||||
// if resp.Data.Data.PersonInfo == nil || resp.Data.Data.PersonInfo.Code == "-1000" {
|
||||
// handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.PersonInfo.Msg), c)
|
||||
// return
|
||||
// }
|
||||
// respData = resp.Data.Data.PersonInfo.Data
|
||||
//} else {
|
||||
// if resp.Data.Data.CompanyInfo == nil || resp.Data.Data.CompanyInfo.Code == "-1000" {
|
||||
// handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.CompanyInfo.Msg), c)
|
||||
// return
|
||||
// }
|
||||
// respData = resp.Data.Data.CompanyInfo.Data
|
||||
//}
|
||||
//===========================================================================================================================
|
||||
//reqData := map[string]interface{}{
|
||||
// "cardNo": reqBody.CardNo,
|
||||
// "name": reqBody.Name,
|
||||
//}
|
||||
//plainText, err := carService.CarReqYuShan("JUD009", &reqData)
|
||||
//log.Println(string(plainText))
|
||||
//if err != nil {
|
||||
// log.Printf("YuShan request at %s error: %s", "JUD009", err.Error())
|
||||
// handleErrorAndRefund(order, userid, "接口系统错误,将自动退款", c)
|
||||
// return
|
||||
//}
|
||||
//analysis, err := lawsuitQueryService.LawsuitDataAnalysis(string(plainText))
|
||||
//if err != nil {
|
||||
// if errors.Is(err, utils.ErrNoRecord) {
|
||||
// handleErrorAndRefund(order, userid, "综合涉诉查询为空,将自动退款", c)
|
||||
// } else {
|
||||
// handleErrorAndRefund(order, userid, "综合涉诉解析错误,将自动退款", c)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
var query model.Query
|
||||
query.OrderID = order.ID
|
||||
@@ -236,7 +293,7 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
query.Userid = userid
|
||||
query.ProductID = order.ProductID
|
||||
db.DB.Create(&query)
|
||||
uniqueID := utils.SetCacheData(ctx, respData)
|
||||
uniqueID := utils.SetCacheData(ctx, []interface{}{respDataData})
|
||||
// 更新订单状态并返回成功响应
|
||||
orderService.OrderConsumed(order)
|
||||
response.OkWithData(gin.H{
|
||||
@@ -270,21 +327,6 @@ func (l *LawsuitQuery) GetRecord(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//userid := utils.GetUserID(c)
|
||||
//record, err := lawsuitQueryService.QueryLawsuitByOrder(req.ID, userid)
|
||||
//if err != nil {
|
||||
// log.Printf("【司法涉诉】获取司法涉诉记录错误:%v", err)
|
||||
// notifyService.SendNotification("系统错误,获取司法涉诉记录错误,请及时处理", "司法涉诉", userid, record.OrderID)
|
||||
// response.FailRefund(c)
|
||||
// return
|
||||
//}
|
||||
//var resp any
|
||||
//err = json.Unmarshal([]byte(record.Resp), &resp)
|
||||
//if err != nil {
|
||||
// log.Printf("【司法涉诉】获取司法涉诉解析错误:%v", err)
|
||||
// notifyService.SendNotification("系统错误,获取司法涉诉解析错误,请及时处理", "司法涉诉", userid, record.OrderID)
|
||||
// return
|
||||
//}
|
||||
data, err := utils.GetCacheData(ctx, req.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
@@ -295,5 +337,61 @@ func (l *LawsuitQuery) GetRecord(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if checkIfEmpty(data) {
|
||||
// 判断data是否是string类型并且等于"查询成功无结果"
|
||||
//if strData, ok := data.(string); ok && strData == "查询成功无结果" {
|
||||
|
||||
// 读取empty.json文件
|
||||
emptyData, readErr := ioutil.ReadFile("empty.json")
|
||||
if readErr != nil {
|
||||
log.Printf("系统错误: 无法读取empty.json:%v", readErr)
|
||||
response.FailWithMessage("系统错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将empty.json的内容反序列化为map或者结构体
|
||||
var jsonData []map[string]interface{}
|
||||
if jsonErr := json.Unmarshal(emptyData, &jsonData); jsonErr != nil {
|
||||
log.Printf("系统错误: 无法解析empty.json:%v", readErr)
|
||||
response.FailWithMessage("系统错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 返回反序列化后的JSON数据
|
||||
response.OkWithData(jsonData, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(data, c)
|
||||
}
|
||||
func GenerateDateString() string {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
// 格式化当前日期为YYYYMMDD
|
||||
today := now.Format("20060102")
|
||||
// 获取明天的日期
|
||||
tomorrow := now.AddDate(0, 0, 1).Format("20060102")
|
||||
// 拼接成所需格式
|
||||
return today + "-" + tomorrow
|
||||
}
|
||||
|
||||
// 判断函数
|
||||
func checkIfEmpty(data interface{}) bool {
|
||||
// 判断是否为 nil
|
||||
if data == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// 判断是否为空数组
|
||||
if arr, ok := data.([]interface{}); ok {
|
||||
return len(arr) == 0
|
||||
}
|
||||
|
||||
// 判断是否为空对象(空 map)
|
||||
if obj, ok := data.(map[string]interface{}); ok {
|
||||
return len(obj) == 0
|
||||
}
|
||||
|
||||
// 如果不是上述情况,表示不为空
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -81,10 +81,24 @@ func NotifyMiddleware() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if utils.IsInTimeRange(startTime, endTime) {
|
||||
response.FailNotify(c)
|
||||
c.Abort()
|
||||
return
|
||||
currentTime := time.Now()
|
||||
|
||||
// 检查是否跨午夜
|
||||
if endTime.Before(startTime) {
|
||||
// 跨午夜,检查是否在开始时间到午夜,或者午夜到结束时间的范围内
|
||||
if utils.IsInTimeRange(startTime, time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location())) ||
|
||||
utils.IsInTimeRange(time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location()), endTime) {
|
||||
response.FailNotify(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 不跨午夜,按普通情况处理
|
||||
if utils.IsInTimeRange(startTime, endTime) {
|
||||
response.FailNotify(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
c.Next()
|
||||
|
||||
88
api/pay.go
88
api/pay.go
@@ -16,6 +16,7 @@ import (
|
||||
wxutils "github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"qnc-server/config"
|
||||
"qnc-server/db"
|
||||
@@ -44,16 +45,17 @@ func InitPay(group *gin.RouterGroup) {
|
||||
payPublicGroup.GET("refund_details/:id", p.RefundDetailsHTML) // 内部退款订单详情页面
|
||||
payPublicGroup.POST("refund/:id", p.Refund) // 内部退款按钮
|
||||
payPublicGroup.POST("refund_callback/:platform", p.RefundCallback) // 微信退款回调
|
||||
payPublicGroup.POST("ali_callback", p.AlipayCallback) // 阿里退款回调
|
||||
payPublicGroup.POST("ali_callback", p.AlipayCallback) // 阿里回调
|
||||
payPublicGroup.POST("complaint_callback/:platform", p.WxPayComplaintCallback)
|
||||
}
|
||||
{
|
||||
payPrivateGroup := group.Group("pay")
|
||||
payPrivateGroup.Use(JWTAuth())
|
||||
payPrivateGroup.POST("prepay", p.Prepay) // 创建微信支付订单
|
||||
payPrivateGroup.GET("order_list", p.GetOrderList) // 获取订单列表
|
||||
payPrivateGroup.POST("ali_prepay", p.AliPrepay) // 创建支付宝支付订单
|
||||
payPrivateGroup.GET("get_query_cache", p.GetQueryCache) // 获取网页的查询缓存
|
||||
payPrivateGroup.POST("prepay", p.Prepay) // 创建微信支付订单
|
||||
payPrivateGroup.GET("order_list", p.GetOrderList) // 获取订单列表
|
||||
payPrivateGroup.GET("promotion_list", p.GetPromotionList) // 获取订单列表
|
||||
payPrivateGroup.POST("ali_prepay", p.AliPrepay) // 创建支付宝支付订单
|
||||
payPrivateGroup.GET("get_query_cache", p.GetQueryCache) // 获取网页的查询缓存
|
||||
}
|
||||
}
|
||||
func (p *Pay) GetOrderList(c *gin.Context) {
|
||||
@@ -81,6 +83,55 @@ func (p *Pay) GetOrderList(c *gin.Context) {
|
||||
}
|
||||
response.OkWithData(list, c)
|
||||
}
|
||||
func (p *Pay) GetPromotionList(c *gin.Context) {
|
||||
userId := utils.GetUserID(c)
|
||||
user, err := userService.GetUserByUserid(userId)
|
||||
if err != nil {
|
||||
log.Println("get user info error:", err)
|
||||
response.FailWithMessage("系统开小差啦, 请稍后再试~", c)
|
||||
return
|
||||
}
|
||||
if user.Promotion == "" {
|
||||
response.FailWithMessage("您不是代理推广人哦", c)
|
||||
return
|
||||
}
|
||||
// 从查询参数中获取分页参数
|
||||
pageSizeStr := c.DefaultQuery("page_size", "10")
|
||||
pageNumStr := c.DefaultQuery("page_num", "1")
|
||||
pageSize, err := strconv.Atoi(pageSizeStr)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
pageNum, err := strconv.Atoi(pageNumStr)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, err := orderService.GetListByPromotion(pageSize, pageNum, user.Promotion)
|
||||
if err != nil {
|
||||
log.Println("get order list error:", err)
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 获取总单数和总金额
|
||||
totalCount, totalAmount, err := orderService.GetSummaryByPromotion(user.Promotion)
|
||||
if err != nil {
|
||||
log.Println("get order summary error:", err)
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 计算总金额的 30%,并保留两位小数
|
||||
totalAmount30 := math.Round((totalAmount/30.0)*100) / 100
|
||||
response.OkWithData(gin.H{
|
||||
"list": list,
|
||||
"points": 30,
|
||||
"total_count": totalCount,
|
||||
"total_amount": totalAmount30, // 总金额的30%
|
||||
}, c)
|
||||
}
|
||||
func (p *Pay) Prepay(c *gin.Context) {
|
||||
Claims, err := utils.GetClaims(c)
|
||||
if err != nil {
|
||||
@@ -102,6 +153,9 @@ func (p *Pay) Prepay(c *gin.Context) {
|
||||
appid string
|
||||
mchID string
|
||||
)
|
||||
log.Printf("Claims, %+v", Claims)
|
||||
log.Printf("reqBody, %+v", reqBody)
|
||||
|
||||
// 获取用户ip
|
||||
clientIP := c.ClientIP()
|
||||
switch reqBody.Platform {
|
||||
@@ -116,6 +170,10 @@ func (p *Pay) Prepay(c *gin.Context) {
|
||||
case model.PlatformH5:
|
||||
appid = config.ConfigData.System.WxH5AppId
|
||||
mchID = config.ConfigData.WxPay.MchH5ID
|
||||
case model.PlatformTYDATA:
|
||||
openid = Claims.AuthIdentifiers.OpenID
|
||||
appid = config.ConfigData.System.WxTyDataAppId
|
||||
mchID = config.ConfigData.WxPay.MchH5ID
|
||||
default:
|
||||
response.FailWithMessage("ProductName Must be wx or mp-h5 or h5", c)
|
||||
return
|
||||
@@ -154,7 +212,14 @@ func (p *Pay) Prepay(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
} else if reqBody.Platform == model.PlatformMPH5 {
|
||||
resp, err = orderService.WechatJSAPIPrepay(appid, mchID, product, outTradeNo, amount, model.PlatformMPH5, openid, global.GlobalData.PayH5Client)
|
||||
resp, err = orderService.WechatJSAPIPrepay(appid, mchID, product, outTradeNo, amount, openid, model.PlatformMPH5, global.GlobalData.PayH5Client)
|
||||
if err != nil {
|
||||
log.Printf("【创建微信支付订单】创建支付失败,系统错误: %v", err)
|
||||
response.FailWithMessage("创建支付失败,系统错误", c)
|
||||
return
|
||||
}
|
||||
} else if reqBody.Platform == model.PlatformTYDATA {
|
||||
resp, err = orderService.WechatJSAPIPrepay(appid, mchID, product, outTradeNo, amount, openid, model.PlatformTYDATA, global.GlobalData.PayH5Client)
|
||||
if err != nil {
|
||||
log.Printf("【创建微信支付订单】创建支付失败,系统错误: %v", err)
|
||||
response.FailWithMessage("创建支付失败,系统错误", c)
|
||||
@@ -178,6 +243,7 @@ func (p *Pay) Prepay(c *gin.Context) {
|
||||
Product: &product,
|
||||
Platform: reqBody.Platform,
|
||||
PaymentMethod: model.PaymentMethod_WECHAT,
|
||||
Promotion: reqBody.Promotion,
|
||||
}
|
||||
err = db.DB.Create(&payOrder).Error
|
||||
if err != nil {
|
||||
@@ -201,7 +267,7 @@ func (p *Pay) Callback(c *gin.Context) {
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchCertificateSerialNumber
|
||||
mchAPIv3Key = config.ConfigData.WxPay.MchAPIv3Key
|
||||
privateKeyPath = "merchant/mp/apiclient_key.pem"
|
||||
case model.PlatformH5, model.PlatformMPH5:
|
||||
case model.PlatformH5, model.PlatformMPH5, model.PlatformTYDATA:
|
||||
mchID = config.ConfigData.WxPay.MchH5ID
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchH5CertificateSerialNumber
|
||||
mchAPIv3Key = config.ConfigData.WxPay.MchH5APIv3Key
|
||||
@@ -327,7 +393,7 @@ func (p *Pay) Refund(c *gin.Context) {
|
||||
switch order.Platform {
|
||||
case model.PlatformMPWEIXIN:
|
||||
payClient = global.GlobalData.PayClient
|
||||
case model.PlatformH5, model.PlatformMPH5:
|
||||
case model.PlatformH5, model.PlatformMPH5, model.PlatformTYDATA:
|
||||
payClient = global.GlobalData.PayH5Client
|
||||
}
|
||||
outRefundNo := utils.GenerateOrderRefundNumber()
|
||||
@@ -373,7 +439,7 @@ func (p *Pay) RefundCallback(c *gin.Context) {
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchCertificateSerialNumber
|
||||
mchAPIv3Key = config.ConfigData.WxPay.MchAPIv3Key
|
||||
privateKeyPath = "merchant/mp/apiclient_key.pem"
|
||||
case model.PlatformH5, model.PlatformMPH5:
|
||||
case model.PlatformH5, model.PlatformMPH5, model.PlatformTYDATA:
|
||||
mchID = config.ConfigData.WxPay.MchH5ID
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchH5CertificateSerialNumber
|
||||
mchAPIv3Key = config.ConfigData.WxPay.MchH5APIv3Key
|
||||
@@ -485,7 +551,7 @@ func (p *Pay) AliPrepay(c *gin.Context) {
|
||||
pay.Subject = product.ProductName // 订单标题
|
||||
pay.OutTradeNo = outTradeNo // 生成的唯一订单号
|
||||
pay.TotalAmount = amount // 支付金额,单位元
|
||||
pay.ProductCode = "QUICK_WAP_PAY" // WAP支付的产品代码
|
||||
pay.ProductCode = "QUICK_WAP_PAY" // WAP支付的产品代码w
|
||||
|
||||
payURL, err := global.GlobalData.AliPayClient.TradeWapPay(pay)
|
||||
if err != nil {
|
||||
@@ -592,7 +658,7 @@ func (p *Pay) WxPayComplaintCallback(c *gin.Context) {
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchCertificateSerialNumber
|
||||
mchAPIv3Key = config.ConfigData.WxPay.MchAPIv3Key
|
||||
privateKeyPath = "merchant/mp/apiclient_key.pem"
|
||||
case model.PlatformH5, model.PlatformMPH5:
|
||||
case model.PlatformH5, model.PlatformMPH5, model.PlatformTYDATA:
|
||||
platformString = "公众号"
|
||||
mchID = config.ConfigData.WxPay.MchH5ID
|
||||
mchCertificateSerialNumber = config.ConfigData.WxPay.MchH5CertificateSerialNumber
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tidwall/gjson"
|
||||
"net/http"
|
||||
"qnc-server/config"
|
||||
|
||||
@@ -38,6 +39,7 @@ func (s *SingleQuery) EvaluateMarriageQuery(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
var reqBody request.EvaluateMarriageReq
|
||||
if err := c.ShouldBindJSON(&reqBody); err != nil {
|
||||
log.Printf("请求参数错误%v\n", err)
|
||||
response.FailWithMessage("Failed to read request body", c)
|
||||
return
|
||||
}
|
||||
@@ -129,7 +131,6 @@ func (s *SingleQuery) EvaluateMarriageQuery(c *gin.Context) {
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
|
||||
if twoElementsResp.Success == false {
|
||||
response.FailWithMessage("请输入有效的身份证号码", c)
|
||||
return
|
||||
@@ -172,10 +173,28 @@ func (s *SingleQuery) EvaluateMarriageQuery(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
evaluateMarriageReq := map[string]interface{}{
|
||||
"name": encodeName,
|
||||
"id": encodeID,
|
||||
"nameMan": encodeName,
|
||||
"certNumMan": encodeID,
|
||||
}
|
||||
|
||||
const maxRetryCount = 5
|
||||
retryCount := 0
|
||||
|
||||
var plainText string
|
||||
|
||||
for retryCount < maxRetryCount {
|
||||
plainText, err = requestService.WestDexRequest("G09SC02", evaluateMarriageReq)
|
||||
if err != nil {
|
||||
retryCount++
|
||||
continue
|
||||
}
|
||||
marriageResult := gjson.Get(plainText, "data.0.maritalStatus")
|
||||
if marriageResult.Exists() {
|
||||
break
|
||||
} else {
|
||||
retryCount++
|
||||
}
|
||||
}
|
||||
plainText, err := requestService.WestDexRequest("G09GX01", evaluateMarriageReq)
|
||||
if err != nil {
|
||||
notifyService.SendNotification("接口系统错误,将自动退款", "婚姻查询", userid, order.ID)
|
||||
if order.PaymentMethod == model.PaymentMethod_ALIPAY {
|
||||
@@ -233,16 +252,33 @@ func (s *SingleQuery) EvaluateMarriageQuery(c *gin.Context) {
|
||||
}
|
||||
|
||||
var code string
|
||||
if result.Code == 201 {
|
||||
code = "1"
|
||||
} else if result.Code == 202 {
|
||||
code = "2"
|
||||
} else if result.Code == 203 {
|
||||
code = "0"
|
||||
} else {
|
||||
response.FailRefund(c)
|
||||
return
|
||||
for _, entry := range result.Data {
|
||||
if entry.MaritalStatus == "" {
|
||||
notifyService.SendNotification("婚姻查询数据为空字段,自动退款", "婚姻查询", userid, order.ID)
|
||||
if order.PaymentMethod == model.PaymentMethod_ALIPAY {
|
||||
err := orderService.AliRefund(ctx, order)
|
||||
if err != nil {
|
||||
notifyService.SendNotification("【支付宝】婚姻查询数据为空,自动退款失败", "婚姻查询", userid, order.ID)
|
||||
} else {
|
||||
notifyService.SendNotification("【支付宝】自动退款成功", order.Product.ProductName, order.Userid, order.ID)
|
||||
}
|
||||
} else {
|
||||
err := orderService.WeChatRefund(order)
|
||||
if err != nil {
|
||||
notifyService.SendNotification("婚姻查询数据为空,自动退款失败", "婚姻查询", userid, order.ID)
|
||||
}
|
||||
}
|
||||
log.Printf("【婚姻查询】数据为空,自动退款")
|
||||
response.FailRefund(c)
|
||||
return
|
||||
}
|
||||
code = entry.MaritalStatus
|
||||
if code == "3" {
|
||||
code = "2"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
orderService.OrderConsumed(order)
|
||||
var query model.Query
|
||||
query.OrderID = order.ID
|
||||
|
||||
74
api/user.go
74
api/user.go
@@ -31,6 +31,7 @@ func InitUser(group *gin.RouterGroup) {
|
||||
userPublicGroup.GET("test", u.Test)
|
||||
userPublicGroup.POST("log", u.Log)
|
||||
userPublicGroup.POST("login", u.Login)
|
||||
userPublicGroup.POST("tydata_login", u.TyDataLogin)
|
||||
userPublicGroup.POST("h5_login", u.H5Login)
|
||||
userPublicGroup.POST("phone_login", u.PhoneLogin)
|
||||
userPublicGroup.POST("verify", u.GetVerify)
|
||||
@@ -128,6 +129,79 @@ func (u *User) Login(c *gin.Context) {
|
||||
u.TokenNext(c, user, authIdentifier, model.AUTHTYPE_WECHAT_MP)
|
||||
}
|
||||
|
||||
// 天远数据登录
|
||||
func (u *User) TyDataLogin(c *gin.Context) {
|
||||
var reqBody request.UserLoginReq
|
||||
|
||||
// 尝试将请求的 JSON body 绑定到 reqBody 结构体
|
||||
if err := c.ShouldBindJSON(&reqBody); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检查请求体中是否包含 code 字段
|
||||
if reqBody.Code == "" {
|
||||
response.FailWithMessage("code is required", c)
|
||||
return
|
||||
}
|
||||
|
||||
// Code获取用户信息
|
||||
wxResponse, err := userService.RequestWxTyData(reqBody.Code)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Errorf("request weixin err:%w", err).Error(), c)
|
||||
return
|
||||
}
|
||||
authIdentifier := model.AuthIdentifier{
|
||||
OpenID: wxResponse.OpenId,
|
||||
UnionID: wxResponse.Unionid,
|
||||
}
|
||||
// 是否有匹配的校验信息
|
||||
authentications, err := userService.MatchingAuthentications(authIdentifier)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("MatchingAuthentications Error:%v", err)
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
var authentication model.Authentication
|
||||
if len(authentications) == 0 {
|
||||
authentication, err = userService.Register(model.User{}, model.AUTHTYPE_TYDATA, authIdentifier)
|
||||
if err != nil {
|
||||
log.Printf("注册用户错误:%v", err)
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
//成功创建用户
|
||||
} else {
|
||||
// 校验信息是否有该平台
|
||||
hasWechatMP := false
|
||||
for _, auth := range authentications {
|
||||
if auth.AuthType == model.AUTHTYPE_TYDATA {
|
||||
hasWechatMP = true
|
||||
authentication = auth
|
||||
}
|
||||
}
|
||||
// 没有则创建该平台校验并关联用户
|
||||
if !hasWechatMP {
|
||||
userid := authentication.UserID
|
||||
authentication, err = userService.CreateAuthentications(userid, authIdentifier, model.AUTHTYPE_TYDATA)
|
||||
if err != nil {
|
||||
log.Printf("创建平台校验错误:%v", err)
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
//成功校验该平台成功
|
||||
}
|
||||
}
|
||||
user, err := userService.GetUser(authentication.UserID)
|
||||
if err != nil {
|
||||
log.Printf("authentication获取关联用户失败:%v", err)
|
||||
response.FailWithMessage("系统错误,请稍后再试", c)
|
||||
return
|
||||
}
|
||||
u.TokenNext(c, user, authIdentifier, model.AUTHTYPE_TYDATA)
|
||||
}
|
||||
|
||||
// 公众号h5登录
|
||||
func (u *User) H5Login(c *gin.Context) {
|
||||
var reqBody request.H5UserLoginReq
|
||||
|
||||
Reference in New Issue
Block a user