Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
system_pay
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王沛
system_pay
Commits
13ef1742
Commit
13ef1742
authored
Jun 27, 2023
by
wangp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lakala
parent
47990473
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
198 additions
and
54 deletions
+198
-54
notice.go
controller/api/v1/pay/notice.go
+1
-1
pay.go
controller/api/v1/pay/pay.go
+1
-1
pay.go
models/pay.go
+17
-23
notice.go
repository/pay/notice.go
+27
-9
pay.go
repository/pay/pay.go
+75
-20
pay_router.go
router/v1/pay_router.go
+3
-0
mysql.go
utils/mysql.go
+74
-0
No files found.
controller/api/v1/pay/notice.go
View file @
13ef1742
...
...
@@ -32,7 +32,7 @@ func (l *PayController) WxNotice(c *gin.Context) {
return
}
//
绑定
//
拉卡拉统一支付微信回调
response
,
err
:=
pay
.
WxNotice
(
ph
)
base
.
ResponseWxNotice
(
c
,
response
)
}
controller/api/v1/pay/pay.go
View file @
13ef1742
...
...
@@ -32,7 +32,7 @@ func (l *PayController) UnifiedOrder(c *gin.Context) {
return
}
//
绑定
//
拉卡拉统一支付
rtn
,
err
:=
pay
.
UnifiedOrder
(
ph
)
if
err
!=
nil
{
zap
.
L
()
.
Error
(
err
.
Error
())
...
...
models/pay.go
View file @
13ef1742
package
models
import
(
"errors"
"github.com/astaxie/beego/validation"
"reflect"
)
type
PlaceAnOrderParamInput
struct
{
PlatformType
uint8
`json:"platform_type" description:"平台类型 1: saas 2: shop 3: shop mobile 4: 收银台"`
PlatformInfo
string
`json:"platform_info" description:"平台信息"`
...
...
@@ -33,23 +27,23 @@ type PlaceAnOrderParamInput struct {
ServeNoticeUrl
string
`json:"-" description:"传递给支付渠道的、而不是业务方的"`
}
func
(
this
*
PlaceAnOrderParamInput
)
ValidPlaceAnOrderParamInput
()
(
err
error
)
{
valid
:=
validation
.
Validation
{}
if
b
,
_
:=
valid
.
Valid
(
this
);
!
b
{
//表示获取验证的结构体
st
:=
reflect
.
TypeOf
(
PlaceAnOrderParamInput
{})
for
_
,
err
:=
range
valid
.
Errors
{
//获取验证的字段名和提示信息的别名
filed
,
_
:=
st
.
FieldByName
(
err
.
Field
)
var
alias
=
filed
.
Tag
.
Get
(
"alias"
)
//返回验证的错误信息
return
errors
.
New
(
alias
+
err
.
Message
)
}
}
return
nil
}
//
func (this *PlaceAnOrderParamInput) ValidPlaceAnOrderParamInput() (err error) {
//
valid := validation.Validation{}
//
//
if b, _ := valid.Valid(this); !b {
//
//表示获取验证的结构体
//
st := reflect.TypeOf(PlaceAnOrderParamInput{})
//
for _, err := range valid.Errors {
//
//获取验证的字段名和提示信息的别名
//
filed, _ := st.FieldByName(err.Field)
//
var alias= filed.Tag.Get("alias")
//
//返回验证的错误信息
//
return errors.New(alias + err.Message)
//
}
//
}
//
//
return nil
//
}
type
LakalaParamInput
struct
{
Version
string
`json:"version" description:"版本"`
...
...
repository/pay/notice.go
View file @
13ef1742
package
pay
import
(
"database/sql"
"encoding/json"
"fmt"
"strconv"
"system_pay/controller/base"
"system_pay/models"
"system_pay/mysql"
"system_pay/utils"
)
// 拉卡拉微信支付回调 - AliPayNotice
...
...
@@ -17,16 +19,29 @@ func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) {
response
:=
new
(
base
.
ResponseDataWxNotice
)
db
,
err
:=
mysql
.
NewShopConn
()
//db, err := mysql.NewShopConn()
//if err != nil {
// response.Code = "FAIL"
// response.Message = "参数格式校验错误"
// return response, err
//}
// 插入数据库
db
,
err
:=
utils
.
NewPayConn
()
if
err
!=
nil
{
return
response
,
err
}
tx
,
err
:=
db
.
Begin
()
if
err
!=
nil
{
response
.
Code
=
"FAIL"
response
.
Message
=
"参数格式校验错误"
return
response
,
err
}
defer
utils
.
CloseTx
(
tx
,
err
)
fmt
.
Println
(
"111"
)
//1.订单
合法
check
//1.订单
存在
check
var
billID
int64
var
attach
,
url
string
err
=
db
.
QueryRow
(
"select ifnull(id, 0), attach, notify_pay_url from pay_bill where payment_order_code = ?"
,
...
...
@@ -40,17 +55,20 @@ func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) {
fmt
.
Println
(
"222"
)
//2.存入 notice_request_body
err
=
InsertPayBillDetailNoticeRequestBody
(
billID
,
input
)
err
=
InsertPayBillDetailNoticeRequestBody
(
tx
,
billID
,
input
)
if
err
!=
nil
{
//beego.Error("微信回调, 根据订单id 插入回调Request参数 失败: ", err)
response
.
Code
=
"FAIL"
response
.
Message
=
"db operation fail"
InsertPayBillDetailNoticeResponseBody
(
billID
,
response
)
InsertPayBillDetailNoticeResponseBody
(
tx
,
billID
,
response
)
return
response
,
err
}
fmt
.
Println
(
"333"
)
//3.拉卡拉订收银台订单查询 - check todo
//3.存入 notice_response_body
//err = InsertPayBillDetailNoticeResponseBody(billID, response)
//if err != nil {
...
...
@@ -93,12 +111,12 @@ func WxNotice(input *models.WxNoticeInput) (*base.ResponseDataWxNotice, error) {
response
.
Code
=
"SUCCESS"
response
.
Message
=
"执行成功"
InsertPayBillDetailNoticeResponseBody
(
billID
,
response
)
InsertPayBillDetailNoticeResponseBody
(
tx
,
billID
,
response
)
return
response
,
nil
}
// InsertPayBillDetailNoticeRequestBody is 插入支付订单详情表中的 下单参数字段 notice_request_body
func
InsertPayBillDetailNoticeRequestBody
(
billID
int64
,
noticeRequestBody
interface
{})
error
{
func
InsertPayBillDetailNoticeRequestBody
(
tx
*
sql
.
Tx
,
billID
int64
,
noticeRequestBody
interface
{})
error
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
@@ -123,7 +141,7 @@ func InsertPayBillDetailNoticeRequestBody(billID int64, noticeRequestBody interf
}
// InsertPayBillDetailNoticeResponseBody is 插入支付订单详情表中的 下单参数字段 notice_response_body
func
InsertPayBillDetailNoticeResponseBody
(
billID
int64
,
noticeResponseBody
interface
{})
error
{
func
InsertPayBillDetailNoticeResponseBody
(
tx
*
sql
.
Tx
,
billID
int64
,
noticeResponseBody
interface
{})
error
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
repository/pay/pay.go
View file @
13ef1742
...
...
@@ -6,6 +6,7 @@ import (
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"database/sql"
"encoding/base64"
"encoding/json"
"encoding/pem"
...
...
@@ -13,10 +14,12 @@ import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
uID
"github.com/satori/go.uuid"
rand2
"math/rand"
"strings"
"system_pay/models"
"system_pay/mysql"
"system_pay/utils"
"time"
)
...
...
@@ -36,6 +39,35 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
fmt
.
Println
(
"拉卡拉支付接口输入参数"
)
fmt
.
Println
(
input
)
orderID
:=
GetUID
()
beego
.
Info
(
"AttachInfo: "
,
input
.
AttachInfo
)
attachMap
:=
make
(
map
[
string
]
interface
{},
0
)
attachMap
[
"store_sn"
]
=
input
.
StoreSn
attachMap
[
"old_attach"
]
=
input
.
AttachInfo
attach
,
_
:=
json
.
Marshal
(
attachMap
)
input
.
AttachInfo
=
string
(
attach
)
// 插入数据库
db
,
err
:=
utils
.
NewPayConn
()
if
err
!=
nil
{
return
0
,
err
}
tx
,
err
:=
db
.
Begin
()
if
err
!=
nil
{
return
nil
,
err
}
defer
utils
.
CloseTx
(
tx
,
err
)
billID
,
err
:=
InsertPayBill
(
tx
,
input
,
orderID
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"req_time"
]
=
"20230626100000"
data
[
"version"
]
=
"3.0"
...
...
@@ -126,6 +158,19 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
fmt
.
Println
(
"拉卡拉输入参数"
)
fmt
.
Println
(
data
)
// 插入下单请求参数
err
=
InsertPayBillDetailRequestBody
(
tx
,
billID
,
data
)
if
err
!=
nil
{
return
nil
,
err
}
//ok, err := wechat.VerifySign(WxKey, wechat.SignType_MD5, wxResponse)
//if err != nil || !ok {
// beego.Error("验签失败, 订单号是: ", orderID)
// beego.Error("wx response: ", wxResponse)
// return nil, err
//}
data_json
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
//this.Data["json"] = utils.CheckError(errors.New("Map转化为byte数组失败"),"异常")
...
...
@@ -138,22 +183,21 @@ func UnifiedOrder(input *models.PlaceAnOrderParamInput) (interface{}, error) {
url
:=
"https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create"
//拉卡拉收银台订单创建url
//调拉卡拉接口
err
,
m_web_url
:=
lakala_post
(
url
,
data_json
)
err
,
m_web_url
,
lakala_rtn
:=
lakala_post
(
url
,
data_json
)
if
err
!=
nil
{
//this.Data["json"] = utils.CheckError(err,"拉卡拉错误")
//this.ServeJSON()
return
nil
,
err
}
response
:=
make
(
map
[
string
]
string
)
response
[
"m_web_url"
]
=
m_web_url
//this.Data["json"] = utils.SuccessLakala(response)
//this.ServeJSON()
// 插入下单成功后返回的参数
err
=
InsertPayBillDetailResponseBody
(
tx
,
billID
,
lakala_rtn
)
if
err
!=
nil
{
beego
.
Error
(
"下单请求成功 --- 但插入成功后的参数失败"
)
return
nil
,
err
}
//rtn["token"] = token
//rtn["user_id"] = seller_id
//rtn["user_name"] = seller_name
return
response
,
nil
//1.校验供应商账号(手机号)是否已注册
...
...
@@ -334,7 +378,7 @@ func UnifiedOrder2(input *models.PlaceAnOrderParamInput) (interface{}, error) {
//url := "https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create" //拉卡拉收银台订单创建url
//调拉卡拉接口
err
,
_
=
lakala_post
(
url
,
data_json
)
err
,
_
,
_
=
lakala_post
(
url
,
data_json
)
if
err
!=
nil
{
//this.Data["json"] = utils.CheckError(err,"拉卡拉错误")
//this.ServeJSON()
...
...
@@ -358,10 +402,10 @@ func UnifiedOrder2(input *models.PlaceAnOrderParamInput) (interface{}, error) {
}
func
lakala_post
(
url
string
,
data_json
[]
byte
)
(
error
,
string
)
{
func
lakala_post
(
url
string
,
data_json
[]
byte
)
(
error
,
string
,
interface
{}
)
{
authorization
,
err
:=
getAuthorization
(
string
(
data_json
))
if
err
!=
nil
{
return
err
,
""
return
err
,
""
,
nil
}
...
...
@@ -376,13 +420,13 @@ func lakala_post(url string, data_json []byte) (error, string) {
req
.
Body
(
data_json
)
body
,
err
:=
req
.
Bytes
()
if
err
!=
nil
{
return
err
,
""
return
err
,
""
,
nil
}
temp
:=
make
(
map
[
string
]
interface
{},
0
)
if
err
=
json
.
Unmarshal
(
body
,
&
temp
);
err
!=
nil
{
return
err
,
""
return
err
,
""
,
nil
}
fmt
.
Println
(
"拉卡拉返回值"
)
...
...
@@ -391,16 +435,16 @@ func lakala_post(url string, data_json []byte) (error, string) {
if
temp
[
"code"
]
!=
"000000"
{
//this.Data["json"] = utils.CheckError(errors.New("拉卡拉错误"), temp["msg"].(string)) //todo
//this.ServeJSON()
return
errors
.
New
(
temp
[
"msg"
]
.
(
string
)),
""
return
errors
.
New
(
temp
[
"msg"
]
.
(
string
)),
""
,
temp
}
//return nil, temp["resp_data"]["counter_url"]
temp2
,
_
:=
temp
[
"resp_data"
]
.
(
map
[
string
]
interface
{})
if
temp2
[
"counter_url"
]
==
""
{
return
errors
.
New
(
"拉卡拉返回值「counter_url」为空错误"
),
""
return
errors
.
New
(
"拉卡拉返回值「counter_url」为空错误"
),
""
,
temp
}
return
nil
,
temp2
[
"counter_url"
]
.
(
string
)
return
nil
,
temp2
[
"counter_url"
]
.
(
string
)
,
temp
}
func
getAuthorization
(
body
string
)
(
string
,
error
)
{
...
...
@@ -595,7 +639,7 @@ func BillPayStateFail(billID int64) error {
//InsertPayBill is 插入 支付订单表中
func
InsertPayBill
(
p
*
models
.
PlaceAnOrderParamInput
,
orderID
string
)
(
int64
,
error
)
{
func
InsertPayBill
(
tx
*
sql
.
Tx
,
p
*
models
.
PlaceAnOrderParamInput
,
orderID
string
)
(
int64
,
error
)
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
@@ -622,7 +666,7 @@ commodity_detail = ?, attach = ?, notify_pay_url = ?, pay_type = ?, is_serve = ?
}
// InsertPayBillDetailRequestBody is 插入支付订单详情表中的 下单参数字段 request_body
func
InsertPayBillDetailRequestBody
(
billID
int64
,
requestBody
interface
{})
error
{
func
InsertPayBillDetailRequestBody
(
tx
*
sql
.
Tx
,
billID
int64
,
requestBody
interface
{})
error
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
@@ -647,7 +691,7 @@ func InsertPayBillDetailRequestBody(billID int64, requestBody interface{}) error
}
// InsertPayBillDetailResponseBody is 插入支付订单详情表中的 下单参数字段 response_body
func
InsertPayBillDetailResponseBody
(
billID
int64
,
responseBody
interface
{})
error
{
func
InsertPayBillDetailResponseBody
(
tx
*
sql
.
Tx
,
billID
int64
,
responseBody
interface
{})
error
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
@@ -671,7 +715,7 @@ func InsertPayBillDetailResponseBody(billID int64, responseBody interface{}) err
return
nil
}
func
InsertPayBillDetailResponseBodyString
(
billID
int64
,
responseBody
string
)
error
{
func
InsertPayBillDetailResponseBodyString
(
tx
*
sql
.
Tx
,
billID
int64
,
responseBody
string
)
error
{
db
,
err
:=
mysql
.
NewShopConn
()
if
err
!=
nil
{
...
...
@@ -690,3 +734,14 @@ func InsertPayBillDetailResponseBodyString(billID int64, responseBody string) er
}
return
nil
}
func
GetUID
()
string
{
u4
:=
uID
.
NewV4
()
//if err != nil {
// return ""
//}
id
:=
fmt
.
Sprintf
(
"%s"
,
u4
)
return
strings
.
Replace
(
id
,
"-"
,
""
,
-
1
)
}
\ No newline at end of file
router/v1/pay_router.go
View file @
13ef1742
...
...
@@ -12,5 +12,8 @@ func PayRouter (r *gin.Engine) {
// 卡拉卡统一支付
r
.
POST
(
pack
.
PayUrlPacking
(
"unified_order"
),
PayController
.
UnifiedOrder
)
// 卡拉卡统一支付回调
r
.
POST
(
pack
.
PayUrlPacking
(
"wx_notice"
),
PayController
.
WxNotice
)
}
utils/mysql.go
0 → 100644
View file @
13ef1742
package
utils
import
(
"database/sql"
"github.com/astaxie/beego"
// import mysql
_
"github.com/go-sql-driver/mysql"
)
var
(
db
*
sql
.
DB
err
error
)
// NewPayConn is 连接支付库
func
NewPayConn
()
(
*
sql
.
DB
,
error
)
{
if
db
==
nil
{
db
,
err
=
sql
.
Open
(
"mysql"
,
beego
.
AppConfig
.
String
(
"PayURL"
))
return
db
,
err
}
return
db
,
nil
}
// GetResultRow is 获取返回值, 获取一条
//func GetResultRow(rows *sql.Rows) map[string]string {
// columns, _ := rows.Columns()
// scanArgs := make([]interface{}, len(columns))
// values := make([][]byte, len(columns))
// for j := range values {
// scanArgs[j] = &values[j]
// }
// record := make(map[string]string)
// for rows.Next() {
// rows.Scan(scanArgs...)
// for i, v := range values {
// if v != nil {
// record[columns[i]] = string(v)
// }
// }
// }
// return record
//}
// GetResultRows is 获取所有
//func GetResultRows(rows *sql.Rows) map[int]map[string]string {
// columns, _ := rows.Columns()
// values := make([][]byte, len(columns))
// scans := make([]interface{}, len(columns))
// for k, _ := range values {
// scans[k] = &values[k]
// }
// i := 0
// result := make(map[int]map[string]string)
// for rows.Next() {
// rows.Scan(scans...)
// row := make(map[string]string)
// for k, v := range values {
// key := columns[k]
// row[key] = string(v)
// }
// result[i] = row
// i++
// }
// return result
//}
// CloseTx is 有错误则关闭事务、没错则提交事务
func
CloseTx
(
tx
*
sql
.
Tx
,
err
error
)
{
if
err
!=
nil
{
tx
.
Rollback
()
}
tx
.
Commit
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment