big

package
v0.0.0-...-6e28af7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

编码操作

网络请求操作

程序操作

字符串操作

结构体操作

系统操作

时间操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnCodeAes

func EnCodeAes(src, key []byte, encryptionMode string, paddingMode int, iv []byte) ([]byte, error)

EnCodeAes AES加密 传参:

src:欲加密的数据
key:加密秘钥,长度为16的倍数
encryptionMode:加密模式,可选值CBC、CTR、OFB、CFB
paddingMode:填充方式,可选值0=pkcs5padding、1=pkcs7padding、2=zeropadding、3=no padding
iv:偏移量,为空默认使用key生成iv

返回:

参数1:加密结果
参数2:错误信息

func EnCodeAesUn

func EnCodeAesUn(src, key []byte, encryptionMode string, paddingMode int, iv []byte) ([]byte, error)

EnCodeAesUn AES解密 传参:

src:欲解密的数据
key:解密秘钥,长度为16的倍数
encryptionMode:解密模式,可选值CBC、CTR、OFB、CFB
paddingMode:填充方式,可选值0=pkcs5padding、1=pkcs7padding、2=zeropadding、3=no padding
iv:偏移量,为空默认使用key生成iv

返回:

参数1:解密结果
参数2:错误信息

func EnCodeAnsiToUnicode

func EnCodeAnsiToUnicode(ansi string) string

编码Ansi到Unicode(ansi的字符串) 返回Unicode字符串

func EnCodeAnsiToUsc2

func EnCodeAnsiToUsc2(ansi string) string

编码Ansi转Usc2(ansi的字符串) 返回Usc2字符串

func EnCodeBase64

func EnCodeBase64(dst []byte) []byte

将字节集进行Base64编码,返回编码后的字节集

func EnCodeBase64Pro

func EnCodeBase64Pro(s []byte, mode int) string

EnCodeBase64Pro BASE64编码终极版 传参:

s:欲编码的字节集数据
mode:编码模式,0=标准编码、1=标准+URL编码(将"/"=>"_","+"=>"-"替换)、2=标准+Raw编码(不进行尾部填充(=)到4的倍数)、4=URL+RAW编码

返回:

结果

func EnCodeBase64ProUn

func EnCodeBase64ProUn(bs64 string, mode int) []byte

EnCodeBase64ProUn BASE64解码终极版 传参:

bs64:欲解码的base64格式字符串
mode:编码模式,0=标准编码、1=标准+URL编码(将"/"=>"_","+"=>"-"替换)、2=标准+Raw编码(不进行尾部填充(=)到4的倍数)、4=URL+RAW编码

返回:

结果

func EnCodeBase64Str

func EnCodeBase64Str(dst string) string

将字符串进行Base64编码,返回编码后的字符串

func EnCodeBase64StrUn

func EnCodeBase64StrUn(s string) (string, error)

将Base64编码的字符串进行解码,返回解码后的字符串

func EnCodeBase64Un

func EnCodeBase64Un(s []byte) ([]byte, error)

将Base64编码的字节集进行解码,返回解码后的字节集

func EnCodeBig5ToUtf8

func EnCodeBig5ToUtf8(orig []byte) ([]byte, error)

编码BIG5到UTF8(BIG5 字节集) 返回UTF8 字节集, 错误信息 error

func EnCodeCompressZlibData

func EnCodeCompressZlibData(resources []byte, level int) ([]byte, error)

EnCodeCompressZlibData 基于Zlib压缩数据 传参:

resources:欲压缩的数据
level:压缩等级,-1=默认压缩、-2=仅适用于Huffman编码的压缩策略、0=无压缩、1=速度优先、9=体积优先

返回:

参数1:压缩后的数据
参数2:错误信息

func EnCodeCompressZlibDataUn

func EnCodeCompressZlibDataUn(resources []byte) ([]byte, error)

EnCodeCompressZlibDataUn 基于Zlib解压数据 传参:

resources:欲解缩的数据

返回:

参数1:解压后的数据
参数2:错误信息

func EnCodeGbkToUtf8

func EnCodeGbkToUtf8(orig []byte) ([]byte, error)

编码GBK到UTF8(GBK 字节集) 返回UTF8 字节集, 错误信息 error

func EnCodeRsa

func EnCodeRsa(publicKey string, str string, ver int, hashTyp int) string

EnCodeRsa RSA加密 传参:

publicKey:Base64编码的公钥
str:欲加密的数据
ver:加密协议标准,0=PKCS1v15,1=OAEP,2=OAEP兼容版(当OAEP1不行时可以试试2)
hashTyp:哈希算法,ver为OAEP时,本参数生效,0=sha1,1=sha256,2=sha512,3=md5

返回:

加密后的结果

func EnCodeRsaSign

func EnCodeRsaSign(privateKey string, str string, parseMode int, ver int, hashTyp int) string

EnCodeRsaSign RSA数据签名

privateKey:Base64编码的私钥
str:欲签名的数据
parseMode:解析模式:0=PKCS1,1=PKCS8,2=EC
ver:加密协议标准,0=PKCS1v15,1=OAEP,2=OAEP兼容版(当OAEP1不行时可以试试2)
hashTyp:哈希算法,0=sha1,1=sha256,2=sha512,3=md5

返回:

签名

func EnCodeRsaSignCheck

func EnCodeRsaSignCheck(publicKey string, signature string, str string, ver int, hashTyp int) error

EnCodeRsaSignCheck 效验RSA签名是否正确 传参:

publicKey:Base64编码的公钥
signature:Base64编码的签名
str:欲签名的数据
ver:加密协议标准,0=PKCS1v15,1=OAEP,2=OAEP兼容版(当OAEP1不行时可以试试2)
hashTyp:哈希算法,ver为OAEP时,本参数生效,0=sha1,1=sha256,2=sha512,3=md5

返回:

err:为nil=效验成功,非nil=效验失败

func EnCodeRsaUn

func EnCodeRsaUn(privateKey string, str string, parseMode int, ver int, hashTyp int) string

EnCodeRsaUn RSA解密 传参:

privateKey:Base64编码的私钥
str:欲解密的数据
parseMode:解析模式:0=PKCS1,1=PKCS8,2=EC
ver:加密协议标准,0=PKCS1v15,1=OAEP,2=OAEP兼容版(当OAEP1不行时可以试试2)
hashTyp:哈希算法,ver为OAEP时,本参数生效,0=sha1,1=sha256,2=sha512,3=md5

返回:

加密后的结果

func EnCodeUnicodeToAnsi

func EnCodeUnicodeToAnsi(unicode string) string

编码Unicode到Ansi(unicode的字符串) 返回Ansi字符串

func EnCodeUrl

func EnCodeUrl(str string) string

将字符串进行URL编码 返回编码后的字符串

func EnCodeUrlUn

func EnCodeUrlUn(str string) string

将字符串进行URL解码,返回解码后的字符串

func EnCodeUsc2ToAnsi

func EnCodeUsc2ToAnsi(usc2 string) string

编码Usc2转Ansi(usc2的字符串) 返回Ansi字符串

func EnCodeUtf8ToBig5

func EnCodeUtf8ToBig5(orig []byte) ([]byte, error)

编码UTF-8到BIG5(UTF-8 字节集) 返回BIG5 字节集, 错误信息 error

func EnCodeUtf8ToGbk

func EnCodeUtf8ToGbk(orig []byte) ([]byte, error)

编码UTF8到GBK(UTF8 字节集) 返回GBK 字节集, 错误信息 error

func HttpCookiesToStr

func HttpCookiesToStr(cookies []*http.Cookie) string

将http的[]Cookie类型转为Cookies字符串

func HttpForward

func HttpForward(hp *HttpParms) (resStr string, resByte []byte, cookies string, headers string, err error)

