Browse Source

邮箱更换

WH01243 3 năm trước cách đây
mục cha
commit
f2525a85b2
3 tập tin đã thay đổi với 93 bổ sung12 xóa
  1. 4 3
      invoice/src/config.json
  2. 1 0
      invoice/src/main.go
  3. 88 9
      invoice/src/util/push.go

+ 4 - 3
invoice/src/config.json

@@ -11,9 +11,9 @@
     "SealCode":"4002",
     "TimingCron":"0/10 * * * * ?",
     "OpenTimingCron":"0/30 * * * * ?",
-    "Url": "http://218.249.166.2:8113/eisp-zk/jsonToBillEntityController.do",
+    "Url": "http://218.249.166.2:81123/eisp-zk/jsonToBillEntityController.do",
     "PdfUrl": "192.168.20.102:7080",
-    "SaleTax":"110101999999447",
+    "SaleTax":"11010199999944711",
     "InvType": "3",
     "BillType": "1",
     "SpecialRedFlag":"0",
@@ -25,5 +25,6 @@
     "JyUrl": "http://192.168.20.241:86/jypay/invoice/callback",
     "Frequency": 5,
     "OpenFrequency": 3,
-    "WarningEmail": "2399761917@qq.com,1397605984@qq.com"
+    "WarningEmail": "2399761917@qq.com,1397605984@qq.com",
+    "NsqUrl": "192.168.3.207:4150"
 }

+ 1 - 0
invoice/src/main.go

