/// <summary> /// 清空设备标签 -- (仅200表示成功) /// </summary> /// <param name="registrationId"></param> /// <returns></returns> public int cleanDeviceTags(string registrationId) { if (string.IsNullOrEmpty(registrationId)) { throw new ApiException(Commons.HTTP_STATUS_400, -1, "registrationId is null"); } String path = MobPushConfig.deviceUrl + "/tags"; Tags t = new Tags(registrationId, 3); try { MobResult mr = Commons.WebClientPost(path, JsonExtension.ToJSON(t)); return(mr.status); } catch (ApiException api) { throw api; } }
/// <summary> /// 绑定设备别名,如果存在则覆盖原有别名 -- (仅200表示成功) /// </summary> /// <param name="alias"></param> /// <param name="registrationId"></param> /// <returns></returns> public int setDeviceAlias(string alias, string registrationId) { if (string.IsNullOrEmpty(registrationId)) { throw new ApiException(Commons.HTTP_STATUS_400, -1, "registrationId is null"); } if (string.IsNullOrEmpty(alias)) { throw new ApiException(Commons.HTTP_STATUS_400, -1, "alias is null"); } String path = MobPushConfig.deviceUrl + "/alias"; Alias a = new Alias(registrationId, alias); try { MobResult mr = Commons.WebClientPost(path, JsonExtension.ToJSON(a)); return(mr.status); } catch (ApiException api) { throw api; } }
/// <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; } }