Commit 6fd3ca09 authored by wangp's avatar wangp

拉卡拉聚合扫码

parent 254551df
...@@ -23,18 +23,18 @@ import ( ...@@ -23,18 +23,18 @@ import (
type NoticeController struct { type NoticeController struct {
} }
// WxNotice 拉卡拉统一支付微信回调 // CashierNotice 拉卡拉统一支付回调(收银台)
// @Summary 拉卡拉统一支付微信回调 // @Summary 拉卡拉统一支付回调(收银台)
// @Description 拉卡拉统一支付微信回调 // @Description 拉卡拉统一支付回调(收银台)
// @Tags 拉卡拉统一支付回调 // @Tags 拉卡拉统一支付回调
// @Accept application/json // @Accept application/json
// @Produce application/json // @Produce application/json
// @Param body body models.WxNoticeInput true "参数" // @Param body body models.CashierNoticeInput true "参数"
// @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文" // @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文"
// @Success 200 // @Success 200
// @router /api/v1/pay/wx_notice [post] // @router /api/v1/pay/cashier_notice [post]
func (l *PayController) WxNotice(c *gin.Context) { func (l *PayController) CashierNotice(c *gin.Context) {
fmt.Println("拉卡拉微信回调start") fmt.Println("拉卡拉回调(收银台)start")
//验证签名 //验证签名
err := VerifySignCert(c) err := VerifySignCert(c)
...@@ -46,19 +46,54 @@ func (l *PayController) WxNotice(c *gin.Context) { ...@@ -46,19 +46,54 @@ func (l *PayController) WxNotice(c *gin.Context) {
base.ResponseWxNotice(c, response) base.ResponseWxNotice(c, response)
return return
} }
fmt.Println("验证签名成功")
//fmt.Println("验证签名成功...未完...") ph := new(models.CashierNoticeInput)
//response := new(base.ResponseDataWxNotice) err = c.ShouldBindBodyWith(&ph, binding.JSON)
//response.Code = "SUCCESS" if err != nil {
//response.Message = "执行成功" response := new(base.ResponseDataWxNotice)
//base.ResponseWxNotice(c, response) response.Code = "FAIL"
//return response.Message = "执行失败2"
base.ResponseWxNotice(c, response)
return
}
fmt.Println(ph)
fmt.Println("验证签名成功") // 拉卡拉统一支付微信回调
response, err := pay.CashierNotice(ph)
fmt.Println("拉卡拉回调(收银台)end")
base.ResponseWxNotice(c, response)
}
ph := new(models.WxNoticeInput) // ScanNotice 拉卡拉统一支付回调(聚合扫码)
// @Summary 拉卡拉统一支付回调(聚合扫码)
// @Description 拉卡拉统一支付回调(聚合扫码)
// @Tags 拉卡拉统一支付回调
// @Accept application/json
// @Produce application/json
// @Param body body models.ScanNoticeInput true "参数"
// @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文"
// @Success 200
// @router /api/v1/pay/scan_notice [post]
func (l *PayController) ScanNotice(c *gin.Context) {
fmt.Println("拉卡拉回调(聚合扫码)start")
//验证签名
//err := VerifySignCert(c)
//if err != nil {
// fmt.Println("verySignByPublicKey err: ", err)
// response := new(base.ResponseDataWxNotice)
// response.Code = "FAIL"
// response.Message = "验证签名失败"
// base.ResponseWxNotice(c, response)
// return
//}
//fmt.Println("验证签名成功")
ph := new(models.ScanNoticeInput)
//err := c.ShouldBindJSON(ph) //err := c.ShouldBindJSON(ph)
err = c.ShouldBindBodyWith(&ph, binding.JSON) err := c.ShouldBindBodyWith(&ph, binding.JSON)
if err != nil { if err != nil {
response := new(base.ResponseDataWxNotice) response := new(base.ResponseDataWxNotice)
response.Code = "FAIL" response.Code = "FAIL"
...@@ -69,9 +104,9 @@ func (l *PayController) WxNotice(c *gin.Context) { ...@@ -69,9 +104,9 @@ func (l *PayController) WxNotice(c *gin.Context) {
fmt.Println(ph) fmt.Println(ph)
// 拉卡拉统一支付微信回调 // 拉卡拉统一支付微信回调
response, err := pay.WxNotice(ph) response, err := pay.ScanNotice(ph)
fmt.Println("拉卡拉微信回调end") fmt.Println("拉卡拉回调(聚合扫码)end")
base.ResponseWxNotice(c, response) base.ResponseWxNotice(c, response)
} }
......
package models package models
// WxNoticeInput 微信回调输入参数 //聚合收银台-交易通知(回调输入参数)
type WxNoticeInput struct { type CashierNoticeInput struct {
ChannelId string `json:"channel_id" description:"渠道号"` ChannelId string `json:"channel_id" description:"渠道号"`
MerchantNo string `json:"merchant_no" description:"结算商户号"` MerchantNo string `json:"merchant_no" description:"结算商户号"`
OrderCreateTime string `json:"order_create_time" description:"订单创建时间"` OrderCreateTime string `json:"order_create_time" description:"订单创建时间"`
...@@ -17,6 +17,32 @@ type WxNoticeInput struct { ...@@ -17,6 +17,32 @@ type WxNoticeInput struct {
OrderTradeInfo interface{} `json:"order_trade_info" description:""` OrderTradeInfo interface{} `json:"order_trade_info" description:""`
SplitInfo interface{} `json:"split_info" description:""` SplitInfo interface{} `json:"split_info" description:""`
} }
//聚合扫码-交易通知(回调输入参数)
type ScanNoticeInput struct {
MerchantNo string `json:"merchant_no" description:"商户号"`
OutTradeNo string `json:"out_trade_no" description:"商户交易流水号"`
TradeNo string `json:"trade_no" description:"拉卡拉交易流水号"`
LogNo string `json:"log_no" description:"拉卡拉对账单流水号"`
AccTradeNo string `json:"acc_trade_no" description:"账户端交易订单号"`
AccountType string `json:"account_type" description:"钱包类型"`
SettleMerchantNo string `json:"settle_merchant_no" description:"结算商户号"`
SettleTermNo string `json:"settle_term_no" description:"结算终端号"`
TradeStatus string `json:"trade_status" description:"交易状态"`
TotalAmount string `json:"total_amount" description:"订单金额"`
PayerAmount string `json:"payer_amount" description:"付款人实付金额"`
AccSettleAmount string `json:"acc_settle_amount" description:"账户端结算金额"`
AccMdiscountAmount string `json:"acc_mdiscount_amount" description:"商户侧优惠金额(账户端)"`
AccDiscountAmount string `json:"acc_discount_amount" description:"账户端优惠金额"`
AccOtherDiscountAmount string `json:"acc_other_discount_amount" description:"账户端其它优惠金额(待上线)"`
TradeTime string `json:"trade_time" description:"交易完成时间"`
UserId1 string `json:"user_id1" description:"用户标识1"`
UserId2 string `json:"user_id2" description:"用户标识2"`
AccActivityId string `json:"acc_activity_id" description:"活动ID"`
BankType string `json:"bank_type" description:"付款银行"`
CardType string `json:"card_type" description:"银行卡类型"`
Remark string `json:"remark" description:"备注"`
HbFqPayInfo interface{} `json:"hb_fq_pay_info" description:"花呗分期支付信息(未上线)"`
}
// CallbackResponse is 回调给业务方的信息 // CallbackResponse is 回调给业务方的信息
type CallbackResponse struct { type CallbackResponse struct {
......
...@@ -9,10 +9,10 @@ import ( ...@@ -9,10 +9,10 @@ import (
"system_pay/mysql" "system_pay/mysql"
) )
// 拉卡拉微信支付回调 - AliPayNotice // 拉卡拉支付回调(收银台)
func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) { func CashierNotice(input *models.CashierNoticeInput) (*base.ResponseDataWxNotice, error) {
fmt.Println("拉卡拉微信回调输入参数") fmt.Println("拉卡拉回调(收银台)输入参数")
fmt.Println(input) fmt.Println(input)
response := new(base.ResponseDataWxNotice) response := new(base.ResponseDataWxNotice)
...@@ -144,6 +144,141 @@ func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) { ...@@ -144,6 +144,141 @@ func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) {
return response, nil return response, nil
} }
// 拉卡拉支付回调(扫码)
func ScanNotice(input *models.ScanNoticeInput) (*base.ResponseDataWxNotice, error) {
fmt.Println("拉卡拉回调(扫码)输入参数")
fmt.Println(input)
response := new(base.ResponseDataWxNotice)
//db, err := mysql.NewShopConn()
//if err != nil {
// response.Code = "FAIL"
// response.Message = "参数格式校验错误"
// return response, err
//}
// 插入数据库
db, err := mysql.NewPayConn()
if err != nil {
return response, err
}
tx, err := db.Begin()
if err != nil {
return response, err
}
defer mysql.CloseTx(tx, err)
fmt.Println("111")
//1.订单存在check
var billID int64
var attach, url string
err = db.QueryRow("select ifnull(id, 0), attach, notify_pay_url from system_pay_bill where payment_order_code = ?",
input.OutTradeNo).Scan(&billID, &attach, &url)
if err != nil || billID == 0 || billID == 2 {
response.Code = "FAIL"
response.Message = "db operation fail1"
return response, err
}
fmt.Println("222")
//if noticeRequest.ReturnCode == "SUCCESS" {
// 把订单状态置为 结算成功
err = BillPayStateSuccess(tx, billID)
if err != nil {
//beego.Error("微信回调, 根据订单id 把订单置为结算成功 失败: ", err)
//response.ReturnCode = "FAIL"
//response.ReturnMsg = "db operation fail"
//return response, nil
response.Code = "FAIL"
response.Message = "db operation fail2"
InsertPayBillDetailNoticeResponseBody(tx, billID, response)
return response, err
}
//} else {
//
// // 把订单状态置为 结算失败
// err = repository.BillPayStateFail(tx, billID)
// if err != nil {
// beego.Error("微信回调, 根据订单id 把订单置为结算成功 失败: ", err)
// response.ReturnCode = "FAIL"
// response.ReturnMsg = "db operation fail"
// return response, nil
// }
//}
//2.「拉卡拉返回数据」存入 notice_request_body
err = InsertPayBillDetailNoticeRequestBody(tx, billID, input)
if err != nil {
//beego.Error("微信回调, 根据订单id 插入回调Request参数 失败: ", err)
response.Code = "FAIL"
response.Message = "db operation fail3"
InsertPayBillDetailNoticeResponseBody(tx, billID, response)
return response, err
}
fmt.Println("333")
//3.拉卡拉订收银台订单查询 - check todo
//3.存入 notice_response_body
//err = InsertPayBillDetailNoticeResponseBody(billID, response)
//if err != nil {
// beego.Error("微信回调, 根据订单id 插入回调Response参数 失败: ", err)
// response.ReturnCode = "FAIL"
// response.ReturnMsg = "db operation fail"
// return err
//}
//beego.Info("回调成功 订单成功")
//type CallbackResponse struct {
// OutTradeNo string `json:"out_trade_no"` // 订单号
// ReturnMsg string `json:"return_msg"` // 是否成功
// AttachInfo string `json:"attach_info"` // 附加信息
// TransactionID string `json:"transaction_id"` // 微信支付订单号
// TradeNo string `json:"trade_no"` // 支付宝交易流水号
//}
if url != "" {
//4.回调业务方「回调函数」
callbackResponse := new(models.CallbackResponse)
callbackResponse.ReturnMsg = "SUCCESS"
//callbackResponse.OutTradeNo = input.OutTradeNo
//callbackResponse.TransactionID = input.TransactionId
callbackResponse.OutTradeNo = input.OutTradeNo //交易凭据单号 todo ?
callbackResponse.TransactionID = input.OutTradeNo //交易凭据单号 todo ? strconv.Itoa(
//OrderTradeInfo, _ := input.OrderTradeInfo.(map[string]interface{})
//if OrderTradeInfo["auth_code"] != nil {
// //LAKALA签约协议号列表
// callbackResponse.AuthCode = OrderTradeInfo["auth_code"].(string)
//}
attachMap := make(map[string]interface{}, 0)
_ = json.Unmarshal([]byte(attach), &attachMap)
if attachMap["store_sn"].(string) == "" {
callbackResponse.AttachInfo = attachMap["old_attach"].(string)
} else {
callbackResponse.AttachInfo = attach //商户订单号(谛宝多多)
}
//fmt.Println("444444444444444444444444444")
//fmt.Println(callbackResponse)
go callBackBusinessService(input.OutTradeNo, url, callbackResponse)
}
response.Code = "SUCCESS"
response.Message = "执行成功"
InsertPayBillDetailNoticeResponseBody(tx, billID, response)
return response, nil
}
// InsertPayBillDetailNoticeRequestBody is 插入支付订单详情表中的 下单参数字段 notice_request_body // InsertPayBillDetailNoticeRequestBody is 插入支付订单详情表中的 下单参数字段 notice_request_body
func InsertPayBillDetailNoticeRequestBody(tx *sql.Tx, billID int64, noticeRequestBody interface{}) error { func InsertPayBillDetailNoticeRequestBody(tx *sql.Tx, billID int64, noticeRequestBody interface{}) error {
......
...@@ -353,7 +353,7 @@ func lakala_post(input *models.PlaceAnOrderParamInput, url, order_id string, dat ...@@ -353,7 +353,7 @@ func lakala_post(input *models.PlaceAnOrderParamInput, url, order_id string, dat
} }
} else if source_code==2 || source_code==3 { } else if source_code==2 || source_code==3 {
//聚合主扫(微信JSAPI+微信小程序)(必康自营除外) //聚合主扫(微信JSAPI+微信小程序)(必康自营的微信小程序除外)
temp2, _ := temp["resp_data"].(map[string]interface{}) temp2, _ := temp["resp_data"].(map[string]interface{})
temp3, _ := temp2["acc_resp_fields"].(map[string]interface{}) temp3, _ := temp2["acc_resp_fields"].(map[string]interface{})
if temp2["acc_resp_fields"]=="" { if temp2["acc_resp_fields"]=="" {
...@@ -472,10 +472,15 @@ func ReadParsePrivaterKey(filename string) (*rsa.PrivateKey, error) { ...@@ -472,10 +472,15 @@ func ReadParsePrivaterKey(filename string) (*rsa.PrivateKey, error) {
} }
// GetNoticeURL is 获取回调地址 // GetNoticeURL is 获取回调地址
func GetNoticeURL(sourceCode uint8) string { func GetNoticeURL(source_code uint8) string {
domainName := setting.Conf.PayUrl.DomainName
domainName := setting.Conf.PayUrl.DomainName //todo if source_code==2 || source_code==3 || source_code==9 {
return domainName + "/api/v1/pay/wx_notice" //目前微信、支付宝调同一个地址 //聚合扫码+聚合被扫
return domainName + "/api/v1/pay/scan_notice"
} else {
//其它支付
return domainName + "/api/v1/pay/cashier_notice"
}
} }
//InsertPayBill is 插入 支付订单表中 //InsertPayBill is 插入 支付订单表中
...@@ -777,7 +782,7 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -777,7 +782,7 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
var status uint var status uint
var platform_type uint8 var platform_type uint8
var source_code uint8 var source_code uint8
var notice_request models.WxNoticeInput var notice_request interface{}
var notice_request2 []byte var notice_request2 []byte
//payment_order_code, paymoney //payment_order_code, paymoney
...@@ -789,6 +794,15 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -789,6 +794,15 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
if err != nil { if err != nil {
return "", "", 0, 0, err return "", "", 0, 0, err
} }
if source_code==2 || source_code==3 || source_code==9 {
//聚合扫码+聚合被扫
notice_request = new(models.ScanNoticeInput)
} else {
//其它支付
notice_request = new(models.CashierNoticeInput)
}
if err := json.Unmarshal(notice_request2, &notice_request); err != nil { if err := json.Unmarshal(notice_request2, &notice_request); err != nil {
return "", "", 0, 0, err return "", "", 0, 0, err
} }
...@@ -817,17 +831,28 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -817,17 +831,28 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
} }
// 获取「对账单流水号」和「交易终端号」,退款用 // 获取「对账单流水号」和「交易终端号」,退款用
// 针对有的支付,不需要传「交易终端号」时,需要用支付返回的「交易终端号」进行退款 var log_no, trans_term_no string
log_no := notice_request.OrderTradeInfo.(map[string]interface{})["log_no"].(string) if source_code==2 || source_code==3 || source_code==9 {
if log_no=="" { //聚合扫码+聚合被扫
return "", "", 0, 0, errors.New("「对账单流水号」未取得错误") log_no = notice_request.(models.ScanNoticeInput).LogNo
} if log_no=="" {
if notice_request.TransTermNo=="" { return "", "", 0, 0, errors.New("「对账单流水号」未取得错误")
//todo }
return "", "", 0, 0, errors.New("「交易终端号」未取得错误") } else {
//其它支付
// 针对有的支付,不需要传「交易终端号」时,需要用支付返回的「交易终端号」进行退款
log_no = notice_request.(models.CashierNoticeInput).OrderTradeInfo.(map[string]interface{})["log_no"].(string)
if log_no=="" {
return "", "", 0, 0, errors.New("「对账单流水号」未取得错误")
}
trans_term_no = notice_request.(models.CashierNoticeInput).TransTermNo
if trans_term_no=="" {
//todo
return "", "", 0, 0, errors.New("「交易终端号」未取得错误")
}
} }
return log_no, notice_request.TransTermNo, source_code, platform_type, nil return log_no, trans_term_no, source_code, platform_type, nil
} }
//InsertRefundBill is 插入 支付订单表中 //InsertRefundBill is 插入 支付订单表中
......
...@@ -13,8 +13,11 @@ func PayRouter (r *gin.Engine) { ...@@ -13,8 +13,11 @@ func PayRouter (r *gin.Engine) {
// 卡拉卡统一支付 // 卡拉卡统一支付
r.POST(pack.PayUrlPacking("unified_order"), PayController.UnifiedOrder) r.POST(pack.PayUrlPacking("unified_order"), PayController.UnifiedOrder)
// 卡拉卡统一支付回调 // 卡拉卡统一支付回调(收银台)
r.POST(pack.PayUrlPacking("wx_notice"), PayController.WxNotice) r.POST(pack.PayUrlPacking("cashier_notice"), PayController.CashierNotice)
// 卡拉卡统一支付回调(聚合扫码)
r.POST(pack.PayUrlPacking("scan_notice"), PayController.ScanNotice)
// 卡拉卡统一支付 // 卡拉卡统一支付
r.POST(pack.PayUrlPacking("unified_refund"), PayController.UnifiedRefund) r.POST(pack.PayUrlPacking("unified_refund"), PayController.UnifiedRefund)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment