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
9bfde828
Commit
9bfde828
authored
Jul 18, 2023
by
wangp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lakala
parent
1dd7c9e0
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
129 deletions
+122
-129
Dockerfile
Dockerfile
+2
-2
config.yaml
conf/dev/config.yaml
+8
-8
config.yaml
conf/prod/config.yaml
+14
-12
notice.go
controller/api/v1/pay/notice.go
+48
-56
main.go
main.go
+6
-7
redis.go
redis/redis.go
+34
-34
setting.go
setting/setting.go
+10
-10
No files found.
Dockerfile
View file @
9bfde828
...
...
@@ -34,8 +34,8 @@ WORKDIR /go/src/system_pay
COPY
--from=0 /go/src/system_pay/server ./
# 拷贝配置文件到当前工作目录
#
COPY --from=0 /go/src/system_pay/conf/dev ./conf
COPY
--from=0 /go/src/system_pay/conf/prod ./conf
COPY
--from=0 /go/src/system_pay/conf/dev ./conf
#
COPY --from=0 /go/src/system_pay/conf/prod ./conf
# 拷贝国际化文件夹到当前工作目录
COPY
--from=0 /go/src/system_pay/i18n ./i18n
...
...
conf/dev/config.yaml
View file @
9bfde828
...
...
@@ -30,12 +30,12 @@ database:
# dbname: "test_food"
# redis
redis
:
host
:
'
39.96.85.45'
port
:
6382
password
:
'
saas123456'
db
:
0
pool_size
:
200
#
redis:
#
host: '39.96.85.45'
#
port: 6382
#
password: 'saas123456'
#
db: 0
#
pool_size: 200
# mongo
...
...
@@ -59,8 +59,8 @@ log:
# smscontent: '【谛宝医生】登录验证码为:%s'
# 支付
#
payurl:
#
domainname: 'http://tpay-v2.pet-dbc.cn:14880'
payurl
:
domainname
:
'
http://tpay-v2.pet-dbc.cn:14880'
# checkorder: 'https://tpay.pet-dbc.cn/v1/pay/unified_order'
# orderstate: 'https://tpay.pet-dbc.cn/v1/pay/order_state/'
...
...
conf/prod/config.yaml
View file @
9bfde828
...
...
@@ -32,12 +32,12 @@ database:
# dbname: "test_food"
# redis
redis
:
host
:
'
39.97.179.15'
port
:
6382
password
:
'
saas123456'
db
:
0
pool_size
:
200
#
redis:
#
host: '39.97.179.15'
#
port: 6382
#
password: 'saas123456'
#
db: 0
#
pool_size: 200
# mongo
...
...
@@ -62,8 +62,8 @@ sms:
smscontent
:
'
【谛宝多多】登录验证码为:%s'
# 支付
#
payurl:
#
domainname: 'http://tpay-v2.pet-dbc.cn:14880'
payurl
:
domainname
:
'
http://tpay-v2.pet-dbc.cn:14880'
# checkorder: 'https://pay.pet-dbc.cn/v1/pay/unified_order'
# orderstate: 'https://pay.pet-dbc.cn/v1/pay/order_state/'
...
...
@@ -74,16 +74,18 @@ lakala:
version
:
'
1.0'
# appid: 'OP00000836' #SAAS
# appid名称: '机构-羿律必康(天津)网络科技有限公司'
# serial_no: '0188b7d3d751'
# serial_no: '1686711293777'
# serial_no: '0188b7d3d751'
appid
:
'
OP00000859'
#谛宝多多自营
appid名称
:
'
商户-谛宝诚网络科技(北京)有限公司'
serial_no
:
'
1689571622248'
# 'APPLET_APPID' =>'wx6ff40a576e2f4ca0', //谛宝多多小程序
# merchant_no=822100058221000599501K999501K9 ?
# appid: '' #必康自营
# appid名称: ''
# serial_no: ''
# serial_no: '
1689571807509
'
#1.聚合收银台(微信H5、支付宝H5)
merchant_no1
:
'
8222900701107M5'
...
...
@@ -94,8 +96,8 @@ lakala:
#3.聚合主扫(微信JSAPI、微信小程序)
merchant_no3
:
'
8222900581201QB'
term_no3
:
'
D0027598'
sub_appid3
:
'
wxc3e4d1682da3053c'
user_id3
:
'
oLvoQ5deygCMj2WrDjPVPvV1L1t8'
sub_appid3
:
'
wxc3e4d1682da3053c'
#子商户公众账号ID
user_id3
:
'
oLvoQ5deygCMj2WrDjPVPvV1L1t8'
#用户标识(sub_openid)
#4.聚合被扫(扫码枪)
merchant_no4
:
'
822290070111135'
#结算商户号
term_no4
:
'
29034705'
#结算终端号
...
...
controller/api/v1/pay/notice.go
View file @
9bfde828
package
pay
import
(
"crypto"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"system_pay/controller/base"
"system_pay/models"
"system_pay/repository/pay"
...
...
@@ -108,54 +100,54 @@ func (l *PayController) WxNotice(c *gin.Context) {
// return errors.New("wangpei签名测试中。。。。。")
//}
func
verySignByPublicKey
(
c
*
gin
.
Context
)
(
bool
,
error
)
{
//publicKey string, data []byte, signData []byte
//String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING);
appid
:=
c
.
GetHeader
(
"Lklapi-Appid"
)
lklapiSerial
:=
c
.
GetHeader
(
"Lklapi-Serial"
)
timestamp
:=
c
.
GetHeader
(
"Lklapi-Timestamp"
)
nonce
:=
c
.
GetHeader
(
"Lklapi-Nonce"
)
signature
:=
c
.
GetHeader
(
"Lklapi-Signature"
)
responseStr
:=
c
.
GetHeader
(
""
)
data
:=
appid
+
"
\n
"
+
lklapiSerial
+
"
\n
"
+
timestamp
+
"
\n
"
+
nonce
+
"
\n
"
+
responseStr
+
"
\n
"
;
fmt
.
Println
(
"verySignByPublicKey start..."
)
fmt
.
Println
(
data
)
fmt
.
Println
(
"signature="
+
signature
)
// 1、读取公钥文件,获取公钥字节
//path_cert := setting.Conf.Lakala.BkPathCert
publicKey
,
err
:=
ioutil
.
ReadFile
(
"./cert/dev/lkl-apigw-v2.cer"
)
if
err
!=
nil
{
return
false
,
err
}
// 2、解码私钥字节,生成加密对象
block
,
_
:=
pem
.
Decode
(
publicKey
)
if
block
==
nil
{
return
false
,
errors
.
New
(
"私钥信息错误!"
)
}
// 3、解析DER编码的私钥,生成私钥对象
pubKey
,
err
:=
x509
.
ParsePKIXPublicKey
(
block
.
Bytes
)
if
err
!=
nil
{
return
false
,
err
}
hashed
:=
sha256
.
Sum256
([]
byte
(
data
))
fmt
.
Println
(
"pubKey.(*rsa.PublicKey): "
,
pubKey
.
(
*
rsa
.
PublicKey
))
pubK
:=
pubKey
.
(
*
rsa
.
PublicKey
)
sig
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
signature
)
err
=
rsa
.
VerifyPKCS1v15
(
pubK
,
crypto
.
SHA256
,
hashed
[
:
],
sig
)
if
err
!=
nil
{
return
false
,
err
}
return
true
,
nil
}
//
func verySignByPublicKey(c *gin.Context) (bool, error) {
//
//
//publicKey string, data []byte, signData []byte
//
//String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING);
//
appid := c.GetHeader("Lklapi-Appid")
//
lklapiSerial := c.GetHeader("Lklapi-Serial")
//
timestamp := c.GetHeader("Lklapi-Timestamp")
//
nonce := c.GetHeader("Lklapi-Nonce")
//
signature := c.GetHeader("Lklapi-Signature")
//
responseStr := c.GetHeader("")
//
//
data := appid + "\n" + lklapiSerial + "\n" + timestamp + "\n" + nonce + "\n" + responseStr + "\n";
//
fmt.Println("verySignByPublicKey start...")
//
fmt.Println(data)
//
fmt.Println("signature="+signature)
//
//
// 1、读取公钥文件,获取公钥字节
//
//path_cert := setting.Conf.Lakala.BkPathCert
//
publicKey, err := ioutil.ReadFile("./cert/dev/lkl-apigw-v2.cer")
//
if err != nil {
//
return false, err
//
}
//
// 2、解码私钥字节,生成加密对象
//
block, _ := pem.Decode(publicKey)
//
if block == nil {
//
return false, errors.New("私钥信息错误!")
//
}
//
// 3、解析DER编码的私钥,生成私钥对象
//
pubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
//
if err != nil {
//
return false, err
//
}
//
//
hashed := sha256.Sum256([]byte(data))
//
//
fmt.Println("pubKey.(*rsa.PublicKey): ", pubKey.(*rsa.PublicKey))
//
//
pubK := pubKey.(*rsa.PublicKey)
//
//
sig, err := base64.StdEncoding.DecodeString(signature)
//
//
err = rsa.VerifyPKCS1v15(pubK, crypto.SHA256, hashed[:], sig)
//
if err != nil {
//
return false, err
//
}
//
//
return true, nil
//
}
//const (
// PEM_BEGIN = "-----BEGIN RSA PRIVATE KEY-----\n"
...
...
main.go
View file @
9bfde828
...
...
@@ -9,7 +9,6 @@ import (
"os/exec"
_
"system_pay/docs"
logger
"system_pay/pkg/logging"
"system_pay/redis"
routers
"system_pay/router"
"system_pay/setting"
)
...
...
@@ -50,13 +49,13 @@ func main() {
}
// redis
if
err
:=
redis
.
Init
(
setting
.
Conf
.
Redis
);
err
!=
nil
{
panic
(
"init redis failed, new_error:"
+
err
.
Error
())
//fmt.Printf("init redis failed, new_error:%v\n", new_error)
//return
}
//
if err := redis.Init(setting.Conf.Redis); err != nil {
//
panic("init redis failed, new_error:"+ err.Error())
//
//fmt.Printf("init redis failed, new_error:%v\n", new_error)
//
//return
//
}
// 关闭项目时候关闭redis连接
defer
redis
.
Close
()
//
defer redis.Close()
// mongo
//MongoDB, err := mongo.ConnectToMongoDB()
...
...
redis/redis.go
View file @
9bfde828
package
redis
import
(
"fmt"
"github.com/go-redis/redis"
"system_pay/setting"
)
var
(
Redisclient
*
redis
.
Client
Nil
=
redis
.
Nil
)
// Init 初始化连接
func
Init
(
cfg
*
setting
.
RedisConfig
)
(
err
error
)
{
Redisclient
=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
fmt
.
Sprintf
(
"%s:%d"
,
cfg
.
Host
,
cfg
.
Port
),
Password
:
cfg
.
Password
,
// no password set
DB
:
cfg
.
DB
,
// use default DB
PoolSize
:
cfg
.
PoolSize
,
MinIdleConns
:
cfg
.
MinIdleConns
,
})
_
,
err
=
Redisclient
.
Ping
()
.
Result
()
if
err
!=
nil
{
return
err
}
return
err
}
func
Close
()
{
_
=
Redisclient
.
Close
()
}
//
//
import (
//
"fmt"
//
"github.com/go-redis/redis"
//
"system_pay/setting"
//
)
//
//
var (
//
Redisclient *redis.Client
//
Nil = redis.Nil
//
)
//
//
//
Init 初始化连接
//
func Init(cfg *setting.RedisConfig) (err error) {
//
//
Redisclient = redis.NewClient(&redis.Options{
//
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
//
Password: cfg.Password, // no password set
//
DB: cfg.DB, // use default DB
//
PoolSize: cfg.PoolSize,
//
MinIdleConns: cfg.MinIdleConns,
//
})
//
//
//
_, err = Redisclient.Ping().Result()
//
if err != nil {
//
return err
//
}
//
return err
//
}
//
//
func Close() {
//
_ = Redisclient.Close()
//
}
setting/setting.go
View file @
9bfde828
...
...
@@ -15,7 +15,7 @@ type Config struct {
ServerSetting
*
Server
`mapstructure:"server"`
AppSetting
*
App
`mapstructure:"app"`
DatabaseSetting
*
Database
`mapstructure:"database"`
Redis
*
RedisConfig
`mapstructure:"redis"`
//
Redis *RedisConfig `mapstructure:"redis"`
LogSetting
*
Log
`mapstructure:"log"`
Sms
*
SmsInternationalConfig
`mapstructure:"sms"`
UploadImage
*
UploadImage
`mapstructure:"uploadimage"`
...
...
@@ -75,14 +75,14 @@ type Database struct {
}
// RedisConfig redis
type
RedisConfig
struct
{
Host
string
`mapstructure:"host"`
Password
string
`mapstructure:"password"`
Port
int
`mapstructure:"port"`
DB
int
`mapstructure:"db"`
PoolSize
int
`mapstructure:"pool_size"`
MinIdleConns
int
`mapstructure:"min_idle_conns"`
}
//
type RedisConfig struct {
//
Host string `mapstructure:"host"`
//
Password string `mapstructure:"password"`
//
Port int `mapstructure:"port"`
//
DB int `mapstructure:"db"`
//
PoolSize int `mapstructure:"pool_size"`
//
MinIdleConns int `mapstructure:"min_idle_conns"`
//
}
// MongoConfig mongo设置
//type MongoConfig struct {
...
...
@@ -185,7 +185,7 @@ type Esign struct {
// Init 支持热修改的viper设置
func
Init
()
error
{
viper
.
SetConfigFile
(
"conf/config.yaml"
)
// 指定配置文件路径
viper
.
SetConfigFile
(
"conf/
dev/
config.yaml"
)
// 指定配置文件路径
err
:=
viper
.
ReadInConfig
()
// 读取配置信息
if
err
!=
nil
{
// 读取配置信息失败
fmt
.
Printf
(
"viper.ReadInConfig failed, new_error:%v
\n
"
,
err
)
...
...
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