123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613 |
- using com.igetui.api.openservice;
- using com.igetui.api.openservice.igetui;
- using com.igetui.api.openservice.igetui.template;
- using com.igetui.api.openservice.payload;
- using LYFZ.WanYuKeFuData.Model;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace LYFZ.WanYuKeFu
- {
- public class ErpGetuiApiSDK
- {
- public ErpGetuiApiSDK()
- {
- }
- #region 生产环境配置
- static string _APPID = "";
- public static string APPID
- {
- get { return ErpGetuiApiSDK._APPID; }
-
- }
- static string _APPKEY = "";
- public static string APPKEY
- {
- get { return ErpGetuiApiSDK._APPKEY; }
-
- }
- static string _AppSecret = "";
- public static string AppSecret
- {
- get { return ErpGetuiApiSDK._AppSecret; }
-
- }
- static string _MASTERSECRET = "";
- public static string MASTERSECRET
- {
- get { return ErpGetuiApiSDK._MASTERSECRET; }
-
- }
- static string _HOST = "";
- public static string HOST
- {
- get { return ErpGetuiApiSDK._HOST; }
-
- }
- #endregion
- #region 开发环境配置
- static string _Dev_APPID = "";
- public static string Dev_APPID
- {
- get { return ErpGetuiApiSDK._Dev_APPID; }
- }
- static string _Dev_APPKEY = "";
- public static string Dev_APPKEY
- {
- get { return ErpGetuiApiSDK._Dev_APPKEY; }
- }
- static string _Dev_AppSecret = "";
- public static string Dev_AppSecret
- {
- get { return ErpGetuiApiSDK._Dev_AppSecret; }
- }
- static string _Dev_MASTERSECRET = "";
- public static string Dev_MASTERSECRET
- {
- get { return ErpGetuiApiSDK._Dev_MASTERSECRET; }
- }
- static string _Dev_HOST = "";
- public static string Dev_HOST
- {
- get { return ErpGetuiApiSDK._Dev_HOST; }
- }
- #endregion
- static string _WanYuKFUrl = "";
- public static string WanYuKFUrl
- {
- get { return ErpGetuiApiSDK._WanYuKFUrl; }
- }
- public static void LoadGetuiApiSDKConfig()
- {
- string configString = System.IO.File.ReadAllText(LYFZ.WinAPI.CustomPublicMethod.GetFullDirectoryPath(LYFZ.WinAPI.CustomPublicMethod.BasePath)+"admin\\json\\systemParameter.json",System.Text.Encoding.UTF8);
- dynamic configJson = JsonConvert.DeserializeObject(configString);
- string GetuiAPI = configJson["GetuiAPI"].Value;
- ErpGetuiApiSDK._WanYuKFUrl = configJson["WanYuKFUrl"].Value;
- ErpGetuiApiSDK._Dev_APPID = configJson["DevAPPID"].Value;
- ErpGetuiApiSDK._Dev_APPKEY = configJson["DevAPPKEY"].Value;
- ErpGetuiApiSDK._Dev_AppSecret = configJson["DevAppSecret"].Value;
- ErpGetuiApiSDK._Dev_MASTERSECRET = configJson["DevMASTERSECRET"].Value;
- ErpGetuiApiSDK._Dev_HOST = configJson["DevHOST"].Value;
- ErpGetuiApiSDK._APPID = configJson["APPID"].Value;
- ErpGetuiApiSDK._APPKEY = configJson["APPKEY"].Value;
- ErpGetuiApiSDK._AppSecret = configJson["AppSecret"].Value;
- ErpGetuiApiSDK._MASTERSECRET = configJson["MASTERSECRET"].Value;
- ErpGetuiApiSDK._HOST = configJson["HOST"].Value;
-
- Global.WriteLog(String.Format("Pro ErpGetuiApiSDK._APPID:{0} ErpGetuiApiSDK._APPKEY:{1} ErpGetuiApiSDK._AppSecret:{2} ErpGetuiApiSDK._MASTERSECRET:{3} ErpGetuiApiSDK._HOST:{4}", ErpGetuiApiSDK._APPID, ErpGetuiApiSDK._APPKEY, ErpGetuiApiSDK._AppSecret, ErpGetuiApiSDK._MASTERSECRET, ErpGetuiApiSDK._HOST), "-1", Global.LogsDongleDomainList);
- Global.WriteLog(String.Format("Dev ErpGetuiApiSDK._APPID:{0} ErpGetuiApiSDK._APPKEY:{1} ErpGetuiApiSDK._AppSecret:{2} ErpGetuiApiSDK._MASTERSECRET:{3} ErpGetuiApiSDK._HOST:{4}", ErpGetuiApiSDK._Dev_APPID, ErpGetuiApiSDK._Dev_APPKEY, ErpGetuiApiSDK._Dev_AppSecret, ErpGetuiApiSDK._Dev_MASTERSECRET, ErpGetuiApiSDK._Dev_HOST), "-1", Global.LogsDongleDomainList);
- }
-
-
-
-
-
-
- public static string pushMessageToSingleBatchApp(LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord, LYFZ.WanYuKeFuData.DAL.GTMessagePushUser msgPushUserDal)
- {
- try
- {
- string retStr = "{\"result\":\"失败\",\"contentId\":\"\"}";
- if (msgRecord.TargetUser == 0)
- {
- retStr = pushMessageToApp(msgRecord,1);
- retStr = pushMessageToApp(msgRecord,0);
- }
- else
- {
- List<PushSingleUser> sUserList = msgPushUserDal.GetPushSingleUserList(msgRecord.TargetUser, msgRecord.TargetList);
- if (sUserList.Count > 0)
- {
- List<string> iosCidList = new List<string>();
- List<PushSingleUser> proUserList = new List<PushSingleUser>();
- List<PushSingleUser> devUserList = new List<PushSingleUser>();
-
- foreach (PushSingleUser suser in sUserList)
- {
- if (suser.GTType == 0)
- {
- iosCidList.Add(suser.GTClientID);
- }
- Global.WriteLog(String.Format("PushSingleUser suser.GTClientID:{0} suser.APPState:{1}", suser.GTClientID, suser.APPState), "-1", Global.LogsDongleDomainList);
-
- if (sUserList.Count <= 2)
- {
- if ((msgRecord.Platform.ToLower().Contains("ios") && suser.GTType == 0)
- || (msgRecord.Platform.ToLower().Contains("android") && suser.GTType == 1))
- {
- retStr = PushMessageToSingle(msgRecord, suser.GTClientID, suser.UserID, suser.Badge, suser.APPState,suser.LYFZAPPID);
- }
-
- }
- if ((msgRecord.Platform.ToLower().Contains("ios") && suser.GTType == 0)
- || (msgRecord.Platform.ToLower().Contains("android") && suser.GTType == 1))
- {
- if (suser.APPState == 1)
- {
- proUserList.Add(suser);
- }
- else {
- devUserList.Add(suser);
- }
- }
- }
-
- if (sUserList.Count > 2)
- {
- if (proUserList.Count > 0)
- {
- retStr = PushMessageToSingleBatch(msgRecord, proUserList, 1, proUserList[0].LYFZAPPID);
- }
- if (retStr.ToLower().Contains("result\":\"ok\","))
- {
- if (devUserList.Count > 0)
- {
- retStr = PushMessageToSingleBatch(msgRecord, devUserList, 0, proUserList[0].LYFZAPPID);
- }
- }
-
- }
- try
- {
- if (retStr.ToLower().Contains("result\":\"ok\","))
- {
- msgPushUserDal.AddBadgeNumber(iosCidList.ToArray());
- }
- }
- catch { }
- iosCidList.Clear();
- }
- else
- {
- retStr = "{\"result\":\"-900000\",\"contentId\":\"\"}";
- }
- sUserList.Clear();
- sUserList = null;
- }
- return retStr;
- }
- catch (Exception ex)
- {
- return "{\"result\":\"" + ex.Message + "\",\"contentId\":\"\"}";
- }
- }
-
-
-
-
-
-
-
- private static string PushMessageToSingle(LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord, string _ClientID,string _userid,int _Badge=0,int appState=1,string lyfzAppid="")
- {
- try
- {
-
- LYFZ.WanYuKeFuData.Model.APPConfig configModel = Global.GetAPPConfig(lyfzAppid,appState);
- if (configModel == null)
- {
- return "{\"result\":\"没有找到推送APP服务配置信息\",\"contentId\":\"\"}";
- }
- string currentAPPID = configModel.GTAppID;
- string currentAPPKEY = configModel.GTAppKey;
- IGtPush push = new IGtPush(configModel.HostUrl, currentAPPKEY, configModel.GTMasterSecret);
- Global.WriteLog(String.Format("Pro HOST:{0}, APPKEY:{1}, MASTERSECRET:{2} currentAPPID:{3}", configModel.HostUrl, currentAPPKEY, configModel.GTMasterSecret, currentAPPID), "-1", Global.LogsDongleDomainList);
-
- Global.WriteLog(String.Format("IGtPush:{0} ", push.ToString()), "-1", Global.LogsDongleDomainList);
-
- TransmissionTemplate template = TransmissionTemplateMsg(msgRecord.Title, msgRecord.Description, msgRecord.MsgData, _userid, msgRecord.ID.ToString(), currentAPPID, currentAPPKEY, _Badge: _Badge + 1);
-
-
- SingleMessage message = new SingleMessage();
- message.IsOffline = true;
- message.OfflineExpireTime = 1000 * 3600 * 12;
- message.Data = template;
-
- message.PushNetWorkType = 0;
- com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
- target.appId = currentAPPID;
- target.clientId = _ClientID;
-
- String pushResult = "";
- try
- {
- pushResult = push.pushMessageToSingle(message, target);
-
- }
- catch (RequestException e)
- {
- String requestId = e.RequestId;
-
- pushResult = push.pushMessageToSingle(message, target, requestId);
-
- }
-
- Global.WriteLog(String.Format("pushResult:{0} ", pushResult), "-1", Global.LogsDongleDomainList);
- return pushResult;
- }
- catch (Exception ex){
- Global.WriteLog(String.Format("Exception:{0} ", ex.Message), "-1", Global.LogsDongleDomainList);
- return "{\"result\":\""+ex.Message+"\",\"contentId\":\"\"}";
- }
- }
-
-
-
-
-
-
- public static string PushMessageToSingleBatch(LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord, List<PushSingleUser> _ClientIDList,int appState=1,string lyfzAppid="")
- {
- try
- {
- LYFZ.WanYuKeFuData.Model.APPConfig configModel = Global.GetAPPConfig(lyfzAppid, appState);
- if (configModel == null)
- {
- return "{\"result\":\"没有找到推送APP服务配置信息\",\"contentId\":\"\"}";
- }
- string currentAPPID = configModel.GTAppID;
- string currentAPPKEY = configModel.GTAppKey;
- IGtPush push = new IGtPush(configModel.HostUrl, currentAPPKEY, configModel.GTMasterSecret);
- IBatch batch = new BatchImpl(currentAPPKEY, push);
- Global.WriteLog(String.Format("Pro HOST:{0}, APPKEY:{1}, MASTERSECRET:{2} currentAPPID:{3}", configModel.HostUrl, currentAPPKEY, configModel.GTMasterSecret, currentAPPID), "-1", Global.LogsDongleDomainList);
-
- int targetCount = 0;
- foreach (PushSingleUser cidItem in _ClientIDList)
- {
- if (cidItem.APPState == appState)
- {
-
- if ((msgRecord.Platform.ToLower().Contains("ios") && cidItem.GTType == 0)
- || (msgRecord.Platform.ToLower().Contains("android") && cidItem.GTType == 1))
- {
-
- TransmissionTemplate template = TransmissionTemplateMsg(msgRecord.Title, msgRecord.Description, msgRecord.MsgData, cidItem.UserID, msgRecord.ID.ToString(), currentAPPID,currentAPPKEY, _Badge: cidItem.Badge + 1);
-
-
- SingleMessage messageTrans = new SingleMessage();
- messageTrans.IsOffline = true;
- messageTrans.OfflineExpireTime = 1000 * 3600 * 12;
- messageTrans.Data = template;
-
- messageTrans.PushNetWorkType = 0;
- com.igetui.api.openservice.igetui.Target targetTrans = new com.igetui.api.openservice.igetui.Target();
- targetTrans.appId = currentAPPID;
- targetTrans.clientId = cidItem.GTClientID;
- targetCount++;
- batch.add(messageTrans, targetTrans);
- }
- }
- }
-
-
- if (targetCount > 0)
- {
- try
- {
- return batch.submit();
- }
- catch
- {
- return batch.retry();
- }
- }
- else {
- return "{\"result\":\"没有要发送的客户端\",\"contentId\":\"\"}";
- }
- }
- catch (Exception ex)
- {
- return "{\"result\":\"" + ex.Message + " appState:"+ appState.ToString() + "\",\"contentId\":\"\"}";
- }
- }
-
-
-
-
- private static string pushMessageToApp(LYFZ.WanYuKeFuData.Model.GTMsgRecord msgRecord, int appState = 1)
- {
- try
- {
- IGtPush push = null;
- string currentAPPID = "";
- string currentAPPKEY = "";
- if (appState == 1)
- {
- currentAPPID = APPID;
- currentAPPKEY = APPKEY;
- push = new IGtPush(HOST, APPKEY, MASTERSECRET);
- }
- else {
- currentAPPID = Dev_APPID;
- currentAPPKEY = Dev_APPKEY;
- push = new IGtPush(Dev_HOST, Dev_APPKEY, Dev_MASTERSECRET);
- }
-
- AppMessage message = new AppMessage();
- TransmissionTemplate template = TransmissionTemplateMsg(msgRecord.Title, msgRecord.Description, msgRecord.MsgData, "", msgRecord.ID.ToString(), currentAPPID, currentAPPKEY, _Badge: 1);
-
-
- message.IsOffline = true;
- message.OfflineExpireTime = 1000 * 3600 * 12;
- message.Data = template;
-
- message.PushNetWorkType = 0;
-
- List<String> appIdList = new List<String>();
- appIdList.Add(currentAPPID);
- List<String> phoneTypeList = new List<String>();
- phoneTypeList.Add("ANDROID");
- phoneTypeList.Add("IOS");
- List<String> provinceList = new List<String>();
-
-
-
- List<String> tagList = new List<string>();
-
- message.AppIdList = appIdList;
- message.PhoneTypeList = phoneTypeList;
-
-
- String pushResult = push.pushMessageToApp(message);
- return pushResult;
- }
- catch (Exception ex)
- {
- return "{\"result\":\"" + ex.Message + "\",\"contentId\":\"\"}";
- }
-
-
- }
-
-
- static string GetMsgContent(string content)
- {
- string retContent = "";
- if (content.ToLower().IndexOf("http://") == 0
- || content.ToLower().IndexOf("https://") == 0)
- {
- retContent = JsonConvert.SerializeObject(new { JumpURL = content });
- }
- else
- {
- retContent = content;
- }
- return retContent;
- }
-
-
-
-
-
-
-
-
- public static TransmissionTemplate TransmissionTemplateMsg(string _title, string _description, string _Content, string _userid,string _msgid,string tAppid,string tAppkey,int _Badge = 0)
- {
- string sendMsgContent = "";
- string tempMsgString = GetMsgContent(_Content);
- dynamic smgObj = new
- {
- msgid=_msgid,
- title = _title,
- description = _description,
- content = _Content.IndexOf("{\"") == 0 ? JsonConvert.DeserializeObject(_Content) : tempMsgString.IndexOf("{\"") == 0 ? JsonConvert.DeserializeObject(tempMsgString) : tempMsgString,
- sendTime=DateTime.Now.ToYYYY_MM_dd_HH_mm_ss(),
- badge = _Badge
- };
- sendMsgContent = JsonConvert.SerializeObject(smgObj);
- TransmissionTemplate template = new TransmissionTemplate();
- template.AppId = tAppid;
- template.AppKey = tAppkey;
- template.TransmissionType = "2";
- template.TransmissionContent = sendMsgContent;
-
-
-
- APNPayload apnpayload = new APNPayload();
- DictionaryAlertMsg alertMsg = new DictionaryAlertMsg();
- alertMsg.Body = _description;
-
- alertMsg.Title = _title;
- apnpayload.AlertMsg = alertMsg;
- if (_Badge > 0)
- {
- apnpayload.Badge = _Badge;
- }
- apnpayload.ContentAvailable = 1;
-
- apnpayload.Sound = "default";
- apnpayload.addCustomMsg("payload", sendMsgContent);
- template.setAPNInfo(apnpayload);
-
-
-
-
- return template;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- }
|