Ejemplo n.º 1
0
        /// <summary>
        /// 获取地理位置列表 -- 子级列表
        /// 如果查询最上级则传入null即可
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public List <Area> getArea(string parentId)
        {
            if (string.IsNullOrEmpty(parentId))
            {
                parentId = "0";
            }
            string path = MobPushConfig.baseUrl + "/area/" + parentId;

            try
            {
                MobResult mr = Commons.WebClientGet(path);
                if (mr == null || mr.res == null)
                {
                    return(new List <Area>());
                }
                string      res  = mr.res.ToString();
                List <Area> list = JsonExtension.DeserializeJsonToList <Area>(res);
                return(list);
            }
            catch (ApiException api)
            {
                throw api;
            }
        }
        /// <summary>
        /// 获取设备别名
        /// </summary>
        /// <param name="registrationId"></param>
        /// <returns></returns>
        public string getDeviceAlias(string registrationId)
        {
            if (string.IsNullOrEmpty(registrationId))
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "registrationId is null");
            }
            string path = MobPushConfig.deviceUrl + "/alias/" + registrationId;

            try
            {
                MobResult mr = Commons.WebClientGet(path);
                if (mr == null || mr.res == null)
                {
                    return(null);
                }
                string res   = mr.res.ToString();
                Alias  alias = JsonExtension.FromJSON <Alias>(res);
                return(alias.alias);
            }
            catch (ApiException api)
            {
                throw api;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 发送推送 -- 返回MobPush唯一标识
        /// </summary>
        /// <param name="pushWork"></param>
        /// <returns></returns>
        public string sendPush(PushWork pushWork)
        {
            if (pushWork == null)
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "pushWork is null");
            }
            pushWork.appkey = MobPushConfig.appkey;
            if (string.IsNullOrEmpty(pushWork.content))
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "content is null");
            }
            if (pushWork.target == null)
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "target is null");
            }
            if (pushWork.type == null)
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "type is null");
            }
            if (pushWork.plats == null)
            {
                throw new ApiException(Commons.HTTP_STATUS_400, -1, "plats is null");
            }
            if (pushWork.unlineTime == null)
            {//默认保留时间
                pushWork.unlineTime = 1;
            }
            if (pushWork.plats.Contains(1))
            { // Android默认参数
                if (pushWork.androidstyle == null)
                {
                    pushWork.androidstyle = (int?)AndroidNotifyStyleEnum.normal;
                }
            }
            if (pushWork.plats.Contains(2))
            { // IOS 的默认参数
                if (pushWork.iosBadge == null)
                {
                    pushWork.iosBadge = 1;
                }
                if (string.IsNullOrEmpty(pushWork.iosSound))
                {
                    pushWork.iosSound = "default";
                }
                if (pushWork.iosProduction == null)
                {
                    pushWork.iosProduction = 1;
                }
            }
            string path = MobPushConfig.pushUrl + "/v2/push";

            try
            {
                MobResult mr = Commons.WebClientPost(path, JsonExtension.ToJSON(pushWork));

                pushWork = JsonExtension.FromJSON <PushWork>(mr.res.ToJSON());

                return(pushWork.batchId);
            }
            catch (ApiException api)
            {
                throw api;
            }
        }