* 【本函数已废弃,HttpSend函数已兼容转发】转发Http请求 将本请求转发到其他Windows服务器进行处理,其他Windows服务器需安装配套的服务(下载链接:https://pan.baidu.com/s/1NLN4Gbc4nfhbwcRI9DnmTw 提取码:712b) 由于Go自带的Http库不支持Http/1.0,故此本功能诞生,兼容Http/1.0 本函数需要填写HttpParms结构体中的ForwardHost和ForwardPwd属性值 另外需注意如果提交[]byte数据(原本为string转的[]byte是支持的)或请求响应的是[]byte数据本函数可能不兼容 传参:

hp:传递HttpParms对象指针,HttpParms对象属性字段用于填写请求参数

返回:

resStr:响应文本结果
resByte:响应字节集结果
cookies:提交时的cookies和服务响应cookies合并后的最新cookies
headers:响应的headers
err:错误信息

func HttpGetCookie

func HttpGetCookie(cookies string, name string) string

* 获取单个Cookie值 传参:

cookies:全部Cookies字符串
name:欲获取的Cookie名称

返回:

cookie的值,若cookie不存在则返回空文本

func HttpGzipPack

func HttpGzipPack(data []byte) []byte

Gzip压缩:传入准备压缩的数据,返回压缩后的数据

func HttpGzipUn

func HttpGzipUn(data []byte) []byte

Gzip解压,传入准备解压的数据,返回解压后的数据

func HttpMergeCookies

func HttpMergeCookies(oldCookies string, newCookies string) string

合并文本Cookies,返回合并后的文本Cookies

func HttpSend

func HttpSend(hp *HttpParms) (resStr string, resByte []byte, cookies string, err error)

HttpSend 发送Http请求 传参:

hp:传递HttpParms对象指针,HttpParms对象属性字段用于填写请求参数

返回:

resStr:响应文本结果
resByte:响应字节集结果
cookies:提交时的cookies和服务响应cookies合并后的最新cookies
err:错误信息

func PicOcrBaidu

func PicOcrBaidu(apiKey string, secretKey string, imgBase64 string) string

* 图片识别文字【百度接口】 注册登录后打开创建APP:https://console.bce.baidu.com/ai/#/ai/ocr/overview/index 传参:

apiKey:百度的API Key
secretKey:百度的Secret Key
imgBase64:需要识别的图片,请传入Base64编码后的字符串

返回:

识别结果,识别失败返回空字符串

func PicOcrYouDao

func PicOcrYouDao(imgBase64 string) string

* 图片识别文字【有道接口】 传参:

imgBase64:需要识别的图片,请传入Base64编码后的字符串

返回:

识别结果,识别失败返回空字符串

func ProgCurrencyRateGet

func ProgCurrencyRateGet(srcCode string, toCode string) (srcName string, toName string, rate float64, err error)

ProgCurrencyRateGet 取币种汇率 传参:

srcCode:原始币种
toCode:欲转换币种

返回:

srcName:原始币种中文名称
toName:欲转换币种中文名称
rate:汇率,使用方法,原始金额*汇率=转换币种金额
err:错误信息

func ProgLenRand

func ProgLenRand(lens int, randtype int) string

ProgLenRand 取随机指定位数数字 传入:

len:欲取随机数长度
randtype: 单双选择,0=不限制单双,1=取单,2=取双

返回:

随机数字

func ProgRandChar

func ProgRandChar(len int, typ int, punctuation bool) string

ProgRandChar 取随机生成指定长度字符串 传参:

len:想要生成的长度
typ:0=不限制、1=只生成数字、2=只生成大写字母、3=只生成小写字母
punctuation:是否掺杂标点符号,false=不加,true=加,当typ为0时本参数有效,否则强行为false

返回:

字符串结果

func ProgRandChineseChar

func ProgRandChineseChar(len int) string

ProgRandChineseChar 取随机指定位数汉字 传入:

len:欲取随机数长度

返回:

随机数字

func ProgRangeRand

func ProgRangeRand(min int, max int, randtype int) int

ProgRangeRand 取随机范围数字 传入:

min:起始数
max:结束数
randtype: 单双选择,0=不限制单双,1=取单,2=取双

返回:

随机数字

func ProgRound

func ProgRound(number float64) float64

ProgRound 四舍五入取整 传参:

number:需要四舍五入的小数

返回:

四舍五入后的整数,是float64类型

func StrCompressZlib

func StrCompressZlib(v string) (string, error)

StrCompressZlib 基于Zlib的文本压缩 传参:

v:欲压缩的文本

返回:

参数1:压缩后的数据,base64编码
参数2:错误信息

func StrCompressZlibUn

func StrCompressZlibUn(v string) (string, error)

StrCompressZlibUn 基于Zlib的文本解压 传参:

v:欲解压的Base64编码数据

返回:

参数1:解压后的文本
参数2:错误信息

func StrDelEmpty

func StrDelEmpty(str string) string

StrDelEmpty 删除文本中的空格和Tab符和换行 传参:

str:欲处理的字符串

返回:

结果

func StrFormKeyValGet

func StrFormKeyValGet(s string) map[string]string

StrFormKeyValGet 表单参数参数值提取 传参:

s:表单开始的form节点

返回:

map类型的键值对,key=参数名,val=参数值

func StrGenerateCreditCard

func StrGenerateCreditCard(cardType int, length int) string

StrGenerateCreditCard 随机生成指定组织的信用卡 传参:

cardType:欲生成的卡组织,0=VISA,1=MASTERCARD,2=AMEX,3=DISCOVER,4=DINERS,5=ENROUTE,6=JCB,7=VOYAGER
length:卡长度,VISA/MASTERCARD/DISCOVER/JCB=16,AMEX/ENROUTE/VOYAGER=15,DINERS=14,VISA=13,注:VISA有16和13两种长度

返回:

结果

func StrGetLeft

func StrGetLeft(orig string, findStr string) string

* 文本取左边(被查找的文本 string, 欲寻找的文本 string) 返回取到的文本 string eg:StrGetLeft("123456", "4") 取4的左边,返回"123",没取到则返回空文本。

func StrGetLetter

func StrGetLetter(orig string) string

* 文本只取字母(不区分大小写),过滤其他字符串 传参:

orig:原始文本

返回:

字符串中的字母

func StrGetNum

func StrGetNum(orig string) string

* 文本只取数字,过滤其他字符串 传参:

orig:原始文本

返回:

字符串中的数字

func StrGetRight

func StrGetRight(orig string, findStr string) string

* 文本取右边(被查找的文本 string, 欲寻找的文本 string) 返回取到的文本 string eg:StrGetRight("123456", "4") 取4的右边,返回"56",没取到则返回空文本。

func StrGetSub

func StrGetSub(orig string, first string, last string) string

* 文本取中间(被查找的文本 string, 前面文本 string, 后面文本 string) 返回取到的文本 string eg:StrGetSub("123456", "12", "56") 取12和56的中间文本,返回"34",没取到则返回空文本。

func StrGetSubBatch

func StrGetSubBatch(orig string, first string, last string) []string

* 批量取文本中间(被查找的文本 string, 前面文本 string, 后面文本 string) 返回取到的文本切片[]string 取所有符合条件的文本并返回

func StrReverse

func StrReverse(s string) string

StrReverse 反转字符串 传参:

s:欲反向的字符串

返回:

结果

func StrSplitChinese

func StrSplitChinese(orig string, resArray *[]string) int

* 文本逐字分割(需要分割的文本 string, 返回结果数组指针 *[]string)返回结果数组成员数 int 将指定文本,逐字分割成数组,保存为指定的变量数组中,返回成员个数,可识别换行符及全半角字符和汉字

func StrToHex

func StrToHex(str string, toHex bool) string

StrToHex 将字符串与十六进制互转 传参:

str:欲转换的字符串
toHex:是否字符串转十六进制,true=字符串转十六进制,false=十六进制转字符串

返回:

结果

func StrToString

func StrToString(obj interface{}) string

* 将任意类型对象转为string 传参:

obj:任意类型变量

返回:

转换后的字符串,转换失败返回空字符串

func StuGetFieldVal

func StuGetFieldVal(stu interface{}, field string) (val interface{}, success bool)

* 快速获取结构体属性字段的值 传参:

stu:传入结构体指针
field:模糊字段名称,可以是属性字段全称或部分字符串,也可以是属性字段json标签值的全值或部分字符串

返回:

val:获取到的值,拿到该值后需val.(原类型)转换为原类型使用
success:获取成功为true,失败为false

func StuSetFieldVal

func StuSetFieldVal(stu interface{}, field string, val interface{}) bool

* 快速设置结构体属性字段的值,设置成功返回true,失败返回false stu:传入结构体指针 field:模糊字段名称,可以是属性字段全称或部分字符串,也可以是属性字段json标签值的全值或部分字符串 val:用作替换的值

func SysGetCpuInfo

func SysGetCpuInfo() (num int, arch string)

取系统CPU信息,返回核心数和架构

func SysGetType

func SysGetType() (arch string, os string)

取系统类型,返回系统架构和系统平台

func SysKeyCode

func SysKeyCode(key string) int

SysKeyCode 取键码 传参:

key:欲取的键码

返回:

键代码

func SysPortInUse

func SysPortInUse(port int) bool

* 端口是否被占用 传参:

port:端口号

返回:

占用=true,没占用=false

func SysPortToPid

func SysPortToPid(port int) int

* 通过端口号找进程PID 传参:

port:端口号

返回:

进程PID,没找到返回-1

func SysWinProcessGetPID

func SysWinProcessGetPID(name string) []int

SysWinProcessGetPID Windows系统下通过进程名取进程ID,也可用于判断进程是否存在 返回:

成功返回进程ID数组,失败数组成员为空

func SysWinProcessKill

func SysWinProcessKill(name string, pid int) bool

SysWinProcessKill Windows系统强制终止经常 传参(二选一传入):

name:欲终止进程名
pid:欲终止进程PID

返回:

成功返回真,失败返回假

func TimeCalculateAge

func TimeCalculateAge(birthday time.Time, referenceTime time.Time) int

计算年龄 精度到日期,时分秒不作为计算条件 传参:

birthday:生日
referenceTime:参照时间,以该时间为基准计算年龄

返回:

年龄

func TimeFastGet

func TimeFastGet(addTime bool) string

* 时间常规格式化,返回现在时间的yyyy-MM-dd hh:mm:ss 24小时制的格式字符串 传参:

addTime:是否添加时间,为true则返回带有时分秒的字符串,否则只返回年月日

返回:

日期时间的字符串

func TimeSleepRangeRand

func TimeSleepRangeRand(min int, max int, duration time.Duration)

* 随机范围延迟 传参:

min:起始数
max:结束数
duration:时间单位,毫秒=time.Millisecond,秒=time.Second,分钟=time.Minute,小时=time.Hour

func TimeStamp

func TimeStamp(lens int) (string, int64)

* 取现行时间戳 传参:

lens:要取的时间戳长度,秒级为10位,毫秒级为13位,纳秒级为19位.

返回2参数:

参数1:string类型的时间戳
参数2:int64类型的时间戳

Types

type HttpParms

type HttpParms struct {
	Url               string      `json:"url"`                   //请求地址
	Mode              string      `json:"mode"`                  //提交方式:GET POST HEAD PUT OPTIONS DELETE TRACE CONNECT PATCH
	DataStr           string      `json:"data_str"`              //提交字符串数据,POST方式本参数有效,Data与DataByte参数二选一传入即可。
	DataByte          []byte      `json:"data_byte"`             //提交字节集数据,POST方式本参数有效,Data与DataByte参数二选一传入即可。
	Cookies           string      `json:"cookies"`               //附加Cookies,把浏览器中开发者工具中Cookies复制传入即可
	Headers           string      `json:"headers"`               //附加协议头,直接将浏览器抓包的协议头复制下来传入即可,无需调整格式,User-Agent也是在此处传入,如果为空默认为Chrome的UA。
	RetHeaders        http.Header `json:"ret_headers"`           //返回协议头,http.Header类型,需导入"net/http"包,返回协议头的参数通过本变量.Get(参数名 string)获取
	RetStatusCode     int         `json:"ret_status_code"`       //返回状态码
	DisableSSLVerify  bool        `json:"disable_ssl_verify"`    //禁用SSL证书效验,部分https请求提示证书错误,可置为True
	Redirect          bool        `json:"redirect"`              //是否禁止重定向,true为禁止重定向
	ProxyType         string      `json:"proxy_type"`            //代理IP类型:http、socks5,为空默认为http
	ProxyIP           string      `json:"proxy_ip"`              //代理IP,格式IP:端口,如:127.0.0.1:8888
	ProxyUser         string      `json:"proxy_user"`            //代理IP账户
	ProxyPwd          string      `json:"proxy_pwd"`             //代理IP密码
	TimeOut           int         `json:"time_out"`              //超时时间,单位:秒,默认30秒,如果提供大于0的数值,则修改操作超时时间
	RetryCount        int         `json:"retry_count"`           //重试次数,适用于代理IP不稳定造成的偶尔访问失败的自动重试
	AutoFormatEnter   bool        `json:"auto_format_enter"`     //是否将提交的数据内容的换行强制转为\r\n格式,当提交有换行数据有问题时,将此项设为true
	ForwardHost       string      `json:"forward_host"`          //欲转发到的主机,格式:ip:端口,本属性仅用于HttpForward函数有效
	ForwardPwd        string      `json:"forward_pwd"`           //授权访问密码,本属性仅用于HttpForward函数有效
	IsCanonicalHeader bool        `json:"is_canonical_header"`   //header是否首字母大写,默认为false=首字母大写,true=原始字符串传递
	IsHookUserAgentPF int         `json:"is_hook_user_agent_pf"` //是否随机UserAgent,开启后可对抗普通防Bot系统:0=关闭,1=桌面端UA,2=移动端UA
	IsHookNetworkPF   bool        `json:"is_hook_network_pf"`    //是否篡改网络协议指纹,开启后可对抗知名CND的防Bot系统
}

HttpParms 请求结构体参数

type ProgMouseMoveXY

type ProgMouseMoveXY struct {
	X     int //横坐标
	Y     int //纵坐标
	Sleep int //延迟毫秒
}

ProgMouseMoveXY 鼠标移动坐标结构体

func ProgMouseMoveBionicX

func ProgMouseMoveBionicX(mouseX int) (XYArr []ProgMouseMoveXY)

ProgMouseMoveBionicX 计算鼠标横向移动仿生轨迹 传参:

mouseX:横向坐标

返回:

type WanIp

type WanIp struct {
	Ip        string `json:"cip"`      //ip地址
	AdminCode string `json:"cid"`      //邮政编码
	Region    string `json:"cname"`    //城市信息
	Operator  string `json:"operator"` //运营商
}

func SysGetWanIp

func SysGetWanIp() WanIp

SysGetWanIp 取外网IP

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL