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
6142204c
Commit
6142204c
authored
Aug 08, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
dc7cf41f
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
181 additions
and
188 deletions
+181
-188
conf.go
a/conf/conf.go
+33
-0
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
+12
-12
allinpay.go
a/lib/allinpay/allinpay.go
+5
-6
main.go
a/lib/allinpay/main/main.go
+22
-23
Logger.go
a/log/Logger.go
+61
-0
ArrayUtil.go
a/util/ArrayUtil.go
+1
-1
DateUtil.go
a/util/DateUtil.go
+1
-1
IfUtil.go
a/util/IfUtil.go
+1
-1
ImgUtil.go
a/util/ImgUtil.go
+1
-1
Map2SHA256WithRSA.go
a/util/Map2SHA256WithRSA.go
+1
-1
MapUtil.go
a/util/MapUtil.go
+1
-1
Md5Util.go
a/util/Md5Util.go
+1
-1
ProgramUtil.go
a/util/ProgramUtil.go
+1
-1
PwdUtil.go
a/util/PwdUtil.go
+1
-1
RuntimeUtil.go
a/util/RuntimeUtil.go
+1
-1
StringUtil.go
a/util/StringUtil.go
+1
-1
conf.go
conf.go
+0
-46
go.mod
go.mod
+0
-16
rym-logger.go
rym-logger.go
+16
-53
No files found.
a/conf/conf.go
0 → 100644
View file @
6142204c
package
conf
type
Config
struct
{
ENV
string
ServerName
string
ShowSql
bool
LogLevel
string
LogColorful
bool
LogResponseLength
int
}
func
BaseConfig
(
conf
Config
)
{
ENV
=
conf
.
ENV
ServerName
=
conf
.
ServerName
ShowSql
=
conf
.
ShowSql
LogLevel
=
conf
.
LogLevel
LogColorful
=
conf
.
LogColorful
LogResponseLength
=
conf
.
LogResponseLength
}
var
ENV
=
"test"
var
ServerName
=
"git.168cad.top/zhengqiuyun/rym-util"
//ShowSql 是否打印SQL
var
ShowSql
=
true
//是否打印SQL
var
LogLevel
=
"Debug"
//LogColorful 日志是否开启彩色打印
var
LogColorful
=
true
var
LogResponseLength
=
1000
a/exception/GlobalException.go
View file @
6142204c
...
...
@@ -2,14 +2,14 @@ package exception
import
(
"errors"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util
/a/log
"
"github.com/go-playground/validator/v10"
"reflect"
)
func
ThrowsErr
(
err
error
)
{
if
err
!=
nil
{
rym_util
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
panic
(
err
)
}
}
...
...
@@ -57,7 +57,7 @@ func (e *DError) Error() string {
}
func
ThrowsErrS
(
err
string
)
{
if
&
err
!=
nil
&&
err
!=
""
{
rym_util
.
Error
(
err
)
log
.
Error
(
err
)
panic
(
DError
{
Err
:
err
})
}
}
a/generate/generate.go
View file @
6142204c
...
...
@@ -2,7 +2,7 @@ package generate
import
(
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util
/a/conf
"
"github.com/deckarep/golang-set"
"github.com/iancoleman/strcase"
"io"
...
...
@@ -49,7 +49,7 @@ func BuildPgModels() {
doTable
,
ok
:=
DoTables
[
table
.
Name
]
if
ok
{
var
tableFields
[]
TableField
if
rym_util
.
DBType
==
"PostgreSql"
{
if
conf
.
DBType
==
"PostgreSql"
{
tableFields
=
GetTableFiledByTableName
(
table
.
Name
)
}
else
{
tableFields
=
MysqlGetTableFiledByTableName
(
table
.
Name
)
...
...
@@ -83,7 +83,7 @@ func getModelImport(field TableField) string {
}
func
getModelFiledType
(
field
TableField
)
string
{
if
rym_util
.
DBType
==
"PostgreSql"
{
if
conf
.
DBType
==
"PostgreSql"
{
return
DbToGoPG
[
field
.
FieldType
]
}
else
{
if
strings
.
Index
(
field
.
ColumnType
,
"unsigned"
)
>
0
{
...
...
@@ -294,10 +294,10 @@ func generateDao(table *Table, fields []TableField, doTable TableInfo) {
pageQuery
+=
"}
\n
"
importStr
:=
"import (
\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/PagePlus
\"\n
"
if
rym_util
.
DBType
==
""
{
if
conf
.
DBType
==
""
{
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db
\"\n
"
}
else
{
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db/"
+
rym_util
.
DBType
+
"
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/db/"
+
conf
.
DBType
+
"
\"\n
"
}
importStr
+=
"
\t\"
"
+
projectName
+
"/a/exception
\"\n
"
importStr
+=
"
\t\"
"
+
projectName
+
"/a/page
\"\n
"
...
...
a/getWay/Request.go
View file @
6142204c
...
...
@@ -3,9 +3,9 @@ package getWay
import
(
"encoding/json"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/db/redis"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"github.com/gin-gonic/gin"
"io/ioutil"
"net"
...
...
@@ -45,18 +45,18 @@ func GetAdminInfo(token string) Admin {
var
adminResponse
=
AdminResponse
{}
resp
,
err
:=
http
.
Get
(
conf
.
SystemHost
+
"/admin/current?token="
+
token
)
if
err
!=
nil
{
rym_util
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
return
Admin
{}
}
defer
resp
.
Body
.
Close
()
adminResponseBytes
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
rym_util
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
return
Admin
{}
}
err
=
json
.
Unmarshal
(
adminResponseBytes
,
&
adminResponse
)
if
err
!=
nil
{
rym_util
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
return
adminResponse
.
Admin
}
...
...
@@ -145,13 +145,13 @@ func ValidRequest(c *gin.Context) {
token
:=
GetToken
(
c
)
if
token
==
""
{
if
checkIp
(
ip
)
{
//如果没有token,看是否是ip白名单
rym_util
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验通过:%s"
,
ip
))
log
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验通过:%s"
,
ip
))
}
else
{
rym_util
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验不通过:%s"
,
ip
))
log
.
Debug
(
fmt
.
Sprintf
(
"IP白名单校验不通过:%s"
,
ip
))
if
checkUri
(
url
)
{
//如果不是ip白名单,看是否是url白名单,例如一些第三方的回调
rym_util
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验通过:%s"
,
url
))
log
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验通过:%s"
,
url
))
}
else
{
rym_util
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验不通过:%s"
,
url
))
log
.
Debug
(
fmt
.
Sprintf
(
"URL白名单校验不通过:%s"
,
url
))
ThrowsGetWayErr
(
Illegal9
)
}
}
...
...
@@ -159,9 +159,9 @@ func ValidRequest(c *gin.Context) {
if
redis
.
Exists
(
token
)
{
//校验token是否有效
currentUser
:=
GetAdminInfo
(
token
)
c
.
Set
(
CurrentUserKey
,
currentUser
)
rym_util
.
Debug
(
fmt
.
Sprintf
(
"登陆校验通过:%s,对应用户id: %d"
,
token
,
currentUser
.
Id
))
log
.
Debug
(
fmt
.
Sprintf
(
"登陆校验通过:%s,对应用户id: %d"
,
token
,
currentUser
.
Id
))
}
else
{
rym_util
.
Debug
(
fmt
.
Sprintf
(
"登陆校验不通过:%s"
,
token
))
log
.
Debug
(
fmt
.
Sprintf
(
"登陆校验不通过:%s"
,
token
))
ThrowsGetWayErr
(
Expire
)
}
}
...
...
@@ -180,7 +180,7 @@ func exceptionGetWayCatch(c *gin.Context) {
}
func
checkUri
(
uri
string
)
bool
{
for
_
,
v
:=
range
rym_util
.
WhiteListUri
{
for
_
,
v
:=
range
conf
.
WhiteListUri
{
if
strings
.
Index
(
uri
,
v
)
==
0
{
return
true
}
...
...
@@ -189,7 +189,7 @@ func checkUri(uri string) bool {
}
func
checkIp
(
ip
string
)
bool
{
for
_
,
v
:=
range
rym_util
.
WhiteListIp
{
for
_
,
v
:=
range
conf
.
WhiteListIp
{
if
strings
.
Index
(
ip
,
v
)
==
0
{
return
true
}
...
...
@@ -198,5 +198,5 @@ func checkIp(ip string) bool {
}
func
logStart
(
c
*
gin
.
Context
)
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"开始 %s %s %s %s"
,
GetMethod
(
c
),
GetURL
(
c
),
GetToken
(
c
),
GetClientIP
(
c
)))
log
.
Info
(
fmt
.
Sprintf
(
"开始 %s %s %s %s"
,
GetMethod
(
c
),
GetURL
(
c
),
GetToken
(
c
),
GetClientIP
(
c
)))
}
a/getWay/Response.go
View file @
6142204c
...
...
@@ -3,11 +3,11 @@ package getWay
import
(
"encoding/json"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util
/a/conf
"
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/log"
"git.168cad.top/zhengqiuyun/rym-util/a/log/es"
"git.168cad.top/zhengqiuyun/rym-util/a/util"
"github.com/gin-gonic/gin"
"net/http"
"time"
...
...
@@ -76,7 +76,7 @@ func AliSuccess(c *gin.Context) {
}
func
logEnd
(
c
*
gin
.
Context
,
data
interface
{})
{
esSwitch
:=
redis
.
SwitchOpen
(
redis
.
ES日志开关
+
rym_util
.
ServerName
)
esSwitch
:=
redis
.
SwitchOpen
(
redis
.
ES日志开关
+
conf
.
ServerName
)
startTime
:=
GetStartTime
(
c
)
endTime
:=
time
.
Now
()
.
UnixNano
()
var
responseStr
string
...
...
@@ -85,14 +85,14 @@ func logEnd(c *gin.Context, data interface{}) {
rs
:=
string
(
dataJson
)
excludeUrl
:=
[]
string
{
""
}
if
esSwitch
{
if
util
.
ArrayContains
(
excludeUrl
,
GetURL
(
c
))
&&
len
(
rs
)
>
rym_util
.
LogResponseLength
{
responseStr
=
rs
[
0
:
rym_util
.
LogResponseLength
]
+
"......"
if
util
.
ArrayContains
(
excludeUrl
,
GetURL
(
c
))
&&
len
(
rs
)
>
conf
.
LogResponseLength
{
responseStr
=
rs
[
0
:
conf
.
LogResponseLength
]
+
"......"
}
else
{
responseStr
=
rs
}
}
else
{
if
len
(
rs
)
>
rym_util
.
LogResponseLength
{
responseStr
=
rs
[
0
:
rym_util
.
LogResponseLength
]
+
"......"
if
len
(
rs
)
>
conf
.
LogResponseLength
{
responseStr
=
rs
[
0
:
conf
.
LogResponseLength
]
+
"......"
}
else
{
responseStr
=
rs
}
...
...
@@ -101,18 +101,18 @@ func logEnd(c *gin.Context, data interface{}) {
token
:=
GetToken
(
c
)
if
esSwitch
&&
token
!=
""
{
esLog
(
c
,
responseStr
)
rym_util
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒"
,
(
endTime
-
startTime
)
/
1e6
))
log
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒"
,
(
endTime
-
startTime
)
/
1e6
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"返回数据:%s"
,
responseStr
))
rym_util
.
Info
(
fmt
.
Sprintf
(
"结束,耗时%d毫秒 %s %s %s %s %s"
,
(
endTime
-
startTime
)
/
1e6
,
GetMethod
(
c
),
GetURL
(
c
),
token
,
GetClientIP
(
c
),
GetParams
(
c
)))
log
.
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
)))
}
}
func
esLog
(
c
*
gin
.
Context
,
response
string
)
{
log
:=
es
.
ServerLogModel
{
ServerName
:
rym_util
.
ServerName
,
Env
:
rym_util
.
ENV
,
ServerName
:
conf
.
ServerName
,
Env
:
conf
.
ENV
,
TimeStamp
:
util
.
MilSecond
(
time
.
Now
()),
ThreadNo
:
fmt
.
Sprintf
(
"%d"
,
util
.
GetGID
()),
ServerIp
:
GetServerIP
(),
...
...
a/lib/allinpay/allinpay.go
View file @
6142204c
...
...
@@ -7,10 +7,9 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
"git.168cad.top/zhengqiuyun/rym-util/a/
util
"
"git.168cad.top/zhengqiuyun/rym-util/a/
log
"
"io"
"io/ioutil"
"net/http"
...
...
@@ -53,7 +52,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
requestStr
=
p
.
Encode
()
buf
=
strings
.
NewReader
(
requestStr
)
}
rym_util
.
Debug
(
fmt
.
Sprintf
(
"请求参数:%s"
,
requestStr
))
log
.
Debug
(
fmt
.
Sprintf
(
"请求参数:%s"
,
requestStr
))
req
,
err
:=
http
.
NewRequest
(
method
,
conf
.
AllinpayUrl
,
buf
)
if
err
!=
nil
{
return
err
...
...
@@ -70,7 +69,7 @@ func (c *Client) doRequest(method string, param Param, result interface{}) (err
if
err
!=
nil
{
return
err
}
rym_util
.
Debug
(
fmt
.
Sprintf
(
"请求结果:%s"
,
string
(
data
)))
log
.
Debug
(
fmt
.
Sprintf
(
"请求结果:%s"
,
string
(
data
)))
ok
,
err
:=
verifyData
(
data
,
c
.
tlPublicKey
)
if
err
!=
nil
{
return
err
...
...
@@ -145,7 +144,7 @@ func signWithPKCS1v15(param url.Values, privateKey *rsa.PrivateKey, hash crypto.
}
sort
.
Strings
(
pList
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
rym_util
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
log
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
md5Str
:=
md5S
(
src
)
sig
,
err
:=
RSASignWithKey
([]
byte
(
md5Str
),
privateKey
,
hash
)
if
err
!=
nil
{
...
...
@@ -179,7 +178,7 @@ func (c *Client) getDefaultNotification(data map[string]string, sign string, res
}
sort
.
Strings
(
pList
)
var
src
=
strings
.
Join
(
pList
,
"&"
)
rym_util
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
log
.
Debug
(
fmt
.
Sprintf
(
"签名数据:%s"
,
src
))
md5Str
:=
md5B
([]
byte
(
src
))
signBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
sign
)
if
err
!=
nil
{
...
...
a/lib/allinpay/main/main.go
View file @
6142204c
...
...
@@ -2,11 +2,10 @@ package main
import
(
"fmt"
"git.168cad.top/zhengqiuyun/rym-util"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/exception"
lib_allinpay
"git.168cad.top/zhengqiuyun/rym-util/a/lib/allinpay"
"git.168cad.top/zhengqiuyun/rym-util/a/
util
"
"git.168cad.top/zhengqiuyun/rym-util/a/
log
"
"time"
)
...
...
@@ -46,9 +45,9 @@ func testGetPayeeFundsInTransitDetail() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -69,9 +68,9 @@ func testQueryInExpDetail() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -106,7 +105,7 @@ func testCreateMember() {
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
func
testBindWxOpenId
()
{
...
...
@@ -123,7 +122,7 @@ func testBindWxOpenId() {
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
func
testGetMemberInfo
()
{
...
...
@@ -137,7 +136,7 @@ func testGetMemberInfo() {
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
func
testConsumeApply
()
{
...
...
@@ -176,9 +175,9 @@ func testConsumeApply() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
.
PayInfo
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
.
PayInfo
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -196,9 +195,9 @@ func testGetOrderDetail() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -214,9 +213,9 @@ func testQueryReserveFundBalance() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -233,9 +232,9 @@ func testQueryBalance() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -251,9 +250,9 @@ func testQueryBankCard() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -275,7 +274,7 @@ func testWithDrawApply() {
p
.
BackUrl
=
conf
.
MainHost
+
"/pay/allin/pay/draw/notify"
bankCardNo
:=
"324348812323"
encryptBankCardNo
,
err
:=
lib_allinpay
.
AesEncryptECB
(
bankCardNo
,
conf
.
AllinpaySecretKey
)
rym_util
.
Info
(
fmt
.
Sprintf
(
"银行卡加密数据:%s"
,
encryptBankCardNo
))
log
.
Info
(
fmt
.
Sprintf
(
"银行卡加密数据:%s"
,
encryptBankCardNo
))
if
err
!=
nil
{
exception
.
ThrowsErrS
(
"通联密钥错误,请检查配置"
)
}
...
...
@@ -291,9 +290,9 @@ func testWithDrawApply() {
exception
.
ThrowsErr
(
err
)
}
if
response
.
Code
==
lib_allinpay
.
CodeSuccess
&&
response
.
SubCode
==
lib_allinpay
.
SubCodeSuccess
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
log
.
Info
(
fmt
.
Sprintf
(
"%s"
,
response
.
Data
))
}
else
{
rym_util
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
log
.
Info
(
fmt
.
Sprintf
(
"%s-%s"
,
response
.
Msg
,
response
.
SubMsg
))
}
}
...
...
@@ -315,5 +314,5 @@ func testGetTradeNotification() {
if
err
!=
nil
{
exception
.
ThrowsErr
(
err
)
}
rym_util
.
Info
(
fmt
.
Sprintf
(
"%v"
,
rd
))
log
.
Info
(
fmt
.
Sprintf
(
"%v"
,
rd
))
}
a/log/Logger.go
0 → 100644
View file @
6142204c
package
log
import
(
"bytes"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"runtime"
"strconv"
"strings"
"time"
)
const
(
DebugL
=
"Debug"
InfoL
=
"Info"
ErrorL
=
"Error"
)
// Colors
const
(
Reset
=
"
\0
33[0m"
Red
=
"
\0
33[31m"
Green
=
"
\0
33[32m"
Yellow
=
"
\0
33[33m"
Blue
=
"
\0
33[34m"
Magenta
=
"
\0
33[35m"
Cyan
=
"
\0
33[36m"
White
=
"
\0
33[37m"
BlueBold
=
"
\0
33[34;1m"
MagentaBold
=
"
\0
33[35;1m"
RedBold
=
"
\0
33[31;1m"
YellowBold
=
"
\0
33[33;1m"
)
func
Print
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
if
conf
.
LogColorful
{
if
tag
==
"Error"
{
str
=
"%s %s [%d] %s %d "
+
Red
+
"%s"
+
Reset
}
else
if
tag
==
"Info"
{
str
=
"%s %s [%d] %s %d "
+
Yellow
+
"%s"
+
Reset
}
else
{
str
=
"%s %s [%d] %s %d "
+
Green
+
"%s"
+
Reset
}
}
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
fmt
.
Println
(
fmt
.
Sprintf
(
str
,
FormatDateMillTime
(
time
.
Now
()),
tag
,
GetGID
(),
file
,
line
,
msg
))
}
func
FormatDateMillTime
(
dataTime
time
.
Time
)
string
{
return
dataTime
.
Format
(
"2006-01-02 15:04:05.000000"
)
}
func
GetGID
()
uint64
{
b
:=
make
([]
byte
,
64
)
b
=
b
[
:
runtime
.
Stack
(
b
,
false
)]
b
=
bytes
.
TrimPrefix
(
b
,
[]
byte
(
"goroutine "
))
b
=
b
[
:
bytes
.
IndexByte
(
b
,
' '
)]
n
,
_
:=
strconv
.
ParseUint
(
string
(
b
),
10
,
64
)
return
n
}
a/util/ArrayUtil.go
View file @
6142204c
package
util
package
rym_
util
func
ArrayContains
(
array
[]
string
,
e
string
)
bool
{
for
_
,
v
:=
range
array
{
...
...
a/util/DateUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"time"
...
...
a/util/IfUtil.go
View file @
6142204c
package
util
package
rym_
util
func
IfInt
(
isTrue
bool
,
a
,
b
int
)
int
{
if
isTrue
{
...
...
a/util/ImgUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"encoding/base64"
...
...
a/util/Map2SHA256WithRSA.go
View file @
6142204c
package
util
package
rym_
util
import
(
"bytes"
...
...
a/util/MapUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"encoding/json"
...
...
a/util/Md5Util.go
View file @
6142204c
package
util
package
rym_
util
import
(
"crypto/md5"
...
...
a/util/ProgramUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"os"
...
...
a/util/PwdUtil.go
View file @
6142204c
package
util
package
rym_
util
func
EncodePwd
(
loginPwd
,
loginPwdSalt
string
)
string
{
pingPwd
:=
loginPwdSalt
+
loginPwd
...
...
a/util/RuntimeUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"bytes"
...
...
a/util/StringUtil.go
View file @
6142204c
package
util
package
rym_
util
import
(
"encoding/json"
...
...
conf.go
deleted
100644 → 0
View file @
dc7cf41f
package
rym_util
type
Config
struct
{
ENV
string
}
func
BaseConfig
(
conf
Config
)
{
ENV
=
conf
.
ENV
}
var
ENV
=
"test"
var
ServerName
=
"git.168cad.top/zhengqiuyun/rym-util"
var
DBType
=
"mysql"
var
EsHttpHost
=
"http://192.168.1.124:9200"
//mysql
var
DbDSN
=
"root:dcrym29210924..@tcp(192.168.1.37:3306)/duocaihui_dev?charset=utf8mb4&parseTime=True&loc=Local"
//ShowSql 是否打印SQL
var
ShowSql
=
true
//是否打印SQL
var
LogLevel
=
"Debug"
var
HttpServerPort
=
"8080"
var
WhiteListIp
=
[
...
]
string
{
"::1"
,
"192.168.71.127"
,
"171.88.67.133"
}
var
WhiteListUri
=
[
...
]
string
{
"/swagger"
,
"/api/app/login/get/captcha"
,
"/api/app/login/register/send/sms"
,
"/api/app/login/register"
,
"/api/app/login/forget/pwd/send/sms"
,
"/api/app/login/forget/pwd"
,
"/api/app/login/login"
,
"/api/app/wx/login/bind/check"
,
"/api/app/wx/login/bind/send/sms"
,
"/api/app/wx/login/bind"
,
"/api/app/wx/login"
,
"/pay/wx/pay/notify"
}
var
CheckSms
=
false
var
SmsSendUrl
=
"http://192.168.1.43:9001"
var
SmsVerifyUrl
=
"http://192.168.1.43:9001"
//LogColorful 日志是否开启彩色打印
var
LogColorful
=
true
var
LogResponseLength
=
1000
var
CaptchaMax
=
5
go.mod
View file @
6142204c
...
...
@@ -3,17 +3,6 @@ module git.168cad.top/zhengqiuyun/rym-util
go 1.16
require (
github.com/deckarep/golang-set v1.7.1
github.com/garyburd/redigo v1.6.3
github.com/gin-gonic/gin v1.7.4
github.com/go-playground/validator/v10 v10.4.1
github.com/iancoleman/strcase v0.2.0
github.com/shopspring/decimal v1.2.0
github.com/wechatpay-apiv3/wechatpay-go v0.2.9
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
gorm.io/driver/mysql v1.2.2
gorm.io/driver/postgres v1.2.2
gorm.io/gorm v1.22.4
)
require (
...
...
@@ -22,13 +11,8 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/olivere/elastic/v7 v7.0.32
github.com/robfig/cron v1.2.0
github.com/smartwalle/crypto4go v1.0.3
github.com/wenlng/go-captcha v1.2.5
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
replace git.168cad.top/zhengqiuyun/rym-util => ../rym-util
DcL
ogger.go
→
rym-l
ogger.go
View file @
6142204c
package
rym_util
import
(
"bytes"
"fmt"
"gorm.io/gorm/logger"
"git.168cad.top/zhengqiuyun/rym-util/a/conf"
"git.168cad.top/zhengqiuyun/rym-util/a/log"
"runtime"
"strconv"
"strings"
"time"
)
const
(
DebugL
=
"Debug"
InfoL
=
"Info"
ErrorL
=
"Error"
)
func
DebugDo
(
f
func
())
{
...
...
@@ -24,8 +15,8 @@ func DebugDo(f func()) {
func
IsDebug
()
bool
{
ok
:=
false
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
log
.
DebugL
)
:
ok
=
true
break
}
...
...
@@ -34,76 +25,48 @@ func IsDebug() bool {
func
Debug
(
msg
string
)
{
ok
:=
false
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
log
.
DebugL
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
mark
(
"Debug"
,
msg
,
file
,
line
)
log
.
Print
(
"Debug"
,
msg
,
file
,
line
)
}
}
func
Info
(
msg
string
)
{
ok
:=
false
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
log
.
DebugL
)
:
ok
=
true
break
case
strings
.
ToLower
(
InfoL
)
:
case
strings
.
ToLower
(
log
.
InfoL
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
mark
(
"Info"
,
msg
,
file
,
line
)
log
.
Print
(
"Info"
,
msg
,
file
,
line
)
}
}
func
Error
(
msg
string
)
{
ok
:=
false
switch
strings
.
ToLower
(
LogLevel
)
{
case
strings
.
ToLower
(
DebugL
)
:
switch
strings
.
ToLower
(
conf
.
LogLevel
)
{
case
strings
.
ToLower
(
log
.
DebugL
)
:
ok
=
true
break
case
strings
.
ToLower
(
InfoL
)
:
case
strings
.
ToLower
(
log
.
InfoL
)
:
ok
=
true
break
case
strings
.
ToLower
(
ErrorL
)
:
case
strings
.
ToLower
(
log
.
ErrorL
)
:
ok
=
true
break
}
if
ok
{
_
,
file
,
line
,
_
:=
runtime
.
Caller
(
1
)
mark
(
"Error"
,
msg
,
file
,
line
)
}
}
func
mark
(
tag
,
msg
string
,
file
string
,
line
int
)
{
str
:=
"%s %s [%d] %s %d %s"
if
LogColorful
{
if
tag
==
"Error"
{
str
=
"%s %s [%d] %s %d "
+
logger
.
Red
+
"%s"
+
logger
.
Reset
}
else
if
tag
==
"Info"
{
str
=
"%s %s [%d] %s %d "
+
logger
.
Yellow
+
"%s"
+
logger
.
Reset
}
else
{
str
=
"%s %s [%d] %s %d "
+
logger
.
Green
+
"%s"
+
logger
.
Reset
log
.
Print
(
"Error"
,
msg
,
file
,
line
)
}
}
file
=
file
[
strings
.
LastIndex
(
file
,
"/"
)
+
1
:
]
fmt
.
Println
(
fmt
.
Sprintf
(
str
,
FormatDateMillTime
(
time
.
Now
()),
tag
,
GetGID
(),
file
,
line
,
msg
))
}
func
FormatDateMillTime
(
dataTime
time
.
Time
)
string
{
return
dataTime
.
Format
(
"2006-01-02 15:04:05.000000"
)
}
func
GetGID
()
uint64
{
b
:=
make
([]
byte
,
64
)
b
=
b
[
:
runtime
.
Stack
(
b
,
false
)]
b
=
bytes
.
TrimPrefix
(
b
,
[]
byte
(
"goroutine "
))
b
=
b
[
:
bytes
.
IndexByte
(
b
,
' '
)]
n
,
_
:=
strconv
.
ParseUint
(
string
(
b
),
10
,
64
)
return
n
}
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