瀏覽代碼

first commit

zoie 2 年之前
父節點
當前提交
1ac91f2992
共有 11 個文件被更改,包括 1056 次插入0 次删除
  1. 5 0
      .gitignore
  2. 22 0
      go.mod
  3. 84 0
      go.sum
  4. 59 0
      lib/Aes.go
  5. 50 0
      lib/GoPDF.go
  6. 193 0
      lib/Onelink.go
  7. 91 0
      lib/Qiniu.go
  8. 24 0
      lib/ReplaceSQL.go
  9. 20 0
      lib/WritePid.go
  10. 417 0
      lib/lib.go
  11. 91 0
      lib/libString.go

+ 5 - 0
.gitignore

@@ -24,3 +24,8 @@ _testmain.go
 *.test
 *.prof
 
+.idea
+/_
+/.cache
+.vscode/
+

+ 22 - 0
go.mod

@@ -0,0 +1,22 @@
+module git.baozhida.cn/ERP_libs
+
+go 1.19
+
+require (
+	github.com/nats-io/nats.go v1.23.0
+	github.com/qiniu/go-sdk/v7 v7.14.0
+	github.com/satori/go.uuid v1.2.0
+	github.com/signintech/gopdf v0.16.1
+)
+
+require (
+	github.com/golang/protobuf v1.5.2 // indirect
+	github.com/nats-io/nats-server/v2 v2.9.14 // indirect
+	github.com/nats-io/nkeys v0.3.0 // indirect
+	github.com/nats-io/nuid v1.0.1 // indirect
+	github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect
+	github.com/pkg/errors v0.8.1 // indirect
+	golang.org/x/crypto v0.5.0 // indirect
+	golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
+	google.golang.org/protobuf v1.28.1 // indirect
+)

+ 84 - 0
go.sum

@@ -0,0 +1,84 @@
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
+github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
+github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
+github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
+github.com/go-playground/validator/v10 v10.8.0/go.mod h1:9JhgTzTaE31GZDpH/HSvHiRJrJ3iKAgqqH0Bl/Ocjdk=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
+github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
+github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
+github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
+github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
+github.com/nats-io/nats-server/v2 v2.9.14 h1:n2GscWVgXpA14vQSRP/MM1SGi4wyazR9l19/gWxqgXQ=
+github.com/nats-io/nats-server/v2 v2.9.14/go.mod h1:40ZwFm4npKdFBhOdY7rkh3YyI1oI91FzLvlYyB7HfzM=
+github.com/nats-io/nats.go v1.23.0 h1:lR28r7IX44WjYgdiKz9GmUeW0uh/m33uD3yEjLZ2cOE=
+github.com/nats-io/nats.go v1.23.0/go.mod h1:ki/Scsa23edbh8IRZbCuNXR9TDcbvfaSijKtaqQgw+Q=
+github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
+github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
+github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
+github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
+github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no=
+github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
+github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
+github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/qiniu/dyn v1.3.0/go.mod h1:E8oERcm8TtwJiZvkQPbcAh0RL8jO1G0VXJMW3FAWdkk=
+github.com/qiniu/go-sdk/v7 v7.14.0 h1:6icihMTKHoKMmeU1mqtIoHUv7c1LrLjYm8wTQaYDqmw=
+github.com/qiniu/go-sdk/v7 v7.14.0/go.mod h1:btsaOc8CA3hdVloULfFdDgDc+g4f3TDZEFsDY0BLE+w=
+github.com/qiniu/x v1.10.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
+github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
+github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
+github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
+github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
+github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
+github.com/signintech/gopdf v0.16.1 h1:p+JjxLsz4ploSmFAruCbYM3c7Hp+jEL3DWZm5SO8bAU=
+github.com/signintech/gopdf v0.16.1/go.mod h1:wrLtZoWaRNrS4hphED0oflFoa6IWkOu6M3nJjm4VbO4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
+golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
+golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
+golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
+google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
+google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 59 - 0
lib/Aes.go

@@ -0,0 +1,59 @@
+package lib
+
+import (
+	"bytes"
+	"crypto/aes"
+	"crypto/cipher"
+	"encoding/base64"
+)
+
+func AesEncryptCBC(orig string, key string) string {
+	// 转成字节数组
+	origData := []byte(orig)
+	k := []byte(key)
+	// 分组秘钥
+	// NewCipher该函数限制了输入k的长度必须为16, 24或者32
+	block, _ := aes.NewCipher(k)
+	// 获取秘钥块的长度
+	blockSize := block.BlockSize()
+	// 补全码
+	origData = PKCS7Padding(origData, blockSize)
+	// 加密模式
+	blockMode := cipher.NewCBCEncrypter(block, k[:blockSize])
+	// 创建数组
+	cryted := make([]byte, len(origData))
+	// 加密
+	blockMode.CryptBlocks(cryted, origData)
+	return base64.StdEncoding.EncodeToString(cryted)
+}
+func AesDecryptCBC(cryted string, key string) string {
+	// 转成字节数组
+	crytedByte, _ := base64.StdEncoding.DecodeString(cryted)
+	k := []byte(key)
+	// 分组秘钥
+	block, _ := aes.NewCipher(k)
+	// 获取秘钥块的长度
+	blockSize := block.BlockSize()
+	// 加密模式
+	blockMode := cipher.NewCBCDecrypter(block, k[:blockSize])
+	// 创建数组
+	orig := make([]byte, len(crytedByte))
+	// 解密
+	blockMode.CryptBlocks(orig, crytedByte)
+	// 去补全码
+	orig = PKCS7UnPadding(orig)
+	return string(orig)
+}
+//补码
+//AES加密数据块分组长度必须为128bit(byte[16]),密钥长度可以是128bit(byte[16])、192bit(byte[24])、256bit(byte[32])中的任意一个。
+func PKCS7Padding(ciphertext []byte, blocksize int) []byte {
+	padding := blocksize - len(ciphertext)%blocksize
+	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
+	return append(ciphertext, padtext...)
+}
+//去码
+func PKCS7UnPadding(origData []byte) []byte {
+	length := len(origData)
+	unpadding := int(origData[length-1])
+	return origData[:(length - unpadding)]
+}

+ 50 - 0
lib/GoPDF.go

@@ -0,0 +1,50 @@
+package lib
+
+import "github.com/signintech/gopdf"
+
+const (
+	ValignTop    = 1
+	ValignMiddle = 2
+	ValignBottom = 3
+)
+
+const (
+	AlignLeft   = 4
+	AlignCenter = 5
+	AlignRight  = 6
+)
+
+func RectFillColor(pdf *gopdf.GoPdf,
+	text string,
+	fontSize int,
+	x, y, w, h float64,
+	r, g, b uint8,
+	align, valign int,
+) {
+
+
+	pdf.SetLineWidth(0.1)
+	pdf.SetFillColor(r, g, b) //setup fill color
+	pdf.SetLineType("")       // 线条样式
+	pdf.RectFromUpperLeftWithStyle(x, y, w, h, "FD")
+	pdf.SetFillColor(0, 0, 0)
+
+	if align == AlignCenter {
+		textw, _ := pdf.MeasureTextWidth(text)
+		x = x + (w / 2) - (textw / 2)
+	} else if align == AlignRight {
+		textw, _ := pdf.MeasureTextWidth(text)
+		x = x + w - textw
+	}
+
+	pdf.SetX(x)
+
+	if valign == ValignMiddle {
+		y = y + (h / 2) - (float64(fontSize) / 2)
+	} else if valign == ValignBottom {
+		y = y + h - float64(fontSize)
+	}
+
+	pdf.SetY(y)
+	pdf.Cell(nil, text)
+}

+ 193 - 0
lib/Onelink.go

@@ -0,0 +1,193 @@
+package lib
+
+import (
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+)
+
+func yidong_token() (string,bool) {
+
+	url := "https://api.iot.10086.cn/v5/ec/get/token?transid=851AIOT202204251553361888100000003&password=L44tB,J5EQhj&appid=851AIOT2022042515533618881&refresh=0"
+	method := "GET"
+
+	client := &http.Client {
+	}
+	req, err := http.NewRequest(method, url, nil)
+
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	defer res.Body.Close()
+
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	fmt.Println(string(body))
+
+
+	type Token struct {
+		Token string `json:"token"`
+	}
+	type TestJson struct {
+		Result []Token `json:"result"`
+	}
+
+	var c TestJson
+	err = json.Unmarshal(body, c)
+	if err := json.Unmarshal([]byte(body), &c); err != nil {
+		fmt.Println("Error =", err)
+	}
+
+	fmt.Println("bodyjson:",c)
+
+	//dd := c["result"]
+	if(len(c.Result) == 0){
+		return "",false
+	}
+	fmt.Println("Token:",c.Result[0].Token)
+
+	return c.Result[0].Token,true
+
+}
+
+
+// 实时查询群组本月套餐内GPRS流量使用量信息。
+type FlowPoolSharingInfo struct {
+	TotalAmount string `json:"totalAmount"`
+	RemainAmount string `json:"remainAmount"`
+	UseAmount string `json:"useAmount"`
+}
+func Yidong_group_data_margin() (FlowPoolSharingInfo,bool) {
+	token,token_is := yidong_token()
+	if !token_is{
+		return FlowPoolSharingInfo{},false
+	}
+	url := "https://api.iot.10086.cn/v5/ec/query/group-data-margin?transid=851AIOT202204251553361888100000003&token="+token+"&groupId=9921000021089000"
+	method := "GET"
+
+	client := &http.Client {
+	}
+	req, err := http.NewRequest(method, url, nil)
+
+	if err != nil {
+		fmt.Println(err)
+		return FlowPoolSharingInfo{},false
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return FlowPoolSharingInfo{},false
+	}
+	defer res.Body.Close()
+
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println(err)
+		return FlowPoolSharingInfo{},false
+	}
+	fmt.Println(string(body))
+
+
+	type List_data struct {
+		FlowPoolSharingInfo []FlowPoolSharingInfo `json:"flowPoolSharingInfo"`
+	}
+	type TestJson struct {
+		Result []List_data `json:"result"`
+	}
+
+	var c TestJson
+	err = json.Unmarshal(body, c)
+	if err := json.Unmarshal([]byte(body), &c); err != nil {
+		fmt.Println("Error =", err)
+	}
+
+	fmt.Println("bodyjson:",c)
+
+	//dd := c["result"]
+	if(len(c.Result) == 0){
+		return FlowPoolSharingInfo{},false
+	}
+	//fmt.Println("Token:",c.Result[0].UseAmount)
+
+	return c.Result[0].FlowPoolSharingInfo[0],true
+
+}
+
+// 实时查询物联卡本月套餐内流量使用量。
+func yidong_sim_data_usage(msisdn string) (string,bool) {
+	token,token_is := yidong_token()
+	if !token_is{
+		return "",false
+	}
+	url := "https://api.iot.10086.cn/v5/ec/query/sim-data-usage?transid=851AIOT202204251553361888100000003&token="+token+"&msisdn="+msisdn
+	method := "GET"
+
+	client := &http.Client {
+	}
+	req, err := http.NewRequest(method, url, nil)
+
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	defer res.Body.Close()
+
+	body, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		fmt.Println(err)
+		return "",false
+	}
+	fmt.Println(string(body))
+
+
+	type List_data struct {
+		DataAmount string `json:"dataAmount"`
+	}
+	type TestJson struct {
+		Result []List_data `json:"result"`
+	}
+
+	var c TestJson
+	err = json.Unmarshal(body, c)
+	if err := json.Unmarshal([]byte(body), &c); err != nil {
+		fmt.Println("Error =", err)
+	}
+
+	fmt.Println("bodyjson:",c)
+
+	//dd := c["result"]
+	if(len(c.Result) == 0){
+		return "",false
+	}
+	//fmt.Println("Token:",c.Result[0].UseAmount)
+
+	return c.Result[0].DataAmount,true
+
+}
+
+
+//
+//
+//flowPoolSharingInfo,_ := yidong_group_data_margin()
+//println("总量:",flowPoolSharingInfo.RemainAmount)
+//println("使用:",flowPoolSharingInfo.RemainAmount)
+//println("剩余:",flowPoolSharingInfo.RemainAmount)
+//
+//sim_data_usage,_ := yidong_sim_data_usage("1440761145498")
+//println("单卡使用量:",sim_data_usage)
+