@@ -66,6 +66,7 @@ func Init() {
 	entity.WarningEmail = fmt.Sprint(Config["WarningEmail"])
 	entity.Fhr = fmt.Sprint(Config["Fhr"])
 	entity.Sky = fmt.Sprint(Config["Sky"])
+	entity.NsqUrl = fmt.Sprint(Config["NsqUrl"])
 	keys := redis.GetKeys(core.GetConfiguration().Redis.Modules, "fp_*")
 	invoiceService := service.InvoiceService{}
 	for numb, _ := range keys {

+ 88 - 9
invoice/src/util/push.go

@@ -6,7 +6,8 @@ import (
 	"encoding/json"
 	"entity"
 	"fmt"
-	"gopkg.in/gomail-2"
+	"github.com/nsqio/go-nsq"
+	"github.com/pkg/errors"
 	"io/ioutil"
 	loger "log"
 	"net/http"
@@ -17,7 +18,7 @@ import (
 var Loger *loger.Logger
 
 //文件是否存在
-func Exists(path string) (bool) {
+func Exists(path string) bool {
 	_, err := os.Stat(path)
 	if err == nil {
 		return true
@@ -54,7 +55,7 @@ func ImgHandle(imgBase64 string, swno string, saleTax string, swno1 string) stri
 }
 
 //pdf邮箱发送
-func SendPdf(emailArr []string,fool bool,orderCode string,msg string) (bool) {
+/*func SendPdf(emailArr []string,fool bool,orderCode string,msg string) (bool) {
 	startTime:=time.Now().Unix()
 	var mailConf entity.MailboxConf
 	if fool{
@@ -80,7 +81,84 @@ func SendPdf(emailArr []string,fool bool,orderCode string,msg string) (bool) {
 	fmt.Println("Send Email Success")
 	fmt.Println("用时:", fmt.Sprint(time.Now().Unix()-startTime))
 	return true
+}*/
+
+//从nsq接收的消息体
+type Msg struct {
+	Id         string                 `json:"id"`    //用于标识这个告警分组,及告警方式、告警人
+	Title      string                 `json:"title"` //非必填项
+	Text       string                 `json:"text"`
+	AppendInfo map[string]interface{} `json:"appendinfo"` //附加信息,非必填项
 }
+
+//pdf邮箱发送
+func SendPdf(emailArr []string, fool bool, orderCode string, msg string) bool {
+	//自定义需要的字段
+	errMap := map[string]interface{}{
+		"order_code": "订单号",
+		"需要记录的参数":    "相关参数",
+	}
+	//nsq
+	text := ""
+	if fool {
+		text = "流水号:" + orderCode + "," + entity.Body + "," + msg
+	} else {
+		text = "流水号:" + orderCode + "," + "开票失败" + "," + msg
+	}
+	m := &Msg{"invoice_alert", "你有新的告警消息处理", text, errMap}
+	bs, _ := json.Marshal(m)
+	//这是正式环境的nsq地址172.17.148.49:4260  测试环境的是:192.168.3.207:4150
+	p, _ := NewProducer(entity.NsqUrl, "jyalert", false)
+	defer p.P.Stop()
+	err := p.Publish(bs)
+	if err != nil {
+		return false
+	}
+	return true
+}
+
+type Producer struct {
+	//Ch    chan interface{}
+	P            *nsq.Producer
+	Topic        string
+	IsJsonEncode bool //是否进行json序列化,如果否则必须以[]byte传递,如果是则必须用对应的消费者对象[也设置了序列化]处理
+}
+
+func NewProducer(addr, toppic string, IsJsonEncode bool) (*Producer, error) {
+	config := nsq.NewConfig()
+	producer, err := nsq.NewProducer(addr, config)
+	if err != nil {
+		return nil, err
+	} else {
+		return &Producer{producer, toppic, IsJsonEncode}, nil
+	}
+}
+func (p *Producer) Publish(msg interface{}) error {
+	if p.IsJsonEncode {
+		var infoType byte
+		switch msg.(type) {
+		case []byte: //原本就是byte数组
+			infoType = 0x01
+		default:
+			infoType = 0x00
+		}
+		data, err := json.Marshal(msg)
+		if err != nil {
+			return err
+		} else if len(data) > 0 { //头部插入类型,用于解码[]byte
+			data = append([]byte{infoType}, data...)
+			return p.P.Publish(p.Topic, data)
+		} else {
+			return errors.New("producer msg err")
+		}
+	} else { //必须传入[]byte
+		if bs, ok := msg.([]byte); ok {
+			return p.P.Publish(p.Topic, bs)
+		}
+		return errors.New("producer msg err: no []byte")
+	}
+}
+
 func SafeConvert2Int(obj interface{}) int {
 	if obj != nil {
 		return int(obj.(float64))
@@ -96,8 +174,9 @@ func Log() {
 	Loger = loger.New(logFile, "[logger]", loger.LstdFlags|loger.Lshortfile|loger.LUTC) // 将文件设置为loger作为输出
 
 }
+
 //回调
-func Callback( swno ,saleTax ,fpdm ,fphm ,path ,changed ,isRed ,resType ,isSys,model ,OrderCode  string) bool {
+func Callback(swno, saleTax, fpdm, fphm, path, changed, isRed, resType, isSys, model, OrderCode string) bool {
 	fmt.Println(swno)
 	url := entity.JyUrl + "?order_code=" + OrderCode +
 		"&code=1&fpdm=" + fpdm +
@@ -106,10 +185,10 @@ func Callback( swno ,saleTax ,fpdm ,fphm ,path ,changed ,isRed ,resType ,isSys,m
 		"&swno=" + swno +
 		"&changed=" + changed +
 		"&isRed=" + isRed +
-		"&resType=" + resType+
+		"&resType=" + resType +
 		"&isSys=" + isSys
 	fmt.Println(url)
-	Loger.Println("更改发票状态:", "流水号:", swno,"是否红票:",isRed, url)
+	Loger.Println("更改发票状态:", "流水号:", swno, "是否红票:", isRed, url)
 	req, _ := http.NewRequest("GET", url, nil)
 	res, _ := http.DefaultClient.Do(req)
 	defer res.Body.Close()
@@ -117,8 +196,8 @@ func Callback( swno ,saleTax ,fpdm ,fphm ,path ,changed ,isRed ,resType ,isSys,m
 	dat := make(map[string]interface{})
 	err := json.Unmarshal([]byte(body), &dat)
 	fmt.Println(err)
-	fmt.Println(swno,"剑鱼数据回调:",dat)
-	if (dat["status"] == "success") {
+	fmt.Println(swno, "剑鱼数据回调:", dat)
+	if dat["status"] == "success" {
 		//if (isRed == "true") {
 		//	swno = "Red_" + swno
 		//}
@@ -126,4 +205,4 @@ func Callback( swno ,saleTax ,fpdm ,fphm ,path ,changed ,isRed ,resType ,isSys,m
 	}
 	return true
 
-}
+}