123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package common
- import (
- "crypto/md5"
- "encoding/hex"
- "fmt"
- "git.listensoft.net/tool/jspkit/common/lxhttp"
- "git.listensoft.net/tool/jspkit/common/variable"
- "git.listensoft.net/tool/jspkit/taxerr"
- "github.com/go-kratos/kratos/v2/log"
- "github.com/tidwall/gjson"
- "io"
- "net/url"
- "os"
- "regexp"
- "strings"
- )
- type LvName string
- const (
- CheckSuccess LvName = "申报成功" // 检查成功 ------ 检查完全通过
- CheckFail LvName = "检查失败" // 检查任务失败 ----- 网页打开失败等
- CheckOmit LvName = "有遗漏" // 检查有遗漏 ----- 未申报问题
- CheckAbnormal LvName = "有异常" //检查有异常 ----- 税款问题
- )
- func GeneratePath(suffix string) string {
- ps := os.PathSeparator
- //检查路径
- if !PathExists("captcha" + string(ps)) {
- _ = os.MkdirAll("captcha"+string(ps), os.ModePerm)
- }
- return "captcha" + string(ps) + GetTimestamp(13) + "." + suffix
- }
- func PathExists(path string) bool {
- _, err := os.Stat(path)
- if err == nil {
- return true
- }
- if os.IsNotExist(err) {
- return false
- }
- return false
- }
- // 返回一个32位md5加密后的字符串
- func Md5(data string) string {
- h := md5.New()
- h.Write([]byte(data))
- return hex.EncodeToString(h.Sum(nil))
- }
- /*
- 生成检查截图本地路径
- lv 图片对应的错误等级 用上面定义好的 Omit>Abnormal
- taxNo 税号
- period 账期
- location 截图位置,例如申报清册、申报结果查询、税款缴纳、缴费缴纳查询
- */
- func GenerateCheckImagePath(lv LvName, taxNo, period, location string) string {
- var path string
- path = "./data/check/" + taxNo + "/"
- if !PathExists(path) {
- os.MkdirAll(path, os.ModePerm)
- }
- return fmt.Sprintf(`%s-%s-%s-新版_%s_%s.png`, path+taxNo, period, GetTimestamp(13), location, lv)
- }
- func PostSbjt(taxno, period, path string) string {
- var params = map[string]string{
- "tax_no": taxno,
- "period": period,
- "type": "etax", //电子税务局
- }
- str, err := PostFile("https://file.listensoft.net/api/v1/uploadsbjt", map[string]string{
- "file": path,
- }, params)
- if err != nil {
- log.Warnf("【%s】文件上传失败", path)
- }
- return gjson.GetBytes(str, "path").String()
- }
- // 获取申报截图的path
- // taxNo 纳税人识别号 period 账期 taxType 任务名称
- func GetSbjtPath(taxNo, period string, taxType variable.TaskName) string {
- var path string
- path = "./data/" + taxNo + "/"
- if !PathExists(path) {
- os.MkdirAll(path, os.ModePerm)
- }
- path = path + period + string(taxType) + "_" + GetTimestamp(13) + ".png"
- return path
- }
- // 判断字符串是否全是英文
- func IsAllEnglish(s string) bool {
- // 检查字符串是否全部由ASCII字符组成
- for _, c := range s {
- if c > 127 {
- return false
- }
- }
- return true
- }
- // CreateFormReader 将 map 转换成 header
- func CreateFormReader(data map[string]string) io.Reader {
- form := url.Values{}
- for k, v := range data {
- form.Add(k, v)
- }
- return strings.NewReader(form.Encode())
- }
- func Unbracket(str string) string {
- str = strings.ReplaceAll(str, "(", "(")
- str = strings.ReplaceAll(str, ")", ")")
- str = strings.ReplaceAll(str, " ", "")
- return str
- }
- // 检查是否是手机号
- func CheckMobile(mobile string) bool {
- r := regexp.MustCompile(`^1[0-9]{10}$`)
- return r.Match([]byte(mobile))
- }
- func NewWebStuckTitle() *taxerr.SystemErr {
- return taxerr.NewSystemV3("电子税局页面卡顿", "系统将于30分钟后重试(可在\"通用设置\"关闭)")
- }
- // 查看设备是否在线
- func CheckEqmLive(tel string) bool {
- client := lxhttp.NewHttpClient()
- defer client.CloseIdleConnections()
- bys, err := lxhttp.POSTJson(client, "https://keep.jsptax.com"+"/api/v1/telDeviceStatus", map[string]string{"mobiles": tel}, map[string]string{})
- if err != nil {
- return false
- }
- if gjson.GetBytes(bys, `data.status`).Bool() {
- return true
- }
- return false
- }
|