123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/wenzhenxi/gorsa"
- "hongze/hongze_yb/global"
- models "hongze/hongze_yb/models/tables/report_send_ths_detail"
- "hongze/hongze_yb/models/tables/voice_broadcast"
- "hongze/hongze_yb/services/alarm_msg"
- "hongze/hongze_yb/services/wechat"
- "hongze/hongze_yb/utils"
- "io/ioutil"
- "net/http"
- "net/url"
- "strings"
- "time"
- )
- var permissionMap map[string]string = map[string]string{
- "化里化外日评": "原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱",
- "股债日评": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "贵金属复盘": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "每日经济数据备忘录": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "宏观商品复盘": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "知白守黑日评": "钢材,铁矿,双焦(焦煤、焦炭)",
- "有声有色日度闲篇": "有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "EIA原油库存点评": "原油",
- "苯乙烯数据点评": "苯乙烯",
- "API原油库存点评": "原油",
- "铁矿航运数据点评": "铁矿",
- "中观需求点评": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "聚酯数据点评": "PTA,MEG",
- "钢材周度数据点评": "钢材",
- "寻根知本": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "国际宏观": "宏观,利率债,原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱,钢材,铁矿,双焦(焦煤、焦炭),有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "能化百家谈": "原油,PTA,MEG,织造终端,甲醇,聚烯烃,沥青,橡胶,苯乙烯,玻璃纯碱",
- "有色百家谈": "有色(铜、铝),有色(锌、铅),镍+不锈钢",
- "黑色百家谈": "钢材,铁矿,双焦(焦煤、焦炭)",
- }
- var permissionLabelMap = map[string]string{
- "宏观经济": "宏观",
- "利率债": "利率债",
- "原油": "原油",
- "PTA": "PTA",
- "MEG": "MEG",
- "织造终端": "织造终端",
- "甲醇": "甲醇",
- "聚烯烃": "聚烯烃",
- "沥青": "沥青",
- "纯苯+苯乙烯": "纯苯+苯乙烯",
- "玻璃纯碱": "玻璃纯碱",
- "钢材": "钢材",
- "铁矿": "铁矿",
- "双焦(焦煤、焦炭)": "双焦(焦煤、焦炭)",
- "有色(锌)": "有色(锌)",
- "有色(铜、铝)": "有色(铜、铝)",
- "镍+不锈钢": "镍+不锈钢",
- "PVC": "PVC",
- "聚酯": "聚酯",
- "钴锂": "钴锂",
- "策略": "策略",
- "苯乙烯": "纯苯+苯乙烯",
- "锌": "有色(锌)",
- "双焦": "双焦(焦煤、焦炭)",
- "铜/铝": "有色(铜、铝)",
- "镍/不锈钢": "镍+不锈钢",
- "成品油": "成品油",
- "油品": "成品油",
- "纺服": "织造终端",
- }
- type TshResult struct {
- ErrorCode int `json:"error" description:"错误状态码"`
- Message string `json:"message" description:"提示信息"`
- }
- var (
- THS_SendUrl string
- THS_PubKey string
- )
- func init() {
- THS_PubKey = `-----BEGIN PUBLIC KEY-----
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqugglfCboOEfWtHlGBOW
- 40a4Y3xOs0MPBwjTOzHgcaWzx5XCc20VftGVXkWlpjs8u4dza/Bp1SV7SJ5Y7U95
- jgUOP8Js9Qgp6UVqBJDJf3i1KpjHzlk3ma8zxAYUAdieEUE+SKSxSY+BD9A6lpf5
- n+igXLmzR5GeVGFeLzoMhB1+pXgGhW30ao9wPwuRF7DBl+FKa/ACi7iXLiwXVgqT
- FFi29TKeerEENu3EpMXvPml7tNUiVmVW6d83hlascfbAlkShwuHLSGpLqK7brtg6
- jRS9hreKFKb0BUQ4TB26e7IDCstbMRvUp4+OGezexzic5NYPQ8uLo5OTaS7f7PrW
- ZwIDAQAB
- -----END PUBLIC KEY-----`
- if global.CONFIG.Serve.RunMode == "release" {
-
- THS_SendUrl = `https://board.10jqka.com.cn/gateway/ps/syncNews`
- } else {
-
- THS_SendUrl = `https://mtest.10jqka.com.cn/gateway/ps/syncNews`
- }
- }
- func SendThs(title, labelStr, abstract, jumpBaseUrl, logoUrl, dataType string) (err error) {
- return nil
- defer func() {
- if err != nil {
-
- go alarm_msg.SendAlarmMsg("发送消息至同花顺失败 ErrMsg:"+err.Error(), 3)
-
- }
- }()
- pubKey := THS_PubKey
- sendUrl := THS_SendUrl
-
- title = utils.SubStr(title, 50)
- global.LOG.Info(fmt.Sprintf("title:%s", title))
- title, err = gorsa.PublicEncrypt(title, pubKey)
- if err != nil {
- return
- }
-
- abstract = utils.SubStr(abstract, 50)
- global.LOG.Info(fmt.Sprintf("abstract:%s", abstract))
- abstract, err = gorsa.PublicEncrypt(abstract, pubKey)
- if err != nil {
- return
- }
-
- newLabelList := make([]string, 0)
- labelList := strings.Split(labelStr, ",")
- for _, v := range labelList {
- tmpLabel, ok := permissionLabelMap[v]
- if !ok {
- tmpLabel = v
- }
- newLabelList = append(newLabelList, tmpLabel)
- }
- labelStr = strings.Join(newLabelList, ",")
- global.LOG.Info(fmt.Sprintf("labelStr:%s", labelStr))
- label, err := gorsa.PublicEncrypt(labelStr, pubKey)
- if err != nil {
- return
- }
-
- jumpUrl, err := gorsa.PublicEncrypt(jumpBaseUrl, pubKey)
- if err != nil {
- return
- }
- picUrl, err := gorsa.PublicEncrypt(logoUrl, pubKey)
- if err != nil {
- return
- }
- dataTypeEncript, err := gorsa.PublicEncrypt(dataType, pubKey)
- if err != nil {
- return
- }
-
- client := http.Client{}
- form := url.Values{}
- form.Add("title", title)
- form.Add("description", abstract)
- form.Add("label", label)
- form.Add("url", jumpUrl)
- form.Add("icon", picUrl)
- form.Add("dataType", dataTypeEncript)
- global.LOG.Info(fmt.Sprintf("SendThs parms:%s", form.Encode()))
- resp, err := client.PostForm(sendUrl, form)
- if err != nil {
- return
- }
- defer resp.Body.Close()
- body, _ := ioutil.ReadAll(resp.Body)
-
- global.LOG.Info(fmt.Sprintf("ThsResult parms:%s", string(body)))
-
- var tshResult TshResult
- err = json.Unmarshal(body, &tshResult)
- if err != nil {
- err = errors.New(fmt.Sprint("同花顺接口返回数据转换成结构体异常,Err:", err))
- return
- }
- if tshResult.ErrorCode != 1 {
- err = errors.New(fmt.Sprint("发送数据到同花顺接口异常,result:", string(body)))
- return
- }
- return
- }
- func SendVoiceBroadcastToThs(voice *voice_broadcast.VoiceBroadcast) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("发送语音播报至同花顺失败 ErrMsg:"+err.Error(), 3)
-
- }
- }()
- permissionName := "宏观"
-
- jumpBaseUrl := wechat.WxYbAppId + `/pages-voice/voiceDetail?voiceId=`
- logoUrl := `https://hongze.oss-cn-shanghai.aliyuncs.com/hzyj.png`
- sendDetail, err := models.GetVoiceSendThsDetailById(voice.BroadcastId, "语音播报")
- if err != nil && err != utils.ErrNoRow {
- return
- } else if err == nil && sendDetail != nil {
- if sendDetail.Status >= 0 {
- fmt.Println("重复发送")
- return
- }
- }
- pushTime := time.Now()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- newSendDetail := &models.ReportSendThsDetail{
- ReportId: voice.BroadcastId,
- ReportType: "语音播报",
- Status: 0,
- PushTime: pushTime,
- CreateTime: time.Now(),
- Title: voice.BroadcastName,
- LabelStr: permissionName,
- RecordStatus: 0,
- MsgType: 2,
- Content: voice.BroadcastName,
- JumpUrl: fmt.Sprint(jumpBaseUrl, voice.BroadcastId),
- Pic: logoUrl,
- }
- sendDetailId, tmpErr := models.AddReportSendThsDetail(newSendDetail)
- if tmpErr != nil {
- err = tmpErr
- return
- }
-
- dataType := "2"
- err = SendThs(voice.BroadcastName, permissionName, voice.BroadcastName, fmt.Sprint(jumpBaseUrl, voice.BroadcastId), logoUrl, dataType)
- if err != nil {
- _ = models.ModifyReportSendThsDetailStatus(int(sendDetailId), -1, err.Error())
- return
- }
- _ = models.ModifyReportSendThsDetailStatus(int(sendDetailId), 1, "")
- return
- }
|