From ca10e9d776509f54cb0251b7eae44cee74d94b2c Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期二, 01 九月 2020 20:09:50 +0800 Subject: [PATCH] findHikSpaceUser add state=1 --- service/msgPush.go | 162 +++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 124 insertions(+), 38 deletions(-) diff --git a/service/msgPush.go b/service/msgPush.go index 252b74e..2da943d 100644 --- a/service/msgPush.go +++ b/service/msgPush.go @@ -7,6 +7,7 @@ "errors" "fmt" "github.com/astaxie/beego" + "strings" "sync" "time" ) @@ -180,6 +181,27 @@ } url := baseUrl+"/push/list/message" intent := "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=uni.UNIEDF0B5C/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title+";S.content="+msg+";S.payload=test;end" + androidPush := map[string]map[string]map[string]string { + "ups": { + "notification": { + "title": title, + "body": msg, + "click_type": "intent", + "intent": intent, + }, + }, + } + iosPush := map[string]interface{}{ + "type":"notify", + "payload":"鑲茶嫳涓鍋滆溅", + "aps":map[string]interface{}{ + "alert":map[string]string{ + "title": title, + "body": msg, + }, + "content-available":0, + }, + } reqBody := map[string]interface{} { "request_id": time.Now().Format("20060102150405") + util.GenValidateCode(6), "settings":map[string]int { @@ -193,17 +215,9 @@ "intent": intent, }, }, - "push_channel": map[string]map[string]map[string]map[string]string { - "android": { - "ups": { - "notification": { - "title": title, - "body": msg, - "click_type": "intent", - "intent": intent, - }, - }, - }, + "push_channel": map[string]interface{} { + "android": androidPush, + "ios":iosPush, }, } header := map[string]string { @@ -246,7 +260,7 @@ } //瀵瑰凡娉ㄥ唽鐨勭敤鎴疯繘琛屾秷鎭帹閫併�傝皟鐢ㄦ鎺ュ彛鍓嶉渶璋冪敤鍒涘缓娑堟伅鎺ュ彛璁剧疆娑堟伅鍐呭 -func PushByAlias(title string, msg string) (bool, error) { +func PushByAlias(title string, msg string, isTest bool) (bool, error, []string) { var aliasArr []string pushUserM := make(map[string]string) @@ -258,23 +272,29 @@ } } if len(pushUserM) == 0 { - return true,errors.New("len(pushUserM) == 0") + return false,errors.New("len(pushUserM) == 0"),aliasArr } carPersonM := make(map[string]string) //浠ヨ溅鐗屽彿涓簁ey锛寁alue鏄痟ik鐨刾ersonId csv := NewCarService() carPersons := csv.GetVehicleListByPerson("") if carPersons != nil { for _, cp := range carPersons { - carPersonM[cp.PlateNo] = cp.PersonId + ncPlateNo := preDealPlateNo(cp.PlateNo) //鍘绘帀姹夊瓧锛孌鍜�0鏇挎崲鎴�* + if ncPlateNo != "" { + carPersonM[ncPlateNo] = cp.PersonId + } } } delPersonIdM := make(map[string]string) spaceNos := csv.FindSpaceNo("") for _,sn := range spaceNos { if sn.State == 1 && sn.PlateNo != "" { //宸茬粡鎶婅溅鍋滃埌鍋滆溅鍦虹殑杞︿富锛屼笉鍐嶆帹閫佹秷鎭� - if pId,ok := carPersonM[sn.PlateNo];ok { - delPersonIdM[pId] = pId - delete(carPersonM, sn.PlateNo) + realPlateNo := preDealPlateNo(sn.PlateNo) + if realPlateNo != "" { + if pId,ok := carPersonM[realPlateNo];ok { + delPersonIdM[pId] = pId + delete(carPersonM, realPlateNo) + } } } } @@ -290,13 +310,21 @@ } lenAS := len(aliasArr) if lenAS == 0 { - return true, errors.New("aliasArr is empty") + return false, errors.New("娌℃湁鎺ㄩ�佺洰鏍囷紝aliasArr is empty"),aliasArr + } + if isTest { + //鍙粰鍐呴儴鎵嬫満鍙锋帹 + testPhones := beego.AppConfig.String("testPushPhones") + if testPhones == "" { + return false, errors.New("test push aliasArr is empty"),aliasArr + } + aliasArr = strings.Split(testPhones, ",") } cResult, taskId, ce := createPushMsg(title, msg) fmt.Println("createPushMsg taskId:", taskId, "cResult:",cResult, "err:", ce) if !cResult { - return false, errors.New("鍒涘缓鎺ㄩ�佸墠缃秷鎭け璐�") + return false, errors.New("鍒涘缓鎺ㄩ�佸墠缃秷鎭け璐�"),aliasArr } //alias 鍗曟鎺ㄩ�侀暱搴︿笂闄愭槸200 @@ -330,10 +358,22 @@ } } if isSuccess { - return true, nil + return true, nil,aliasArr } - return false, errors.New("鎺ㄩ�佸け璐�") + return false, errors.New("鎺ㄩ�佸け璐�"),aliasArr +} + +//棰勫鐞嗚溅鐗屽彿锛屽幓闄ら涓眽瀛楋紝浠ュ強蹇界暐D鍜�0 +func preDealPlateNo(pn string) string { + if pn != "" { + r := []rune(pn) + ncStr := string(r[1:]) + newPlateNo := strings.ReplaceAll(ncStr, "D", "*") + newPlateNo = strings.ReplaceAll(newPlateNo, "0", "*") + return newPlateNo + } + return "" } func doPush(taskId string, aliasArr []string) (bool,error) { @@ -384,7 +424,7 @@ return false, errors.New("鎺ㄩ�佸け璐�") } -func NightPush(title string, msg string) (bool, error) { +func NightPush(title string, msg string) (bool, error, []string) { var aliasArr []string pushUserM := make(map[string]string) @@ -396,7 +436,7 @@ } } if len(pushUserM) == 0 { - return true,nil + return false, errors.New("len(pushUserM) == 0"), aliasArr } carPersonM := make(map[string]string) csv := NewCarService() @@ -422,18 +462,48 @@ if len(aliasArr) == 0 { fmt.Println("娌℃湁鎺ㄩ�佺洰鏍�,aliasArr is empty") - return true, nil + return false, errors.New("娌℃湁鎺ㄩ�佺洰鏍�,aliasArr is empty"), aliasArr } cResult, taskId, ce := createPushMsg(title, msg) if !cResult { fmt.Println("createPushMsg taskId:", taskId, "err:", ce) - return false, errors.New("鍒涘缓鎺ㄩ�佸墠缃秷鎭け璐�") + return false, errors.New("鍒涘缓鎺ㄩ�佸墠缃秷鎭け璐�"), aliasArr } - return doPush(taskId, aliasArr) + b,e := doPush(taskId, aliasArr) + return b,e, aliasArr } +//濡傛灉澶滈棿鏈夌粰杞﹀簱鍐呯殑杞︿富鎺ㄩ�佲�滆灏藉揩椹剁鈥濈殑娑堟伅锛屽垯鍛婄煡绠$悊鍛� 鏈夊摢浜涜溅灏氬仠鍦ㄨ溅搴撳唴 +func Push2Manager(title string, msg string) (bool, error, []string) { + if len(msg) > 256 { + fmt.Println("澶滈棿鍋滅暀杞﹀お澶氾紝message:", msg) + + r := []rune(msg) + msg = string(r[:125])+"..." + } + managers := beego.AppConfig.String("nightManagerPhones") + if managers == "" { + return false, errors.New("澶滈棿鎺ㄩ�佺鐞嗗憳鎵嬫満鍙锋湭閰嶇疆"), []string{} + } + managerArr := strings.Split(managers, "") + if len(managerArr) == 0 { + fmt.Println("娌℃湁鎺ㄩ�佺洰鏍�,managerArr is empty") + return false, errors.New("绠$悊鍛樻墜鏈哄彿鏈厤缃�"), managerArr + } + + cResult, taskId, ce := createPushMsg(title, msg) + if !cResult { + fmt.Println("createPushMsg taskId:", taskId, "err:", ce) + return false, errors.New("鍒涘缓鎺ㄩ�佸墠缃秷鎭け璐�"), managerArr + } + + b,e := doPush(taskId, managerArr) + return b,e, managerArr +} + +/* func PushAll(title string, msg string) (bool,error) { appId := beego.AppConfig.String("pushAppId") baseUrl := beego.AppConfig.String("pushBaseUrl") + appId @@ -445,6 +515,30 @@ } url := baseUrl+"/push/all" intent := "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component=uni.UNIEDF0B5C/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title="+title+";S.content="+msg+";S.payload=test;end" + androidPush := map[string]map[string]map[string]string { + "ups": { + "notification": { + "title": title, + "body": msg, + "click_type": "intent", + "intent": intent, + }, + }, + } + iosPush := map[string]interface{}{ + "type":"notify", + "payload":"鑲茶嫳涓鍋滆溅", + "aps":map[string]interface{}{ + "alert":map[string]string{ + "title": title, + "body": msg, + }, + "content-available":0, + //"sound":"com.gexin.ios.silence", + //"category":"ACTIONABLE", + }, + "auto_badge":"+1", + } reqBody := map[string]interface{} { "request_id": time.Now().Format("20060102150405") + util.GenValidateCode(6), "settings":map[string]int { @@ -459,17 +553,9 @@ "intent": intent, }, }, - "push_channel": map[string]map[string]map[string]map[string]string { - "android": { - "ups": { - "notification": { - "title": title, - "body": msg, - "click_type": "intent", - "intent": intent, - }, - }, - }, + "push_channel": map[string]interface{} { + "android": androidPush, + "ios": iosPush, }, } header := map[string]string { @@ -502,7 +588,7 @@ } return false, errors.New("鎺ㄩ�佸け璐�") -} +}*/ func RefreshToken() (*TokenResult,error) { appId := beego.AppConfig.String("pushAppId") -- Gitblit v1.8.0