+ 91 - 0
lib/Qiniu.go

@@ -0,0 +1,91 @@
+package lib
+
+// 存储相关功能的引入包只有这两个,后面不再赘述
+import (
+	"Cold_Api/conf"
+	"Cold_Api/logs"
+	"context"
+	"github.com/qiniu/go-sdk/v7/auth/qbox"
+	"github.com/qiniu/go-sdk/v7/storage"
+	uuid "github.com/satori/go.uuid"
+	"strconv"
+	"time"
+)
+
+var Qiniu *qbox.Mac
+
+// var (
+//
+//	//BUCKET是你在存储空间的名称
+//	accessKey = "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
+//	secretKey = "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
+//	BUCKET    = "bzdcoldoss"
+//
+// )
+func init() {
+	Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey)
+}
+
+// if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx","ofile/"+timeStr+".xlsx"){
+// c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
+// c.ServeJSON()
+// return
+// }
+func Pload_qiniu(localFile string, name string) bool {
+	//localFile := "C:\\Users\\Administrator\\Downloads\\kodo-browser-Windows-x64-v1.0.15.zip"
+	//key := "kodo-browser-Windows-x64-v1.0.15.zip"
+	// 自定义返回值结构体
+	type MyPutRet struct {
+		Key    string
+		Hash   string
+		Fsize  int
+		Bucket string
+		Name   string
+	}
+
+	//key := "your file save key"
+	// 使用 returnBody 自定义回复格式
+	putPolicy := storage.PutPolicy{
+		Scope:      conf.Qiniu_BUCKET,
+		ReturnBody: `{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}`,
+	}
+
+	upToken := putPolicy.UploadToken(Qiniu)
+	cfg := storage.Config{}
+	formUploader := storage.NewFormUploader(&cfg)
+	ret := MyPutRet{}
+	putExtra := storage.PutExtra{
+		Params: map[string]string{
+			"x:name": "github logo",
+		},
+	}
+	err := formUploader.PutFile(context.Background(), &ret, upToken, name, localFile, &putExtra)
+	if err != nil {
+		logs.Error("Pload_qiniu", err)
+		return false
+	}
+	logs.Println("七牛云", ret.Bucket, ret.Key, ret.Fsize, ret.Hash, ret.Name)
+	return true
+}
+
+func UploadToken(T_suffix string) string {
+	Tokey := strconv.FormatInt(time.Now().Unix(), 10) + uuid.NewV4().String()
+	if len(T_suffix) == 0 {
+		T_suffix = ".png"
+	}
+	putPolicy := storage.PutPolicy{
+		Scope:      conf.Qiniu_BUCKET,
+		InsertOnly: 1,    // 仅能以新增模式上传文件。
+		Expires:    7200, //示例2小时有效期
+		ReturnBody: `{"key":"` + conf.OssQiniu + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`,
+		//{"key":"github-x.png","hash":"FqKXVdTvIx_mPjOYdjDyUSy_H1jr","fsize":6091,"bucket":"if-pbl","name":"github logo"}
+		//{"key":"` + conf.Oss + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}
+		ForceSaveKey: true,
+		SaveKey:      "UpImage/" + Tokey + "." + T_suffix,
+		//FsizeLimit:   1024 * 1024 * 1,
+		MimeLimit: "image/*;application/pdf;application/octet-stream",
+	}
+
+	upToken := putPolicy.UploadToken(Qiniu)
+	return upToken
+}

+ 24 - 0
lib/ReplaceSQL.go

@@ -0,0 +1,24 @@
+package lib
+
+import "strings"
+
+// 过滤sql特殊字符
+func ReplaceSQL(name string) string {
+	name = strings.Replace(name, ";", "", -1)
+	name = strings.Replace(name, ",", "", -1)
+	name = strings.Replace(name, "?", "", -1)
+	name = strings.Replace(name, "<", "", -1)
+	name = strings.Replace(name, ">", "", -1)
+	name = strings.Replace(name, "(", "", -1)
+	name = strings.Replace(name, ")", "", -1)
+	name = strings.Replace(name, "@", "", -1)
+	name = strings.Replace(name, "=", "", -1)
+	name = strings.Replace(name, "+", "", -1)
+	name = strings.Replace(name, "*", "", -1)
+	name = strings.Replace(name, "&", "", -1)
+	name = strings.Replace(name, "#", "", -1)
+	name = strings.Replace(name, "%", "", -1)
+	name = strings.Replace(name, "$", "", -1)
+
+	return name
+}

+ 20 - 0
lib/WritePid.go

@@ -0,0 +1,20 @@
+package lib
+
+import (
+	"bufio"
+	"os"
+	"strconv"
+)
+
+func WritePid() {
+	fileName := "./server.pid"
+	file, _ := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0666)
+	defer file.Close()
+
+	writer := bufio.NewWriter(file)
+
+	pid := strconv.Itoa(os.Getpid())
+	println("server_pid:", pid)
+	writer.Write([]byte(pid))
+	writer.Flush()
+}

+ 417 - 0
lib/lib.go

