Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
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
zhengqiuyun
rym-util
Commits
dc7cf41f
Commit
dc7cf41f
authored
Aug 08, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
b0fa14c1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
66 additions
and
229 deletions
+66
-229
DcLogger.go
DcLogger.go
+6
-7
GlobalException.go
a/exception/GlobalException.go
+3
-3
generate.go
a/generate/generate.go
+5
-5
Request.go
a/getWay/Request.go
+13
-13
Response.go
a/getWay/Response.go
+11
-12
allinpay.go
a/lib/allinpay/allinpay.go
+5
-5
main.go
a/lib/allinpay/main/main.go
+22
-22
Const.go
a/log/es/Const.go
+0
-3
EsDb.go
a/log/es/EsDb.go
+0
-31
EsLogger.go
a/log/es/EsLogger.go
+0
-127
conf.go
conf.go
+1
-1
No files found.
a/log/
DcLogger.go
→
DcLogger.go
View file @
dc7cf41f
package
log
package
rym_util
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"gorm.io/gorm/logger"
"gorm.io/gorm/logger"
"runtime"
"runtime"
"strconv"
"strconv"
...
@@ -25,7 +24,7 @@ func DebugDo(f func()) {
...
@@ -25,7 +24,7 @@ func DebugDo(f func()) {
func
IsDebug
()
bool
{
func
IsDebug
()
bool
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
case
strings
.
ToLower
(
DebugL
)
:
ok
=
true
ok
=
true
break
break
...
@@ -35,7 +34,7 @@ func IsDebug() bool {
...
@@ -35,7 +34,7 @@ func IsDebug() bool {
func
Debug
(
msg
string
)
{
func
Debug
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
case
strings
.
ToLower
(
DebugL
)
:
ok
=
true
ok
=
true
break
break
...
@@ -48,7 +47,7 @@ func Debug(msg string) {
...
@@ -48,7 +47,7 @@ func Debug(msg string) {
func
Info
(
msg
string
)
{
func
Info
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
case
strings
.
ToLower
(
DebugL
)
:
ok
=
true
ok
=
true
break
break
...
@@ -64,7 +63,7 @@ func Info(msg string) {
...
@@ -64,7 +63,7 @@ func Info(msg string) {
func
Error
(
msg
string
)
{
func
Error
(
msg
string
)
{
ok
:=
false
ok
:=
false
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
case
strings
.
ToLower
(
DebugL
)
:
ok
=
true
ok
=
true
break
break
...
@@ -83,7 +82,7 @@ func Error(msg string) {
...
@@ -83,7 +82,7 @@ func Error(msg string) {
func
mark
(
tag
,
msg
string
,
file
string
,
line
int
)
{
func
mark
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
str
:=
"%s %s [%d] %s %d %s"
if
conf
.
LogColorful
{
if
LogColorful
{
if
tag
==
"Error"
{
if
tag
==
"Error"
{
str
=
"%s %s [%d] %s %d "
+
logger
.
Red
+
"%s"
+
logger
.
Reset
str
=
"%s %s [%d] %s %d "
+
logger
.
Red
+
"%s"
+
logger
.
Reset
}
else
if
tag
==
"Info"
{
}
else
if
tag
==
"Info"
{
...
...
a/exception/GlobalException.go
View file @
dc7cf41f
...
@@ -2,14 +2,14 @@ package exception
...
@@ -2,14 +2,14 @@ package exception
import
(
import
(
"errors"
"errors"
"git.168cad.top/zhengqiuyun/rym-util
/a/log
"
"git.168cad.top/zhengqiuyun/rym-util"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10"
"reflect"
"reflect"
)
)
func
ThrowsErr
(
err
error
)
{
func
ThrowsErr
(
err
error
)
{
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
rym_util
.
Error
(
err
.
Error
())
panic
(
err
)
panic
(
err
)
}
}
}
}
...
@@ -57,7 +57,7 @@ func (e *DError) Error() string {
...
@@ -57,7 +57,7 @@ func (e *DError) Error() string {
}
}
func
ThrowsErrS
(
err
string
)
{
func
ThrowsErrS
(
err
string
)
{
if
&
err
!=
nil
&&
err
!=
""
{
if
&
err
!=
nil
&&
err
!=
""
{
log
.
Error
(
err
)
rym_util
.
Error
(
err
)
panic
(
DError
{
Err
:
err
})
panic
(
DError
{
Err
:
err
})
}
}
}
}
a/generate/generate.go
View file @
dc7cf41f
...
@@ -2,7 +2,7 @@ package generate
...
@@ -2,7 +2,7 @@ package generate
import
(
import
(
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util
/a/conf
"
"git.168cad.top/zhengqiuyun/rym-util"
"github.com/deckarep/golang-set"
"github.com/deckarep/golang-set"
"github.com/iancoleman/strcase"
"github.com/iancoleman/strcase"
"io"
"io"
...
@@ -49,7 +49,7 @@ func BuildPgModels() {
...
@@ -49,7 +49,7 @@ func BuildPgModels() {
doTable
,
ok
:=
DoTables
[
table
.
Name
]
doTable
,
ok
:=
DoTables
[
table
.
Name
]
if
ok
{
if
ok
{
var
tableFields
[]
TableField
var
tableFields
[]
TableField
if
conf
.
DBType
==
"PostgreSql"
{
if
rym_util
.
DBType
==
"PostgreSql"
{
tableFields
=
GetTableFiledByTableName
(
table
.
Name
)
tableFields
=
GetTableFiledByTableName
(
table
.
Name
)
}
else
{
}
else
{
tableFields
=
MysqlGetTableFiledByTableName
(
table
.
Name
)
tableFields
=
MysqlGetTableFiledByTableName
(
table
.
Name
)
...
@@ -83,7 +83,7 @@ func getModelImport(field TableField) string {
...
@@ -83,7 +83,7 @@ func getModelImport(field TableField) string {
}
}
func
getModelFiledType
(
field
TableField
)
string
{
func
getModelFiledType
(
field
TableField
)
string
{
if
conf
.
DBType
==
"PostgreSql"
{
if
rym_util
.
DBType
==
"PostgreSql"
{
return
DbToGoPG
[
field
.
FieldType
]
return
DbToGoPG
[
field
.
FieldType
]
}
else
{
}
else
{
if
strings
.
Index
(
field
.
ColumnType
,
"unsigned"
)
>
0
{
if
strings
.
Index
(
field
.
ColumnType
,
"unsigned"
)
>
0
{
...
@@ -294,10 +294,10 @@ func generateDao(table *Table, fields []TableField, doTable TableInfo) {
...
@@ -294,10 +294,10 @@ func generateDao(table *Table, fields []TableField, doTable TableInfo) {
pageQuery
+=
"}
\n
"
pageQuery
+=
"}
\n
"
importStr
:=
"import (
\n
"
importStr
:=
"import (
\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/PagePlus
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/PagePlus
\"\n
"
if
conf
.
DBType
==
""
{
if
rym_util
.
DBType
==
""
{
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db
\"\n
"
}
else
{
}
else
{
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db/"
+
conf
.
DBType
+
"
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db/"
+
rym_util
.
DBType
+
"
\"\n
"
}
}
importStr
+=
"
\t\"
"
+
projectName
+
"/a/exception
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/exception
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/page
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/page
\"\n
"
...
...
a/getWay/Request.go
View file @
dc7cf41f
...
@@ -3,9 +3,9 @@ package getWay
...
@@ -3,9 +3,9 @@ package getWay
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/db/redis"
"git.168cad.top/zhengqiuyun/rym-util/a/db/redis"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"io/ioutil"
"io/ioutil"
"net"
"net"
...
@@ -45,18 +45,18 @@ func GetAdminInfo(token string) Admin {
...
@@ -45,18 +45,18 @@ func GetAdminInfo(token string) Admin {
var
adminResponse
=
AdminResponse
{}
var
adminResponse
=
AdminResponse
{}
resp
,
err
:=
http
.
Get
(
conf
.
SystemHost
+
"/admin/current?token="
+
token
)
resp
,
err
:=
http
.
Get
(
conf
.
SystemHost
+
"/admin/current?token="
+
token
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
rym_util
.
Error
(
err
.
Error
())
return
Admin
{}
return
Admin
{}
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
adminResponseBytes
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
adminResponseBytes
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
rym_util
.
Error
(
err
.
Error
())
return
Admin
{}
return
Admin
{}
}
}
err
=
json
.
Unmarshal
(
adminResponseBytes
,
&
adminResponse
)
err
=
json
.
Unmarshal
(
adminResponseBytes
,
&
adminResponse
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
rym_util
.
Error
(
err
.
Error
())
}
}
return
adminResponse
.
Admin
return
adminResponse
.
Admin
}
}
...
@@ -145,13 +145,13 @@ func ValidRequest(c *gin.Context) {
...
@@ -145,13 +145,13 @@ func ValidRequest(c *gin.Context) {
token
:=
GetToken
(
c
)
token
:=
GetToken
(
c
)
if
token
==
""
{
if
token
==
""
{
if
checkIp
(
ip
)
{
//如果没有token,看是否是ip白名单
if
checkIp
(
ip
)
{
//如果没有token,看是否是ip白名单
log
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验通过:%s"
,
ip
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验通过:%s"
,
ip
))
}
else
{
}
else
{
log
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验不通过:%s"
,
ip
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验不通过:%s"
,
ip
))
if
checkUri
(
url
)
{
//如果不是ip白名单,看是否是url白名单,例如一些第三方的回调
if
checkUri
(
url
)
{
//如果不是ip白名单,看是否是url白名单,例如一些第三方的回调
log
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验通过:%s"
,
url
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验通过:%s"
,
url
))
}
else
{
}
else
{
log
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验不通过:%s"
,
url
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验不通过:%s"
,
url
))
ThrowsGetWayErr
(
Illegal9
)
ThrowsGetWayErr
(
Illegal9
)
}
}
}
}
...
@@ -159,9 +159,9 @@ func ValidRequest(c *gin.Context) {
...
@@ -159,9 +159,9 @@ func ValidRequest(c *gin.Context) {
if
redis
.
Exists
(
token
)
{
//校验token是否有效
if
redis
.
Exists
(
token
)
{
//校验token是否有效
currentUser
:=
GetAdminInfo
(
token
)
currentUser
:=
GetAdminInfo
(
token
)
c
.
Set
(
CurrentUserKey
,
currentUser
)
c
.
Set
(
CurrentUserKey
,
currentUser
)
log
.
Debug
(
fmt
.
Sprintf
(
"登陆校验通过:%s,对应用户id: %d"
,
token
,
currentUser
.
Id
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"登陆校验通过:%s,对应用户id: %d"
,
token
,
currentUser
.
Id
))
}
else
{
}
else
{
log
.
Debug
(
fmt
.
Sprintf
(
"登陆校验不通过:%s"
,
token
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"登陆校验不通过:%s"
,
token
))
ThrowsGetWayErr
(
Expire
)
ThrowsGetWayErr
(
Expire
)
}
}
}
}
...
@@ -180,7 +180,7 @@ func exceptionGetWayCatch(c *gin.Context) {
...
@@ -180,7 +180,7 @@ func exceptionGetWayCatch(c *gin.Context) {
}
}
func
checkUri
(
uri
string
)
bool
{
func
checkUri
(
uri
string
)
bool
{
for
_
,
v
:=
range
conf
.
WhiteListUri
{
for
_
,
v
:=
range
rym_util
.
WhiteListUri
{
if
strings
.
Index
(
uri
,
v
)
==
0
{
if
strings
.
Index
(
uri
,
v
)
==
0
{
return
true
return
true
}
}
...
@@ -189,7 +189,7 @@ func checkUri(uri string) bool {
...
@@ -189,7 +189,7 @@ func checkUri(uri string) bool {
}
}
func
checkIp
(
ip
string
)
bool
{
func
checkIp
(
ip
string
)
bool
{
for
_
,
v
:=
range
conf
.
WhiteListIp
{
for
_
,
v
:=
range
rym_util
.
WhiteListIp
{
if
strings
.
Index
(
ip
,
v
)
==
0
{
if
strings
.
Index
(
ip
,
v
)
==
0
{
return
true
return
true
}
}
...
@@ -198,5 +198,5 @@ func checkIp(ip string) bool {
...
@@ -198,5 +198,5 @@ func checkIp(ip string) bool {
}
}
func
logStart
(
c
*
gin
.
Context
)
{
func
logStart
(
c
*
gin
.
Context
)
{
log
.
Info
(
fmt
.
Sprintf
(
"开始 %s %s %s %s"
,
GetMethod
(
c
),
GetURL
(
c
),
GetToken
(
c
),
GetClientIP
(
c
)))
rym_util
.
Info
(
fmt
.
Sprintf
(
"开始 %s %s %s %s"
,
GetMethod
(
c
),
GetURL
(
c
),
GetToken
(
c
),
GetClientIP
(
c
)))
}
}
a/getWay/Response.go
View file @
dc7cf41f
...
@@ -3,10 +3,9 @@ package getWay
...
@@ -3,10 +3,9 @@ package getWay
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util
/a/conf
"
"git.168cad.top/zhengqiuyun/rym-util"
db
"git.168cad.top/zhengqiuyun/rym-util/a/db/mysql"
db
"git.168cad.top/zhengqiuyun/rym-util/a/db/mysql"
"git.168cad.top/zhengqiuyun/rym-util/a/db/redis"
"git.168cad.top/zhengqiuyun/rym-util/a/db/redis"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"git.168cad.top/zhengqiuyun/rym-util/a/log/es"
"git.168cad.top/zhengqiuyun/rym-util/a/log/es"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -77,7 +76,7 @@ func AliSuccess(c *gin.Context) {
...
@@ -77,7 +76,7 @@ func AliSuccess(c *gin.Context) {
}
}
func
logEnd
(
c
*
gin
.
Context
,
data
interface
{})
{
func
logEnd
(
c
*
gin
.
Context
,
data
interface
{})
{
esSwitch
:=
redis
.
SwitchOpen
(
redis
.
ES日志开关
+
conf
.
ServerName
)
esSwitch
:=
redis
.
SwitchOpen
(
redis
.
ES日志开关
+
rym_util
.
ServerName
)
startTime
:=
GetStartTime
(
c
)
startTime
:=
GetStartTime
(
c
)
endTime
:=
time
.
Now
()
.
UnixNano
()
endTime
:=
time
.
Now
()
.
UnixNano
()
var
responseStr
string
var
responseStr
string
...
@@ -86,14 +85,14 @@ func logEnd(c *gin.Context, data interface{}) {
...
@@ -86,14 +85,14 @@ func logEnd(c *gin.Context, data interface{}) {
rs
:=
string
(
dataJson
)
rs
:=
string
(
dataJson
)
excludeUrl
:=
[]
string
{
""
}
excludeUrl
:=
[]
string
{
""
}
if
esSwitch
{
if
esSwitch
{
if
util
.
ArrayContains
(
excludeUrl
,
GetURL
(
c
))
&&
len
(
rs
)
>
conf
.
LogResponseLength
{
if
util
.
ArrayContains
(
excludeUrl
,
GetURL
(
c
))
&&
len
(
rs
)
>
rym_util
.
LogResponseLength
{
responseStr
=
rs
[
0
:
conf
.
LogResponseLength
]
+
"......"
responseStr
=
rs
[
0
:
rym_util
.
LogResponseLength
]
+
"......"
}
else
{
}
else
{
responseStr
=
rs
responseStr
=
rs
}
}
}
else
{
}
else
{
if
len
(
rs
)
>
conf
.
LogResponseLength
{
if
len
(
rs
)
>
rym_util
.
LogResponseLength
{
responseStr
=
rs
[
0
:
conf
.
LogResponseLength
]
+
"......"
responseStr
=
rs
[
0
:
rym_util
.
LogResponseLength
]
+
"......"
}
else
{
}
else
{
responseStr
=
rs
responseStr
=
rs
}
}
...
@@ -102,18 +101,18 @@ func logEnd(c *gin.Context, data interface{}) {
...
@@ -102,18 +101,18 @@ func logEnd(c *gin.Context, data interface{}) {
token
:=
GetToken
(
c
)
token
:=
GetToken
(
c
)
if
esSwitch
&&
token
!=
""
{
if
esSwitch
&&
token
!=
""
{
esLog
(
c
,
responseStr
)
esLog
(
c
,
responseStr
)
log
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒"
,
(
endTime
-
startTime
)
/
1e6
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒"
,
(
endTime
-
startTime
)
/
1e6
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"返回数据:%s"
,
responseStr
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"返回数据:%s"
,
responseStr
))
log
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒 %s %s %s %s %s"
,
(
endTime
-
startTime
)
/
1e6
,
GetMethod
(
c
),
GetURL
(
c
),
token
,
GetClientIP
(
c
),
GetParams
(
c
)))
rym_util
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒 %s %s %s %s %s"
,
(
endTime
-
startTime
)
/
1e6
,
GetMethod
(
c
),
GetURL
(
c
),
token
,
GetClientIP
(
c
),
GetParams
(
c
)))
}
}
}
}
func
esLog
(
c
*
gin
.
Context
,
response
string
)
{
func
esLog
(
c
*
gin
.
Context
,
response
string
)
{
log
:=
es
.
ServerLogModel
{
log
:=
es
.
ServerLogModel
{
ServerName
:
conf
.
ServerName
,
ServerName
:
rym_util
.
ServerName
,
Env
:
conf
.
ENV
,
Env
:
rym_util
.
ENV
,
TimeStamp
:
util
.
MilSecond
(
time
.
Now
()),
TimeStamp
:
util
.
MilSecond
(
time
.
Now
()),
ThreadNo
:
fmt
.
Sprintf
(
"%d"
,
util
.
GetGID
()),
ThreadNo
:
fmt
.
Sprintf
(
"%d"
,
util
.
GetGID
()),
ServerIp
:
GetServerIP
(),
ServerIp
:
GetServerIP
(),
...
...
a/lib/allinpay/allinpay.go
View file @
dc7cf41f
...
@@ -7,9 +7,9 @@ import (
...
@@ -7,9 +7,9 @@ import (
"encoding/base64"
"encoding/base64"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -53,7 +53,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
...
@@ -53,7 +53,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
requestStr
=
p
.
Encode
()
requestStr
=
p
.
Encode
()
buf
=
strings
.
NewReader
(
requestStr
)
buf
=
strings
.
NewReader
(
requestStr
)
}
}
log
.
Debug
(
fmt
.
Sprintf
(
"请求参数:%s"
,
requestStr
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"请求参数:%s"
,
requestStr
))
req
,
err
:=
http
.
NewRequest
(
method
,
conf
.
AllinpayUrl
,
buf
)
req
,
err
:=
http
.
NewRequest
(
method
,
conf
.
AllinpayUrl
,
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -70,7 +70,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
...
@@ -70,7 +70,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
log
.
Debug
(
fmt
.
Sprintf
(
"请求结果:%s"
,
string
(
data
)))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"请求结果:%s"
,
string
(
data
)))
ok
,
err
:=
verifyData
(
data
,
c
.
tlPublicKey
)
ok
,
err
:=
verifyData
(
data
,
c
.
tlPublicKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -145,7 +145,7 @@ func signWithPKCS1v15(param url.Values, privateKey *rsa.PrivateKey, hash crypto.
...
@@ -145,7 +145,7 @@ func signWithPKCS1v15(param url.Values, privateKey *rsa.PrivateKey, hash crypto.
}
}
sort
.
Strings
(
pList
)
sort
.
Strings
(
pList
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
log
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
md5Str
:=
md5S
(
src
)
md5Str
:=
md5S
(
src
)
sig
,
err
:=
RSASignWithKey
([]
byte
(
md5Str
),
privateKey
,
hash
)
sig
,
err
:=
RSASignWithKey
([]
byte
(
md5Str
),
privateKey
,
hash
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -179,7 +179,7 @@ func (c *Client) getDefaultNotification(data map[string]string, sign string, res
...
@@ -179,7 +179,7 @@ func (c *Client) getDefaultNotification(data map[string]string, sign string, res
}
}
sort
.
Strings
(
pList
)
sort
.
Strings
(
pList
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
log
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
rym_util
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
md5Str
:=
md5B
([]
byte
(
src
))
md5Str
:=
md5B
([]
byte
(
src
))
signBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
sign
)
signBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
sign
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
a/lib/allinpay/main/main.go
View file @
dc7cf41f
...
@@ -2,10 +2,10 @@ package main
...
@@ -2,10 +2,10 @@ package main
import
(
import
(
"fmt"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
lib_allinpay
"git.168cad.top/zhengqiuyun/rym-util/a/lib/allinpay"
lib_allinpay
"git.168cad.top/zhengqiuyun/rym-util/a/lib/allinpay"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"time"
"time"
)
)
...
@@ -46,9 +46,9 @@ func testGetPayeeFundsInTransitDetail() {
...
@@ -46,9 +46,9 @@ func testGetPayeeFundsInTransitDetail() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -69,9 +69,9 @@ func testQueryInExpDetail() {
...
@@ -69,9 +69,9 @@ func testQueryInExpDetail() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -106,7 +106,7 @@ func testCreateMember() {
...
@@ -106,7 +106,7 @@ func testCreateMember() {
if
err
!=
nil
{
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
func
testBindWxOpenId
()
{
func
testBindWxOpenId
()
{
...
@@ -123,7 +123,7 @@ func testBindWxOpenId() {
...
@@ -123,7 +123,7 @@ func testBindWxOpenId() {
if
err
!=
nil
{
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
func
testGetMemberInfo
()
{
func
testGetMemberInfo
()
{
...
@@ -137,7 +137,7 @@ func testGetMemberInfo() {
...
@@ -137,7 +137,7 @@ func testGetMemberInfo() {
if
err
!=
nil
{
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
func
testConsumeApply
()
{
func
testConsumeApply
()
{
...
@@ -176,9 +176,9 @@ func testConsumeApply() {
...
@@ -176,9 +176,9 @@ func testConsumeApply() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
.
PayInfo
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
.
PayInfo
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -196,9 +196,9 @@ func testGetOrderDetail() {
...
@@ -196,9 +196,9 @@ func testGetOrderDetail() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -214,9 +214,9 @@ func testQueryReserveFundBalance() {
...
@@ -214,9 +214,9 @@ func testQueryReserveFundBalance() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -233,9 +233,9 @@ func testQueryBalance() {
...
@@ -233,9 +233,9 @@ func testQueryBalance() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -251,9 +251,9 @@ func testQueryBankCard() {
...
@@ -251,9 +251,9 @@ func testQueryBankCard() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -275,7 +275,7 @@ func testWithDrawApply() {
...
@@ -275,7 +275,7 @@ func testWithDrawApply() {
p
.
BackUrl
=
conf
.
MainHost
+
"/pay/allin/pay/draw/notify"
p
.
BackUrl
=
conf
.
MainHost
+
"/pay/allin/pay/draw/notify"
bankCardNo
:=
"324348812323"
bankCardNo
:=
"324348812323"
encryptBankCardNo
,
err
:=
lib_allinpay
.
AesEncryptECB
(
bankCardNo
,
conf
.
AllinpaySecretKey
)
encryptBankCardNo
,
err
:=
lib_allinpay
.
AesEncryptECB
(
bankCardNo
,
conf
.
AllinpaySecretKey
)
log
.
Info
(
fmt
.
Sprintf
(
"银行卡加密数据:%s"
,
encryptBankCardNo
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"银行卡加密数据:%s"
,
encryptBankCardNo
))
if
err
!=
nil
{
if
err
!=
nil
{
exception
.
ThrowsErrS
(
"通联密钥错误,请检查配置"
)
exception
.
ThrowsErrS
(
"通联密钥错误,请检查配置"
)
}
}
...
@@ -291,9 +291,9 @@ func testWithDrawApply() {
...
@@ -291,9 +291,9 @@ func testWithDrawApply() {
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
}
else
{
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
}
}
...
@@ -315,5 +315,5 @@ func testGetTradeNotification() {
...
@@ -315,5 +315,5 @@ func testGetTradeNotification() {
if
err
!=
nil
{
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
exception
.
ThrowsErr
(
err
)
}
}
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
rd
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
rd
))
}
}
a/log/es/Const.go
deleted
100644 → 0
View file @
b0fa14c1
package
es
const
indexNamePrefix
=
"manage_client_log"
a/log/es/EsDb.go
deleted
100644 → 0
View file @
b0fa14c1
package
es
import
(
"context"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"github.com/olivere/elastic/v7"
_log
"log"
"os"
)
var
Client
*
elastic
.
Client
//初始化
func
init
()
{
host
:=
conf
.
EsHttpHost
var
err
error
errorLog
:=
_log
.
New
(
os
.
Stdout
,
"APP"
,
_log
.
LstdFlags
)
Client
,
err
=
elastic
.
NewClient
(
elastic
.
SetErrorLog
(
errorLog
),
elastic
.
SetURL
(
host
))
if
err
!=
nil
{
exception
.
ThrowsErrS
(
fmt
.
Sprintf
(
"ES连接失败:%s"
,
err
.
Error
()))
}
info
,
code
,
err
:=
Client
.
Ping
(
host
)
.
Do
(
context
.
Background
())
if
err
!=
nil
{
panic
(
err
)
}
log
.
Info
(
fmt
.
Sprintf
(
"Elasticsearch connect %d"
,
code
))
log
.
Info
(
fmt
.
Sprintf
(
"Elasticsearch version %s"
,
info
.
Version
.
Number
))
}
a/log/es/EsLogger.go
deleted
100644 → 0
View file @
b0fa14c1
package
es
import
(
"context"
"encoding/json"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
log2
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"github.com/olivere/elastic/v7"
"sort"
"time"
)
func
getCurrentIndex
()
string
{
return
indexNamePrefix
+
util
.
FormatDates
(
time
.
Now
())
}
type
ServerLogModel
struct
{
ServerName
string
`json:"serverName"`
Env
string
`json:"env"`
TimeStamp
int64
`json:"timeStamp"`
ThreadNo
string
`json:"threadNo"`
ServerIp
string
`json:"serverIp"`
ClientIp
string
`json:"clientIp"`
Token
string
`json:"token"`
CustomerId
uint32
`json:"customerId"`
ClientSource
string
`json:"clientSource"`
Url
string
`json:"url"`
Method
string
`json:"method"`
Request
string
`json:"request"`
Response
string
`json:"response"`
DealTimes
int64
`json:"dealTimes"`
}
func
InsertEsLog
(
log
interface
{})
{
indexName
:=
getCurrentIndex
()
put
,
err
:=
Client
.
Index
()
.
Index
(
indexName
)
.
BodyJson
(
log
)
.
Do
(
context
.
Background
())
if
err
!=
nil
{
log2
.
Error
(
fmt
.
Sprintf
(
"insert es log fail:%s"
,
err
.
Error
()))
}
else
{
log2
.
Debug
(
fmt
.
Sprintf
(
"insert es log success:%s"
,
put
.
Id
))
}
}
func
GroupField
(
indexName
,
field
string
,
size
,
minCount
int
,
excludeValues
[]
string
)
[]
byte
{
if
size
==
0
{
size
=
30
}
aggregationQuery
:=
elastic
.
NewTermsAggregation
()
.
Field
(
field
)
.
MinDocCount
(
minCount
)
.
Size
(
size
)
for
_
,
excludeValue
:=
range
excludeValues
{
aggregationQuery
.
ExcludeValues
(
excludeValue
)
}
if
log2
.
IsDebug
()
{
source
,
_
:=
aggregationQuery
.
Source
()
queryByte
,
_
:=
json
.
Marshal
(
source
)
log2
.
Info
(
fmt
.
Sprintf
(
"查询条件:%s"
,
string
(
queryByte
)))
}
res
,
err
:=
Client
.
Search
(
indexName
)
.
Aggregation
(
"group_field"
,
aggregationQuery
)
.
From
(
0
)
.
Size
(
0
)
.
Do
(
context
.
Background
())
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
bs
,
err
:=
json
.
Marshal
(
res
.
Aggregations
)
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
return
bs
}
func
QueryLogs
(
indexName
,
filed
,
value
string
,
from
,
size
int
)
interface
{}
{
if
from
<=
0
{
from
=
0
}
if
size
<=
0
{
size
=
10
}
query
:=
elastic
.
NewBoolQuery
()
.
Must
(
elastic
.
NewTermQuery
(
filed
,
value
))
res
,
err
:=
Client
.
Search
(
indexName
)
.
Query
(
query
)
.
From
(
from
)
.
Size
(
size
)
.
Do
(
context
.
Background
())
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
return
res
}
type
IndexInfo
struct
{
Name
string
`json:"name"`
Count
int
`json:"count"`
Size
string
`json:"size"`
}
func
AllIndex
()
interface
{}
{
res
,
err
:=
Client
.
CatIndices
()
.
Do
(
context
.
Background
())
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
var
keys
[]
string
var
sizeMap
=
make
(
map
[
string
]
IndexInfo
)
for
_
,
row
:=
range
res
{
keys
=
append
(
keys
,
row
.
Index
)
sizeMap
[
row
.
Index
]
=
IndexInfo
{
row
.
Index
,
row
.
DocsCount
,
row
.
StoreSize
}
}
sort
.
Strings
(
keys
)
data
:=
make
([]
IndexInfo
,
len
(
keys
))
for
i
,
key
:=
range
keys
{
data
[
i
]
=
sizeMap
[
key
]
}
return
data
}
func
DeleteIndex
(
indexName
string
)
interface
{}
{
res
,
err
:=
Client
.
DeleteIndex
(
indexName
)
.
Do
(
context
.
Background
())
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
return
res
}
a/conf/
conf.go
→
conf.go
View file @
dc7cf41f
package
conf
package
rym_util
type
Config
struct
{
type
Config
struct
{
ENV
string
ENV
string
...
...
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