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
1f52298a
Commit
1f52298a
authored
Jul 21, 2023
by
wangp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lakala
parent
71412710
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
114 deletions
+74
-114
config.yaml
conf/dev/config.yaml
+1
-1
config.yaml
conf/prod/config.yaml
+2
-2
pay.go
models/pay.go
+3
-2
pay.go
repository/pay/pay.go
+67
-108
setting.go
setting/setting.go
+1
-1
No files found.
conf/dev/config.yaml
View file @
1f52298a
...
...
@@ -74,7 +74,7 @@ lakala:
#必康自营
bk_path_private_key
:
'
./cert/dev/OP00000003_private_key.pem'
#私钥
bk_path_cert
:
'
./cert/dev/lkl-apigw-v2.cer'
#证书
#
SAAS
#
必康医生
saas_path_private_key
:
'
./cert/dev/OP00000003_private_key.pem'
#私钥
saas_path_cert
:
'
./cert/dev/lkl-apigw-v2.cer'
#证书
...
...
conf/prod/config.yaml
View file @
1f52298a
...
...
@@ -51,7 +51,7 @@ payurl:
lakala
:
#通用
version
:
'
1.0'
# appid: 'OP00000836' #
SAAS
# appid: 'OP00000836' #
必康医生
# appid名称: '机构-羿律必康(天津)网络科技有限公司'
# serial_no: '1686711293777'
# serial_no: '0188b7d3d751'
...
...
@@ -89,7 +89,7 @@ lakala:
#必康自营
bk_path_private_key
:
'
./cert/prod/bk/api_private_key.pem'
#私钥
bk_path_cert
:
'
./cert/prod/bk/lkl-apigw-v1.cer'
#证书
#
SAAS
#
必康医生
saas_path_private_key
:
'
./cert/prod/saas/api_private_key.pem'
#私钥
saas_path_cert
:
'
./cert/prod/saas/lkl-apigw-v1.cer'
#证书
...
...
models/pay.go
View file @
1f52298a
...
...
@@ -30,8 +30,9 @@ type PlaceAnOrderParamInput struct {
//退款
type
RefundParamInput
struct
{
OrderId
string
`json:"order_id" description:"随机生成的订单号 商户订单号"`
GoodsPrice
float64
`json:"goods_price" description:"商品金额,个位为分"`
RefundNo
string
`json:"refund_no" description:"退款号:原对账单流水号"`
RefundAmount
float64
`json:"refund_amount" description:"退款金额,个位为分"`
RefundReason
string
`json:"refund_reason" description:"退款原因"`
}
type
LakalaParamInput
struct
{
...
...
repository/pay/pay.go
View file @
1f52298a
...
...
@@ -4,7 +4,6 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"database/sql"
"encoding/base64"
...
...
@@ -380,15 +379,6 @@ func getAuthorization(platform_type uint8, body string) (string, error) {
//fmt.Println("签名1:", signature)
// 谛宝多多自营
//dbc_path_private_key := setting.Conf.Lakala.DbcPathPrivateKey
//dbc_path_cert := setting.Conf.Lakala.DbcPathCert
//// 必康自营
//bk_path_private_key := setting.Conf.Lakala.BkPathPrivateKey
//bk_path_cert := setting.Conf.Lakala.BkPathCert
//// SAAS
//saas_path_private_key: './cert/prod/saas/api_private_key.pem' #私钥
//saas_path_cert: './cert/prod/saas/lkl-apigw-v1.cer' #证书
var
path_private_key
string
//私钥文件地址
//平台类型 1:saas 2:shop 3:shop mobile 4:收银台 6:bk_shop 7:bk_shop_mobile
if
platform_type
==
2
||
platform_type
==
3
{
...
...
@@ -398,7 +388,7 @@ func getAuthorization(platform_type uint8, body string) (string, error) {
// 必康自营
path_private_key
=
setting
.
Conf
.
Lakala
.
BkPathPrivateKey
}
else
{
//
SAAS
//
必康医生
path_private_key
=
setting
.
Conf
.
Lakala
.
SaasPathPrivateKey
}
//todo 退款时,证书???
...
...
@@ -418,104 +408,72 @@ func getAuthorization(platform_type uint8, body string) (string, error) {
return
authorization
,
nil
}
func
Sha256WithRsa
(
privateRaw
string
,
msg
string
)
(
string
,
error
)
{
privateRaw
=
strings
.
Trim
(
privateRaw
,
"
\n
"
)
if
!
strings
.
HasPrefix
(
privateRaw
,
"-----BEGIN RSA PRIVATE KEY-----"
)
{
privateRaw
=
fmt
.
Sprintf
(
"%s
\n
%s
\n
%s"
,
"-----BEGIN RSA PRIVATE KEY-----"
,
privateRaw
,
"-----END RSA PRIVATE KEY-----"
)
}
//fmt.Println(privateRaw)
blockPri
,
_
:=
pem
.
Decode
([]
byte
(
privateRaw
))
if
blockPri
==
nil
{
return
""
,
fmt
.
Errorf
(
"blockPri is nil"
)
}
rsaPri
,
e
:=
genPriKey
(
blockPri
.
Bytes
,
PKCS8
)
if
e
!=
nil
{
panic
(
e
)
}
h
:=
sha256
.
New
()
h
.
Write
([]
byte
(
msg
))
d
:=
h
.
Sum
(
nil
)
signature
,
err
:=
rsa
.
SignPKCS1v15
(
rand
.
Reader
,
rsaPri
,
crypto
.
SHA256
,
d
)
if
err
!=
nil
{
//return "", errorx.Wrap(err)
return
""
,
err
}
encodedSig
:=
base64
.
StdEncoding
.
EncodeToString
(
signature
)
return
encodedSig
,
nil
}
const
(
PKCS1
int64
=
iota
PKCS8
)
func
genPriKey
(
privateKey
[]
byte
,
privateKeyType
int64
)
(
*
rsa
.
PrivateKey
,
error
)
{
var
priKey
*
rsa
.
PrivateKey
var
err
error
switch
privateKeyType
{
case
PKCS1
:
{
priKey
,
err
=
x509
.
ParsePKCS1PrivateKey
([]
byte
(
privateKey
))
if
err
!=
nil
{
return
nil
,
err
}
}
case
PKCS8
:
{
prkI
,
err
:=
x509
.
ParsePKCS8PrivateKey
([]
byte
(
privateKey
))
if
err
!=
nil
{
return
nil
,
err
}
priKey
=
prkI
.
(
*
rsa
.
PrivateKey
)
}
default
:
{
return
nil
,
fmt
.
Errorf
(
"unsupport private key type"
)
}
}
return
priKey
,
nil
}
//
func Sha256WithRsa(privateRaw string, msg string) (string, error) {
//
privateRaw = strings.Trim(privateRaw, "\n")
//
if !strings.HasPrefix(privateRaw, "-----BEGIN RSA PRIVATE KEY-----") {
//
privateRaw = fmt.Sprintf("%s\n%s\n%s", "-----BEGIN RSA PRIVATE KEY-----", privateRaw, "-----END RSA PRIVATE KEY-----")
//
}
//
//fmt.Println(privateRaw)
//
blockPri, _ := pem.Decode([]byte(privateRaw))
//
if blockPri == nil {
//
return "", fmt.Errorf("blockPri is nil")
//
}
//
//
rsaPri, e := genPriKey(blockPri.Bytes, PKCS8)
//
if e != nil {
//
panic(e)
//
}
//
//
h := sha256.New()
//
h.Write([]byte(msg))
//
d := h.Sum(nil)
//
//
signature, err := rsa.SignPKCS1v15(rand.Reader, rsaPri, crypto.SHA256, d)
//
if err != nil {
//
//return "", errorx.Wrap(err)
//
return "", err
//
}
//
encodedSig := base64.StdEncoding.EncodeToString(signature)
//
return encodedSig, nil
//
}
//
const (
//
PKCS1 int64 = iota
//
PKCS8
//
)
//
//
func genPriKey(privateKey []byte, privateKeyType int64) (*rsa.PrivateKey, error) {
//
var priKey *rsa.PrivateKey
//
var err error
//
switch privateKeyType {
//
case PKCS1:
//
{
//
priKey, err = x509.ParsePKCS1PrivateKey([]byte(privateKey))
//
if err != nil {
//
return nil, err
//
}
//
}
//
case PKCS8:
//
{
//
prkI, err := x509.ParsePKCS8PrivateKey([]byte(privateKey))
//
if err != nil {
//
return nil, err
//
}
//
priKey = prkI.(*rsa.PrivateKey)
//
}
//
default:
//
{
//
return nil, fmt.Errorf("unsupport private key type")
//
}
//
}
//
return priKey, nil
//
}
// GetNoticeURL is 获取回调地址
func
GetNoticeURL
(
sourceCode
uint8
)
string
{
//domainName := beego.AppConfig.String("DomainName")
domainName
:=
setting
.
Conf
.
PayUrl
.
DomainName
//domainName = "http://tpay-v2.pet-dbc.cn:14880";
return
domainName
+
"/api/v1/pay/wx_notice"
//目前微信、支付宝调同一个地址
//// <= 5 是微信
//if sourceCode < 5 {
// return domainName + "/api/v1/pay/wx_notice"
//}
//
//// > 5 是支付宝
//return domainName + "/api/v1/pay/alipay_notice"
//
//if isServe == 0 {
// // payType 1: 原生 2: paymax
// if payType == 1 {
//
// // <= 5 是微信 > 5 是支付宝
// if sourceCode < 5 {
// return domainName + "/v1/notice/wx"
// }
//
// return domainName + "/v1/notice/ali"
// }
//
// return domainName + "/v1/notice/paymax"
//}
//
//// <= 5 是微信 > 5 是支付宝
//if sourceCode < 5 {
// return domainName + "/v1/notice/serve_wx"
//}
//
//return domainName + "/v1/notice/serve_ali"
}
// BillPayStateSuccess is 微信回调后 把订单状态 置为结算成功
...
...
@@ -566,7 +524,7 @@ func InsertRefundBill(tx *sql.Tx, p *models.RefundParamInput, refundID string) (
insertSQL
:=
`insert system_pay_bill set original_payment_order_code=?, payment_order_code=?, paymoney=?*1000, pay_type=4, _type=1`
//platformType, sourceCode, checkSn, refundAmount, attach, orderID
result
,
err
:=
tx
.
Exec
(
insertSQL
,
p
.
OrderId
,
refundID
,
p
.
GoodsPrice
)
result
,
err
:=
tx
.
Exec
(
insertSQL
,
p
.
RefundNo
,
refundID
,
p
.
RefundAmount
)
if
err
!=
nil
{
return
billID
,
err
}
...
...
@@ -760,8 +718,8 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro
//扫码支付授权码,设备读取用户APP中的条码或者二维码信息,用户付款码条形码规则见说明
//data2["auth_code"] = "135178236713755038"
//data2["auth_code"] = input.DynamicID
data2
[
"refund_amount"
]
=
input
.
GoodsPrice
*
100
//退款金额
data2
[
"refund_reason"
]
=
""
//退款原因
data2
[
"refund_amount"
]
=
input
.
RefundAmount
*
100
//退款金额
data2
[
"refund_reason"
]
=
input
.
RefundReason
//退款原因
//input.OrderId = "2023070566210308960791"
//data2["origin_out_trade_no"] = input.OrderId //原商户交易流水号
...
...
@@ -832,7 +790,7 @@ func selectPayBill(tx *sql.Tx, input *models.RefundParamInput) (string, string,
from system_pay_bill b
left join system_pay_bill_detail bd on b.id=bd.pay_bill_id
where b._type=0 and b.payment_order_code=?`
err
:=
tx
.
QueryRow
(
selectPayBillDetailSQL
,
input
.
OrderId
)
.
Scan
(
&
billID
,
&
status
,
&
source_code
,
&
notice_request2
)
err
:=
tx
.
QueryRow
(
selectPayBillDetailSQL
,
input
.
RefundNo
)
.
Scan
(
&
billID
,
&
status
,
&
source_code
,
&
notice_request2
)
if
err
!=
nil
{
return
""
,
""
,
0
,
err
}
...
...
@@ -854,10 +812,11 @@ func selectPayBill(tx *sql.Tx, input *models.RefundParamInput) (string, string,
}
if
source_code
==
0
{
return
""
,
""
,
0
,
errors
.
New
(
"「source_code」错误,有效值为[1-6,9]"
)
return
""
,
""
,
0
,
errors
.
New
(
"「source_code」错误,有效值为[1-6,9
,15
]"
)
}
// 获取「对账单流水号」和「交易终端号」,退款用
// 针对有的支付,不需要传「交易终端号」时,需要用支付返回的「交易终端号」进行退款
log_no
:=
notice_request
.
OrderTradeInfo
.
(
map
[
string
]
interface
{})[
"log_no"
]
.
(
string
)
if
log_no
==
""
{
return
""
,
""
,
0
,
errors
.
New
(
"「对账单流水号」未取得错误"
)
...
...
setting/setting.go
View file @
1f52298a
...
...
@@ -84,7 +84,7 @@ type Lakala struct {
// 必康自营
BkPathPrivateKey
string
`mapstructure:"bk_path_private_key"`
//私钥
BkPathCert
string
`mapstructure:"bk_path_cert"`
//证书
//
SAAS
//
必康医生
SaasPathPrivateKey
string
`mapstructure:"saas_path_private_key"`
//私钥
SaasPathCert
string
`mapstructure:"saas_path_cert"`
//证书
// 拉卡拉接口地址
...
...
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