@@ -0,0 +1,417 @@
+package lib
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/nats-io/nats.go"
+	"math/rand"
+	"os"
+	"path/filepath"
+	"runtime"
+
+	"sort"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var Run_My_Server = false // 运行当期服务
+
+var DeviceRealSnMap map[string]int /*创建集合 */
+var Nats *nats.Conn
+
+func init() {
+	DeviceRealSnMap = make(map[string]int)
+}
+
+type JSONS struct {
+	//必须的大写开头
+	Code int16
+	Msg  string
+	Data interface{} // 泛型
+}
+type R_JSONS_List struct {
+	//必须的大写开头
+	Data      []interface{}
+	Num       int64
+	Page      int
+	Page_size int
+}
+type R_JSONS struct {
+	//必须的大写开头
+	Data      interface{}
+	Num       int64
+	Page      int
+	Page_size int
+}
+
+type R1_JSONS struct {
+	//必须的大写开头
+	List      interface{}
+	Num       int
+	Page      int
+	Page_size int
+	Pages     []Page_T
+}
+
+// 登录验证
+//func Verification(GetCookie string, GetString string) (bool, Account.Admin) {
+//	Run_My_Server = true // 运行当期服务
+//	// 自适应 参数
+//	User_tokey := GetCookie
+//	if len(User_tokey) == 0 {
+//		User_tokey = GetString
+//	}
+//	if len(User_tokey) == 0 {
+//		return false, Account.Admin{}
+//	}
+//	tokey, is := Account.Redis_Tokey_Get(User_tokey)
+//	T_uuid := strings.Split(tokey, "|")[0]
+//	if !is {
+//		return false, Account.Admin{}
+//	}
+//	var err error
+//	admin_r, err := Account.Read_Admin_ByUuid(T_uuid)
+//	if err != nil {
+//		return false, Account.Admin{}
+//	}
+//	Admin_r = &admin_r
+//	log.Println("登录 Admin_name 为:", Admin_r.T_name)
+//	return true, admin_r
+//}
+
+// func_page 分页   [{3 1} {4 2} {4 3} {4 4} {4 5} {4 6} {4 7} {4 8} {4 9} {5 2}]-
+type Page_T struct {
+	A int
+	V int64
+}
+
+func Func_page(Page int64, Page_size int64) (page_t_list []Page_T) {
+	if Page > 1 {
+		page_t_list = append(page_t_list, Page_T{A: 1, V: Page - 1})
+	}
+	i := int64(0)
+	for aa := int64(1); aa < 5; aa++ {
+		if Page-aa <= 0 {
+			break
+		}
+		page_t_list = append(page_t_list, Page_T{A: 2, V: Page - aa})
+		i++
+	}
+	page_t_list = append(page_t_list, Page_T{A: 3, V: Page})
+
+	for aa := int64(1); aa < 10-i; aa++ {
+		if Page_size < Page+aa {
+			break
+		}
+		page_t_list = append(page_t_list, Page_T{A: 4, V: Page + aa})
+	}
+	sort.Slice(page_t_list, func(i, j int) bool {
+		if page_t_list[i].V < page_t_list[j].V {
+			return true
+		}
+		return false
+	})
+	sort.Slice(page_t_list, func(i, j int) bool {
+		if page_t_list[i].A < page_t_list[j].A {
+			return true
+		}
+		return false
+
+	})
+	if Page < Page_size {
+		page_t_list = append(page_t_list, Page_T{A: 5, V: Page + 1})
+	}
+
+	return page_t_list
+}
+
+func Strval(value interface{}) string {
+	var key string
+	if value == nil {
+		return key
+	}
+
+	switch value.(type) {
+	case float64:
+		ft := value.(float64)
+		key = strconv.FormatFloat(ft, 'f', -1, 64)
+	case float32:
+		ft := value.(float32)
+		key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
+	case int:
+		it := value.(int)
+		key = strconv.Itoa(it)
+	case uint:
+		it := value.(uint)
+		key = strconv.Itoa(int(it))
+	case int8:
+		it := value.(int8)
+		key = strconv.Itoa(int(it))
+	case uint8:
+		it := value.(uint8)
+		key = strconv.Itoa(int(it))
+	case int16:
+		it := value.(int16)
+		key = strconv.Itoa(int(it))
+	case uint16:
+		it := value.(uint16)
+		key = strconv.Itoa(int(it))
+	case int32:
+		it := value.(int32)
+		key = strconv.Itoa(int(it))
+	case uint32:
+		it := value.(uint32)
+		key = strconv.Itoa(int(it))
+	case int64:
+		it := value.(int64)
+		key = strconv.FormatInt(it, 10)
+	case uint64:
+		it := value.(uint64)
+		key = strconv.FormatUint(it, 10)
+	case string:
+		key = value.(string)
+	case []byte:
+		key = string(value.([]byte))
+	default:
+		newValue, _ := json.Marshal(value)
+		key = string(newValue)
+	}
+
+	return key
+}
+
+func To_int(value interface{}) int {
+	var key int
+	if value == nil {
+		return key
+	}
+	switch value.(type) {
+	case float64:
+		key = int(value.(float64))
+	case float32:
+		key = int(value.(float32))
+	case int:
+		key = int(value.(int))
+	case uint:
+		key = int(value.(uint))
+	case int8:
+		key = int(value.(int8))
+	case uint8:
+		key = int(value.(uint8))
+	case int16:
+		key = int(value.(int16))
+	case uint16:
+		key = int(value.(uint16))
+	case int32:
+		key = int(value.(int32))
+	case uint32:
+		key = int(value.(uint32))
+	case int64:
+		key = int(value.(int64))
+	case uint64:
+		key = int(value.(uint64))
+	case string:
+		key, _ = strconv.Atoi(value.(string))
+	case []byte:
+		key, _ = strconv.Atoi(string(value.([]byte)))
+	default:
+		newValue, _ := json.Marshal(value)
+		key, _ = strconv.Atoi(string(newValue))
+	}
+	return key
+}
+
+func To_float32(value interface{}) float32 {
+	var key float32
+	if value == nil {
+		return key
+	}
+
+	switch value.(type) {
+	case float64:
+		key = float32(value.(float64))
+	case float32:
+		key = float32(value.(float32))
+	case int:
+		key = float32(value.(int))
+	case uint:
+		key = float32(value.(uint))
+	case int8:
+		key = float32(value.(int8))
+	case uint8:
+		key = float32(value.(uint8))
+	case int16:
+		key = float32(value.(int16))
+	case uint16:
+		key = float32(value.(uint16))
+	case int32:
+		key = float32(value.(int32))
+	case uint32:
+		key = float32(value.(uint32))
+	case int64:
+		key = float32(value.(int64))
+	case uint64:
+		key = float32(value.(uint64))
+	case string:
+		key_float64, _ := strconv.ParseFloat(value.(string), 32/64)
+		key = float32(key_float64)
+	case []byte:
+		key_float64, _ := strconv.ParseFloat(string(value.([]byte)), 32/64)
+		key = float32(key_float64)
+	default:
+		newValue, _ := json.Marshal(value)
+		key_float64, _ := strconv.ParseFloat(string(newValue), 32/64)
+		key = float32(key_float64)
+	}
+
+	key_float64, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", key), 32/64)
+	key = float32(key_float64)
+
+	return key
+}
+
+func To_string(value interface{}) string {
+	var key string
+	if value == nil {
+		return key
+	}
+
+	switch value.(type) {
+	case float64:
+		ft := value.(float64)
+		key = strconv.FormatFloat(ft, 'f', -1, 64)
+	case float32:
+		ft := value.(float32)
+		key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
+	case int:
+		it := value.(int)
+		key = strconv.Itoa(it)
+	case uint:
+		it := value.(uint)
+		key = strconv.Itoa(int(it))
+	case int8:
+		it := value.(int8)
+		key = strconv.Itoa(int(it))
+	case uint8:
+		it := value.(uint8)
+		key = strconv.Itoa(int(it))
+	case int16:
+		it := value.(int16)
+		key = strconv.Itoa(int(it))
+	case uint16:
+		it := value.(uint16)
+		key = strconv.Itoa(int(it))
+	case int32:
+		it := value.(int32)
+		key = strconv.Itoa(int(it))
+	case uint32:
+		it := value.(uint32)
+		key = strconv.Itoa(int(it))
+	case int64:
+		it := value.(int64)
+		key = strconv.FormatInt(it, 10)
+	case uint64:
+		it := value.(uint64)
+		key = strconv.FormatUint(it, 10)
+	case string:
+		key = value.(string)
+	case []byte:
+		key = string(value.([]byte))
+	default:
+		newValue, _ := json.Marshal(value)
+		key = string(newValue)
+	}
+	return key
+}
+
+func Random(min, max int) int {
+	rand.Seed(time.Now().Unix()) //Seed生成的随机数
+	return rand.Intn(max-min) + min
+}
+
+// 取文本(字符串)中间
+func GetBetweenStr(str, start, end string) string {
+	n := strings.Index(str, start)
+	if n == -1 {
+		n = 0
+	} else {
+		n = n + len(start) // 增加了else,不加的会把start带上
+	}
+	str = string([]byte(str)[n:])
+	m := strings.Index(str, end)
+	if m == -1 {
+		m = len(str)
+	}
+	str = string([]byte(str)[:m])
+	return str
+}
+
+// getYearMonthToDay 查询指定年份指定月份有多少天
+// @params year int 指定年份
+// @params month int 指定月份
+func GetYearMonthToDay(year int, month int) int {
+	// 有31天的月份
+	day31 := map[int]bool{
+		1:  true,
+		3:  true,
+		5:  true,
+		7:  true,
+		8:  true,
+		10: true,
+		12: true,
+	}
+	if day31[month] == true {
+		return 31
+	}
+	// 有30天的月份
+	day30 := map[int]bool{
+		4:  true,
+		6:  true,
+		9:  true,
+		11: true,
+	}
+	if day30[month] == true {
+		return 30
+	}
+	// 计算是平年还是闰年
+	if (year%4 == 0 && year%100 != 0) || year%400 == 0 {
+		// 得出2月的天数
+		return 29
+	}
+	// 得出2月的天数
+	return 28
+}
+
+func Decimal(value float64) float64 {
+	value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64)
+	return value
+}
+
+func Strconv_Atoi(string string) int {
+	int, _ := strconv.Atoi(string)
+	return int
+}
+
+// golang获取程序运行路径
+func GetCurrentDirectory() string {
+	dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
+
+	return strings.Replace(dir, "\\", "/", -1)
+}
+
+// 获取正在运行的函数名
+func FuncName() string {
+	pc := make([]uintptr, 1)
+	runtime.Callers(2, pc)
+	f := runtime.FuncForPC(pc[0])
+	return f.Name()
+}
+
+// 获取两个时间相差的天数,0表同一天,正数表t1>t2,负数表t1<t2
+func GetDiffDays(t1, t2 time.Time) int {
+	t1 = time.Date(t1.Year(), t1.Month(), t1.Day(), 0, 0, 0, 0, time.Local)
+	t2 = time.Date(t2.Year(), t2.Month(), t2.Day(), 0, 0, 0, 0, time.Local)
+
+	return int(t1.Sub(t2).Hours() / 24)
+}

+ 91 - 0
lib/libString.go

@@ -0,0 +1,91 @@
+package lib
+
+import (
+	"crypto/md5"
+	"encoding/hex"
+	"math/rand"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// #取得随机字符串:通过打乱slice来操作
+func GetRandstring(length int, char string, rand_x int64) string {
+	if length < 1 {
+		return ""
+	}
+
+	if len(char) <= 6 || len(char) <= length {
+		char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+	}
+
+	charArr := strings.Split(char, "")
+	ran := rand.New(rand.NewSource(time.Now().Unix() + rand_x))
+
+	l := len(charArr)
+	for i := l - 1; i > 0; i-- {
+		r := ran.Intn(i)
+		charArr[r], charArr[i] = charArr[i], charArr[r]
+	}
+	rchar := charArr[:length]
+	return strings.Join(rchar, "")
+}
+
+// 返回一个32位md5加密后的字符串
+func Md5(str string) string {
+	h := md5.New()
+	h.Write([]byte(str))
+	return hex.EncodeToString(h.Sum(nil))
+}
+
+// 转化
+func TimeStrToTime(T_time string) (time.Time, bool) {
+
+	stamp, err := time.Parse("2006-01-02 15:04:05", T_time)
+
+	if err != nil {
+		return time.Time{}, false
+	}
+
+	return stamp, true
+}
+
+func SplitStringIds(str string, prefix string) (r []string) {
+	Ids_str := strings.TrimRight(str, "|")
+	Ids := strings.Split(Ids_str, "|")
+	for _, v := range Ids {
+		r = append(r, strings.TrimLeft(v, prefix))
+	}
+	return r
+}
+
+func SplitStringToDotStr(str string, prefix string) (r string) {
+	Ids_str := strings.TrimRight(str, "|")
+	Ids := strings.Split(Ids_str, "|")
+	for _, v := range Ids {
+		r += strings.TrimLeft(v, prefix) + ","
+	}
+	r = strings.TrimRight(r, ",")
+	return r
+}
+
+func SplitStringToIntIds(str string, prefix string) (r []int) {
+	Ids_str := strings.TrimRight(str, "|")
+	Ids := strings.Split(Ids_str, "|")
+	for _, v := range Ids {
+		id, _ := strconv.Atoi(strings.TrimLeft(v, prefix))
+		r = append(r, id)
+	}
+	return r
+}
+
+func IntIdsDistinct(Ids []int) (result []int) {
+	distinctMap := make(map[int]int, len(Ids))
+	for _, Id := range Ids {
+		if _, ok := distinctMap[Id]; !ok {
+			distinctMap[Id] = 1
+			result = append(result, Id)
+		}
+	}
+	return result
+}