From 4945b7781badfe6703635444ba046597a1b80d78 Mon Sep 17 00:00:00 2001 From: wind2008hxy Date: Mon, 4 Jun 2018 11:58:06 +0800 Subject: [PATCH 01/22] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Djpush=E5=9C=A8ce?= =?UTF-8?q?lery=20raise=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jpush/common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jpush/common.py b/jpush/common.py index a638ee3..71aaeb5 100644 --- a/jpush/common.py +++ b/jpush/common.py @@ -81,6 +81,8 @@ def __str__(self): class APIConnectionException(Exception): def __init__(self, value): self.value = value + # 修复celery的错误,参考https://github.com/celery/celery/issues/3623 + super(Exception, self).__init__(value) def __str__(self): return repr(self.value) From f75bde1c65daba902ac5012a18c7201c10a7dcd6 Mon Sep 17 00:00:00 2001 From: Helperhaps Date: Mon, 29 Oct 2018 11:11:07 +0800 Subject: [PATCH 02/22] add api --- jpush/__init__.py | 2 +- jpush/schedule/core.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/jpush/__init__.py b/jpush/__init__.py index 129196b..0fafacd 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.0' +__version__ = '3.3.2' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default diff --git a/jpush/schedule/core.py b/jpush/schedule/core.py index c536cbf..875f238 100644 --- a/jpush/schedule/core.py +++ b/jpush/schedule/core.py @@ -43,6 +43,11 @@ def delete_schedule(self,schedule_id): result = self.send("DELETE", url) return result + def get_msg_ids(self, schedule_id): + url = common.BASE_SCHEDULEURL + schedule_id + '/msg_ids' + body = None + result = self.send("GET", url, body) + return result class ScheduleResponse(object): """Response to a successful device request send. From 58b20b76ed4e55b758ad85142f6bf85d0348413d Mon Sep 17 00:00:00 2001 From: cockcrow Date: Mon, 29 Oct 2018 14:42:12 +0800 Subject: [PATCH 03/22] fix indentation --- jpush/schedule/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jpush/schedule/core.py b/jpush/schedule/core.py index 875f238..69b2c03 100644 --- a/jpush/schedule/core.py +++ b/jpush/schedule/core.py @@ -43,7 +43,7 @@ def delete_schedule(self,schedule_id): result = self.send("DELETE", url) return result - def get_msg_ids(self, schedule_id): + def get_msg_ids(self, schedule_id): url = common.BASE_SCHEDULEURL + schedule_id + '/msg_ids' body = None result = self.send("GET", url, body) @@ -72,4 +72,4 @@ def get_status_code(self): return self.status_code def __str__(self): - return "Schedule response Payload: {0}".format(self.payload) \ No newline at end of file + return "Schedule response Payload: {0}".format(self.payload) From 5c624eef3462f1d1999f3e032bc3ce8532e4ea1b Mon Sep 17 00:00:00 2001 From: Helperhaps Date: Mon, 29 Oct 2018 15:39:44 +0800 Subject: [PATCH 04/22] update version --- jpush/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpush/__init__.py b/jpush/__init__.py index 0fafacd..0bdc331 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.2' +__version__ = '3.3.3' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default From da2ce84db8b961e69dc618495a506cd09410de0e Mon Sep 17 00:00:00 2001 From: Helperhaps Date: Fri, 30 Nov 2018 13:36:56 +0800 Subject: [PATCH 05/22] add status message api --- examples/report_example.py | 3 +++ jpush/__init__.py | 2 +- jpush/report/core.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/report_example.py b/examples/report_example.py index 9b89576..679cca5 100644 --- a/examples/report_example.py +++ b/examples/report_example.py @@ -12,3 +12,6 @@ def receivede(): def users(): report.get_users("DAY","2016-04-10","3") + +def status(): + report.get_status_messages('3289406737', ['xxx']) diff --git a/jpush/__init__.py b/jpush/__init__.py index 0bdc331..578ea67 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.3' +__version__ = '3.3.4' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default diff --git a/jpush/report/core.py b/jpush/report/core.py index a1085b9..9256101 100644 --- a/jpush/report/core.py +++ b/jpush/report/core.py @@ -22,6 +22,19 @@ def get_received(self,msg_ids): received = self.send("GET", url, params = params) return received + def get_status_messages(self, msg_id, reg_ids, date=None): + url = common.get_url('report', self.zone) + 'status/messages' + if not isinstance(reg_ids, list): + reg_ids = [reg_ids] + body = { + 'msg_id': msg_id, + 'registration_ids': reg_ids + } + if date is not None: + body['date'] = date + sm = self.send("POST", url, body = body) + return sm + def get_messages(self, msg_ids): url = common.get_url('report', self.zone) + 'messages' params = { 'msg_ids': msg_ids } From e22f1d338df884c87f5d709f036e0b3d5606dead Mon Sep 17 00:00:00 2001 From: Helperhaps Date: Thu, 20 Dec 2018 17:12:57 +0800 Subject: [PATCH 06/22] update apis --- docs/push/push.md | 30 ++++++++++++++++++++++++------ jpush/__init__.py | 2 +- jpush/push/payload.py | 11 +++++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/push/push.md b/docs/push/push.md index 0c39d5b..2f09e66 100644 --- a/docs/push/push.md +++ b/docs/push/push.md @@ -171,8 +171,7 @@ notification(alert=None, ios=None, android=None, winphone=None) ##### ios payload ``` -ios(alert=None, badge=None, sound=None, content_available=False, - extras=None, sound_disable=False) +ios(alert=None, badge='+1', sound=None, content_available=False, mutable_content=False, category=None, extras=None, sound_disable=False, thread_id=None): ``` 参数说明 @@ -190,14 +189,19 @@ ios(alert=None, badge=None, sound=None, content_available=False, string 必填 通知内容 - 这里指定了,将会覆盖上级统一指定的 alert 信息;内容为空则不展示到通知栏。支持 emoji 表情。 + + 这里指定内容将会覆盖上级统一指定的 alert 信息;内容为空则不展示到通知栏。支持字符串形式也支持官方定义的 alert payload 结构,在该结构中包含 title 和 subtitle 等官方支持的 key + sound string 可选 通知提示声音 - 如果无此字段,则此消息无声音提示;有此字段,如果找到了指定的声音就播放该声音,否则播放默认声音,如果此字段为空字符串,iOS 7 为默认声音,iOS 8 为无声音。(消息) 说明:JPush 官方 API Library (SDK) 会默认填充声音字段。提供另外的方法关闭声音。 + + 普通通知: string类型,如果无此字段,则此消息无声音提示;有此字段,如果找到了指定的声音就播放该声音,否则播放默认声音,如果此字段为空字符串,iOS 7 为默认声音,iOS 8 及以上系统为无声音。说明:JPush 官方 SDK 会默认填充声音字段,提供另外的方法关闭声音,详情查看各 SDK 的源码。 + 告警通知: JSON Object ,支持官方定义的 payload 结构,在该结构中包含 critical 、name 和 volume 等官方支持的 key + badge @@ -211,7 +215,14 @@ ios(alert=None, badge=None, sound=None, content_available=False, boolean 可选 推送唤醒 - 推送的时候携带"content-available":true 说明是 Background Remote Notification,如果不携带此字段则是普通的Remote Notification。详情参考:Background Remote Notification + 推送的时候携带"content-available":true 说明是 Background Remote Notification,如果不携带此字段则是普通的Remote Notification。详情参考:Background Remote Notification + + + mutable-content + boolean + 可选 + 通知扩展 + 推送的时候携带 ”mutable-content":true 说明是支持iOS10的UNNotificationServiceExtension,如果不携带此字段则是普通的 Remote Notification。详情参考:UNNotificationServiceExtension category @@ -220,6 +231,13 @@ ios(alert=None, badge=None, sound=None, content_available=False, IOS8才支持。设置APNs payload中的"category"字段值 + + thread-id + string + 可选 + 通知分组 + ios 的远程通知通过该属性来对通知进行分组,同一个 thread-id 的通知归为一组。 + extras JSON Object @@ -236,7 +254,7 @@ ios(alert=None, badge=None, sound=None, content_available=False, ##### android payload ``` -android(alert, title=None, builder_id=None, extras=None) +android(alert, title=None, builder_id=None, extras=None, priority=None, category=None, style=None, alert_type=None, big_text=None, inbox=None, big_pic_path=None, large_icon=None, intent=None) ``` 参数说明
diff --git a/jpush/__init__.py b/jpush/__init__.py index 578ea67..0a29fe0 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.4' +__version__ = '3.3.5' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default diff --git a/jpush/push/payload.py b/jpush/push/payload.py index 0ed45fc..001230e 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -37,7 +37,7 @@ def notification(alert=None, ios=None, android=None, winphone=None): def ios(alert=None, badge='+1', sound=None, content_available=False, - mutable_content=False, category=None, extras=None, sound_disable=False): + mutable_content=False, category=None, extras=None, sound_disable=False, thread_id=None): """iOS/APNS specific platform override payload. :keyword alert: iOS format alert, as either a string or dictionary. @@ -76,12 +76,15 @@ def ios(alert=None, badge='+1', sound=None, content_available=False, payload['mutable-content'] = 1 if category: payload['category'] = category + if thread_id: + payload['thread-id'] = thread_id if extras is not None: payload['extras'] = extras return payload def android(alert, title=None, builder_id=None, extras=None, - priority=None, category=None, style=None, alert_type=None,big_text=None, inbox=None, big_pic_path=None): + priority=None, category=None, style=None, alert_type=None, + big_text=None, inbox=None, big_pic_path=None, large_icon=None, intent=None): """Android specific platform override payload. :keyword alert: String alert text.If you set alert to a empty string,then the payload @@ -114,6 +117,10 @@ def android(alert, title=None, builder_id=None, extras=None, payload['inbox'] = inbox if big_pic_path is not None: payload['big_pic_path'] = big_pic_path + if large_icon is not None: + payload['large_icon'] = large_icon + if intent is not None: + payload['intent'] = intent if extras is not None: payload['extras'] = extras return payload From b690c1cc057758fa3ab9578b3f482d157b2caf72 Mon Sep 17 00:00:00 2001 From: jinwen Date: Wed, 27 Feb 2019 18:20:46 +0800 Subject: [PATCH 07/22] Revised comments --- jpush/push/payload.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jpush/push/payload.py b/jpush/push/payload.py index 001230e..342c1bb 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -45,13 +45,13 @@ def ios(alert=None, badge='+1', sound=None, content_available=False, :keyword sound: An string sound file to play. :keyword content_available: If True, pass on the content-available command for Newsstand iOS applications. - :keyword extra: A set of key/value pairs to include in the push payload + :keyword extras: A set of key/value pairs to include in the push payload sent to the device. :keyword sound_disalbe: Disable sound to implement slient push. >>> ios(alert='Hello!', sound='cat.caf', - ... extra={'articleid': '12345'}) - {'sound': 'cat.caf', 'extra': {'articleid': '12345'}, 'alert': 'Hello!'} + ... extras={'articleid': '12345'}) + {'sound': 'cat.caf', 'extras': {'articleid': '12345'}, 'alert': 'Hello!'} """ payload = {} From 3361f7d618429a918b1a974f904f54bfc0f9be8c Mon Sep 17 00:00:00 2001 From: laodong Date: Thu, 28 Feb 2019 17:35:26 +0800 Subject: [PATCH 08/22] add params in sms message --- jpush/__init__.py | 2 +- jpush/push/payload.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jpush/__init__.py b/jpush/__init__.py index 0a29fe0..9a26c78 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.5' +__version__ = '3.3.6' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default diff --git a/jpush/push/payload.py b/jpush/push/payload.py index 001230e..aaf5588 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -165,12 +165,16 @@ def message(msg_content, title=None, content_type=None, extras=None): payload['extras'] = extras return payload -def smsmessage(delay_time, temp_id, temp_para = None): +def smsmessage(delay_time, temp_id, temp_para = None, signid = None, active_filter = True): payload = {} payload["delay_time"]=delay_time payload["temp_id"]=temp_id if temp_para is not None: payload['temp_para'] = temp_para + if signid is not None: + payload['signid'] = signid + if not active_filter: + payload['active_filter'] = False return payload From c52c82bec62760737e0c4f3ea99c084e8b14cba2 Mon Sep 17 00:00:00 2001 From: laodong Date: Thu, 25 Apr 2019 13:18:25 +0800 Subject: [PATCH 09/22] fix exception issue --- jpush/common.py | 1 + jpush/core.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/jpush/common.py b/jpush/common.py index 71aaeb5..0cc6bb9 100644 --- a/jpush/common.py +++ b/jpush/common.py @@ -91,6 +91,7 @@ def __str__(self): class APIRequestException(Exception): def __init__(self, value): self.value = value + super(Exception, self).__init__(value) def __str__(self): return repr(self.value) diff --git a/jpush/core.py b/jpush/core.py index f9ce09f..29022d7 100644 --- a/jpush/core.py +++ b/jpush/core.py @@ -36,7 +36,7 @@ def _request(self, method, body, url, content_type=None, version=None, params=No except requests.exceptions.ConnectTimeout: raise common.APIConnectionException("Connection to api.jpush.cn timed out.") except Exception: - raise common.APIConnectionException("Connection to api.jpush.cn error.") + raise common.APIRequestException("Connection to api.jpush.cn error.") logger.debug("Received %s response. Headers:\n\t%s\nBody:\n\t%s", response.status_code, '\n\t'.join( '%s: %s' % (key, value) for (key, value) in response.headers.items()), response.content) From 98fa1cb802b6394f59d9aedf4fc53c2e1af51c9b Mon Sep 17 00:00:00 2001 From: laodong Date: Thu, 25 Apr 2019 13:21:08 +0800 Subject: [PATCH 10/22] 3.3.7 --- jpush/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpush/__init__.py b/jpush/__init__.py index 9a26c78..223e587 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.6' +__version__ = '3.3.7' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default From 5fc35b84f857a1b052d2caa9cf907ba9455411f7 Mon Sep 17 00:00:00 2001 From: zhengjh Date: Tue, 3 Sep 2019 14:19:32 +0800 Subject: [PATCH 11/22] =?UTF-8?q?=E6=8E=A8=E9=80=81API=EF=BC=8CNotificatio?= =?UTF-8?q?n=E9=87=8CAndroid=E5=A2=9E=E5=8A=A0channel=5Fid=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E5=8D=95?= =?UTF-8?q?=E6=8E=A8=E6=8E=A5=E5=8F=A3=20=E5=A2=9E=E5=8A=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=80=81=E8=BE=BE=E7=BB=9F=E8=AE=A1=E8=AF=A6=E6=83=85?= =?UTF-8?q?=EF=BC=88=E6=96=B0=EF=BC=89=20/v3/received/detail=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B6=88=E6=81=AF=E7=BB=9F=E8=AE=A1=E8=AF=A6=E6=83=85?= =?UTF-8?q?=EF=BC=88VIP=20=E4=B8=93=E5=B1=9E=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=EF=BC=89/v3/messages/detail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + examples/batch_push_example.py | 13 +++++++++++++ examples/push_example.py | 5 +++-- examples/report_example.py | 16 +++++++++++++--- jpush/__init__.py | 2 +- jpush/core.py | 2 +- jpush/push/core.py | 22 ++++++++++++++++++++++ jpush/push/payload.py | 4 +++- jpush/report/core.py | 16 ++++++++++++++-- tests/conf.py | 3 --- tests/conf.py.example | 3 +++ 11 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 examples/batch_push_example.py delete mode 100644 tests/conf.py create mode 100644 tests/conf.py.example diff --git a/.gitignore b/.gitignore index b03798e..3de25b9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ jpush.egg-info/ .idea/ examples/conf.py +/tests/conf.py diff --git a/examples/batch_push_example.py b/examples/batch_push_example.py new file mode 100644 index 0000000..31d4d98 --- /dev/null +++ b/examples/batch_push_example.py @@ -0,0 +1,13 @@ +from conf import app_key, master_secret +import jpush + +_jpush = jpush.JPush(app_key, master_secret) +_jpush.set_logging("DEBUG") + +push = _jpush.create_push() +single_payload_list = [ + {'platform':'all', 'target':'regid1', 'notification':{'alert':'alert content'}}, + {'platform':'all', 'target':'regid2', 'notification':{'alert':'alert content'}} +] +response = push.batch_push_by_regid(single_payload_list) +print(response) \ No newline at end of file diff --git a/examples/push_example.py b/examples/push_example.py index 0e5f03d..4d6b3d1 100644 --- a/examples/push_example.py +++ b/examples/push_example.py @@ -1,4 +1,5 @@ -from . import jpush, app_key, master_secret +from conf import app_key, master_secret +import jpush _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") @@ -106,4 +107,4 @@ def validate(): push.audience = jpush.all_ push.notification = jpush.notification(alert="Hello, world!") push.platform = jpush.all_ - push.send_validate() + push.send_validate() \ No newline at end of file diff --git a/examples/report_example.py b/examples/report_example.py index 679cca5..0f52875 100644 --- a/examples/report_example.py +++ b/examples/report_example.py @@ -1,4 +1,5 @@ -from . import jpush, app_key, master_secret +from conf import app_key, master_secret +import jpush _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") @@ -7,11 +8,20 @@ def messages(): report.get_messages("3289406737") -def receivede(): +def messages_detail(): + report.get_messages_detail("3289406737") + +def received(): report.get_received("3289406737") +def received_detail(): + report.get_received_detail("3289406737") + def users(): report.get_users("DAY","2016-04-10","3") def status(): - report.get_status_messages('3289406737', ['xxx']) + report.get_status_message('3289406737', ['xxx']) + +messages_detail() +received_detail() \ No newline at end of file diff --git a/jpush/__init__.py b/jpush/__init__.py index 223e587..feeb906 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.7' +__version__ = '3.3.8' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default diff --git a/jpush/core.py b/jpush/core.py index 29022d7..ea667f7 100644 --- a/jpush/core.py +++ b/jpush/core.py @@ -60,7 +60,7 @@ def push(self, payload): url = common.get_url('push', self.zone) + 'push' self._request('POST', body, url, 'application/json', version=1) - def set_logging(self, level): + def set_logging(self, level): level_list= ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"] if level in level_list: if(level == "CRITICAL"): diff --git a/jpush/push/core.py b/jpush/push/core.py index 9976d9a..bcd12ea 100644 --- a/jpush/push/core.py +++ b/jpush/push/core.py @@ -80,6 +80,28 @@ def get_cid(self, count, type = None): response = self._jpush._request('GET', body, url, 'application/json', version=3, params = params) return PushResponse(response) + def batch_push_by_regid(self, single_payload_list): + cid_response = self.get_cid(len(single_payload_list), 'push') + cidlist = cid_response.payload['cidlist'] + batch_payload = {"pushlist":{}} + for index in range(len(single_payload_list)): + batch_payload["pushlist"][cidlist[index]] = single_payload_list[index] + body = json.dumps(batch_payload) + url = common.get_url('push', self.zone) + 'push/batch/regid/single' + response = self._jpush._request('POST', body, url, 'application/json', version=3) + return PushResponse(response) + + def batch_push_by_alias(self, single_payload_list): + cid_response = self.get_cid(len(single_payload_list), 'push') + cidlist = cid_response.payload['cidlist'] + batch_payload = {"pushlist":{}} + for index in range(len(single_payload_list)): + batch_payload["pushlist"][cidlist[index]] = single_payload_list[index] + body = json.dumps(batch_payload) + url = common.get_url('push', self.zone) + 'push/batch/alias/single' + response = self._jpush._request('POST', body, url, 'application/json', version=3) + return PushResponse(response) + class PushResponse(object): """Response to a successful push notification send. diff --git a/jpush/push/payload.py b/jpush/push/payload.py index c2353a9..6f1559a 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -84,7 +84,7 @@ def ios(alert=None, badge='+1', sound=None, content_available=False, def android(alert, title=None, builder_id=None, extras=None, priority=None, category=None, style=None, alert_type=None, - big_text=None, inbox=None, big_pic_path=None, large_icon=None, intent=None): + big_text=None, inbox=None, big_pic_path=None, large_icon=None, intent=None, channel_id=None): """Android specific platform override payload. :keyword alert: String alert text.If you set alert to a empty string,then the payload @@ -103,6 +103,8 @@ def android(alert, title=None, builder_id=None, extras=None, payload['title'] = title if builder_id is not None: payload['builder_id'] = builder_id + if channel_id is not None: + payload['channel_id'] = channel_id if priority is not None: payload['priority'] = priority if category is not None: diff --git a/jpush/report/core.py b/jpush/report/core.py index 9256101..b79b077 100644 --- a/jpush/report/core.py +++ b/jpush/report/core.py @@ -22,8 +22,14 @@ def get_received(self,msg_ids): received = self.send("GET", url, params = params) return received - def get_status_messages(self, msg_id, reg_ids, date=None): - url = common.get_url('report', self.zone) + 'status/messages' + def get_received_detail(self, msg_ids): + url = common.get_url('report', self.zone) + 'received/detail' + params = {'msg_ids': msg_ids} + response = self.send("GET", url, params = params) + return response + + def get_status_message(self, msg_id, reg_ids, date=None): + url = common.get_url('report', self.zone) + 'status/message' if not isinstance(reg_ids, list): reg_ids = [reg_ids] body = { @@ -41,6 +47,12 @@ def get_messages(self, msg_ids): messages = self.send("GET", url, params = params) return messages + def get_messages_detail(self, msg_ids): + url = common.get_url('report', self.zone) + 'messages/detail' + params = {'msg_ids': msg_ids} + response = self.send("GET", url, params = params) + return response + def get_users(self, time_unit,start,duration): url = common.get_url('report', self.zone) + 'users' params = { diff --git a/tests/conf.py b/tests/conf.py deleted file mode 100644 index 76aa676..0000000 --- a/tests/conf.py +++ /dev/null @@ -1,3 +0,0 @@ -# please put your app_key and master_secret here -app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'cae22120eed6835e486399a7' diff --git a/tests/conf.py.example b/tests/conf.py.example new file mode 100644 index 0000000..c1f599a --- /dev/null +++ b/tests/conf.py.example @@ -0,0 +1,3 @@ +# please put your app_key and master_secret here +app_key = u'xxxxxx' +master_secret = u'xxxxxx' From 470d2d027c518f18245f0a8a61c93e440a76b551 Mon Sep 17 00:00:00 2001 From: wangjq Date: Wed, 27 Nov 2019 17:19:09 +0800 Subject: [PATCH 12/22] long_description_content_type="text/markdown", --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 484e354..ea8c366 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'), license='MIT License', long_description=open("README.rst", "r").read(), - + long_description_content_type="text/markdown", url='https://github.com/jpush/jpush-api-python-client', author='jpush', author_email='support@jpush.cn', From 2bcac52a760dc57a5e0150b85a32aaf905d024cd Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 11:30:56 +0800 Subject: [PATCH 13/22] Create python-publish.yml --- .github/workflows/python-publish.yml | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..3bfabfc --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,36 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From 95a09c2ba9a1f9625fa0eef6e515be235e63a1fc Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 11:51:33 +0800 Subject: [PATCH 14/22] Delete .github/workflows directory --- .github/workflows/python-publish.yml | 36 ---------------------------- 1 file changed, 36 deletions(-) delete mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 3bfabfc..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Upload Python Package - -on: - release: - types: [published] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} From 4942b32746ae9b94374ef2a27c0f2a8eff2f475c Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 12:17:03 +0800 Subject: [PATCH 15/22] Create python-publish.yml --- .github/workflows/python-publish.yml | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..7d3b556 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,38 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* From 0a62f2861920756a38f0815b0be416759f5ee49f Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 14:42:49 +0800 Subject: [PATCH 16/22] Delete .github/workflows directory --- .github/workflows/python-publish.yml | 38 ---------------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 7d3b556..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Upload Python Package - -on: - release: - types: [published] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* From 0385158e60f3d3ce875794c8aa13dba5b9754594 Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 14:43:07 +0800 Subject: [PATCH 17/22] Create python-publish.yml --- .github/workflows/python-publish.yml | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..3bfabfc --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,36 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From 2e62f4bcfebeec46cfc9cb04b84e201b5b2736b3 Mon Sep 17 00:00:00 2001 From: Ruibo Zhang Date: Wed, 28 Jul 2021 14:53:58 +0800 Subject: [PATCH 18/22] update automatic publish release --- jpush/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpush/__init__.py b/jpush/__init__.py index feeb906..86f69dd 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -75,7 +75,7 @@ schedulepayload, ] -__version__ = '3.3.8' +__version__ = '3.3.9' VERSION = tuple(map(int, __version__.split('.'))) # Silence urllib3 INFO logging by default From bed9b0897b36c190824f9593c5e07b1f2a0e216a Mon Sep 17 00:00:00 2001 From: Anonymous <38679446+SlipChik@users.noreply.github.com> Date: Wed, 28 Jul 2021 15:47:44 +0800 Subject: [PATCH 19/22] Update python-publish.yml --- .github/workflows/python-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3bfabfc..a8091e8 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -27,6 +27,7 @@ jobs: run: | python -m pip install --upgrade pip pip install build + pip install wheel - name: Build package run: python -m build - name: Publish package From 8319264a624a21f894ba09ec3b633d48bbfbad8c Mon Sep 17 00:00:00 2001 From: RaymondYao <45799780+YongquanYao@users.noreply.github.com> Date: Wed, 24 Nov 2021 15:32:31 -0500 Subject: [PATCH 20/22] fix invalid parameter issue of get_status_mesage. --- jpush/report/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jpush/report/core.py b/jpush/report/core.py index b79b077..83d6855 100644 --- a/jpush/report/core.py +++ b/jpush/report/core.py @@ -29,6 +29,7 @@ def get_received_detail(self, msg_ids): return response def get_status_message(self, msg_id, reg_ids, date=None): + import json url = common.get_url('report', self.zone) + 'status/message' if not isinstance(reg_ids, list): reg_ids = [reg_ids] @@ -38,6 +39,7 @@ def get_status_message(self, msg_id, reg_ids, date=None): } if date is not None: body['date'] = date + body = json.dumps(body) sm = self.send("POST", url, body = body) return sm From 4453844e9cbf3df42f229b30ec5a22a046e181fb Mon Sep 17 00:00:00 2001 From: RaymondYao <45799780+YongquanYao@users.noreply.github.com> Date: Wed, 24 Nov 2021 16:09:30 -0500 Subject: [PATCH 21/22] feat report_example.py --- examples/report_example.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/report_example.py b/examples/report_example.py index 0f52875..89a5b7e 100644 --- a/examples/report_example.py +++ b/examples/report_example.py @@ -21,7 +21,9 @@ def users(): report.get_users("DAY","2016-04-10","3") def status(): - report.get_status_message('3289406737', ['xxx']) + msgid = '3289406737' + regid = 'xxx' + report.get_status_message(int(msgid), [regid]) messages_detail() received_detail() \ No newline at end of file From 12fc3561219dff8ad021182a8da37f08f0ff9c49 Mon Sep 17 00:00:00 2001 From: kex Date: Fri, 13 Jun 2025 11:29:59 +0800 Subject: [PATCH 22/22] support hmos --- docs/push/push.md | 2 +- examples/device_example.py | 6 ++--- examples/push_example.py | 9 +++++--- jpush/__init__.py | 2 ++ jpush/push/__init__.py | 1 + jpush/push/payload.py | 42 +++++++++++++++++++++++++++++++++-- setup.py | 4 ++-- tests/devices/test_devices.py | 6 ++--- tests/push/test_message.py | 6 +++++ 9 files changed, 64 insertions(+), 14 deletions(-) diff --git a/docs/push/push.md b/docs/push/push.md index 2f09e66..17bd5cb 100644 --- a/docs/push/push.md +++ b/docs/push/push.md @@ -250,7 +250,7 @@ ios(alert=None, badge='+1', sound=None, content_available=False, mutable_conte 返回值 -> ios payload 字典 +> android payload 字典 ##### android payload ``` diff --git a/examples/device_example.py b/examples/device_example.py index 8c51fd5..344a8e5 100644 --- a/examples/device_example.py +++ b/examples/device_example.py @@ -6,7 +6,7 @@ def alias_user(): alias = "alias1" - platform = "android,ios" + platform = "android,ios,hmos" device.get_aliasuser(alias, platform) def ctrl_tag(): @@ -20,12 +20,12 @@ def get_device(): def delete_alias(): alias = "alias1" - platform = "android,ios" + platform = "android,ios,hmos" device.delete_alias(alias, platform) def delete_tag(): tag = "ddd" - platform = "android,ios" + platform = "android,ios,hmos" device.delete_tag(tag, platform) def check_tag(): diff --git a/examples/push_example.py b/examples/push_example.py index 4d6b3d1..c854fbf 100644 --- a/examples/push_example.py +++ b/examples/push_example.py @@ -58,8 +58,9 @@ def notification(): ios = jpush.ios(alert="Hello, IOS JPush!", sound="a.caf", extras={'k1':'v1'}) android = jpush.android(alert="Hello, Android msg", priority=1, style=1, alert_type=1,big_text='jjjjjjjjjj', extras={'k1':'v1'}) + hmos = jpush.hmos(alert="Hello, HMOS JPush!", category="category", large_icon="large_icon", intent={"url":"action.system.home"}, extras={'k1':'v1'}, style="style", inbox="inbox") - push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios) + push.notification = jpush.notification(alert="Hello, JPush!", android=android, ios=ios, hmos=hmos) # pprint (push.payload) result = push.send() @@ -77,7 +78,8 @@ def platfrom_msg(): push.audience = jpush.all_ ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", sound="a.caf", extras={'k1':'v1'}) android_msg = jpush.android(alert="Hello, android msg") - push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg) + hmos_msg = jpush.hmos(alert="Hello, HMOS JPush msg") + push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg, hmos=hmos_msg) push.message=jpush.message("content",extras={'k2':'v2','k3':'v3'}) push.platform = jpush.all_ push.send() @@ -88,7 +90,8 @@ def silent(): push.audience = jpush.all_ ios_msg = jpush.ios(alert="Hello, IOS JPush!", badge="+1", extras={'k1':'v1'}, sound_disable=True) android_msg = jpush.android(alert="Hello, android msg") - push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg) + hmos_msg = jpush.hmos(alert="Hello, HMOS JPush msg") + push.notification = jpush.notification(alert="Hello, JPush!", android=android_msg, ios=ios_msg, hmos=hmos_msg) push.platform = jpush.all_ push.send() diff --git a/jpush/__init__.py b/jpush/__init__.py index 86f69dd..902ab79 100644 --- a/jpush/__init__.py +++ b/jpush/__init__.py @@ -13,6 +13,7 @@ notification, ios, android, + hmos, winphone, platform, audience, @@ -57,6 +58,7 @@ notification, ios, android, + hmos, winphone, message, smsmessage, diff --git a/jpush/push/__init__.py b/jpush/push/__init__.py index 6720ea6..efadd49 100644 --- a/jpush/push/__init__.py +++ b/jpush/push/__init__.py @@ -14,6 +14,7 @@ android, ios, winphone, + hmos, platform, cid, notification, diff --git a/jpush/push/payload.py b/jpush/push/payload.py index 6f1559a..b816ff9 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -13,13 +13,14 @@ string_types = (str, unicode) -def notification(alert=None, ios=None, android=None, winphone=None): +def notification(alert=None, ios=None, android=None, winphone=None,hmos=None): """Create a notification payload. :keyword alert: A simple text alert, applicable for all platforms. :keyword ios: An iOS platform override, as generated by :py:func:`ios`. :keyword android: An Android platform override, as generated by :py:func:`android`. :keyword winphone: A MPNS platform override, as generated by :py:func:`mpns`. + :keyword hmos: A hmos platform override, as generated by :py:func:`hmos`. """ payload = {} @@ -31,6 +32,8 @@ def notification(alert=None, ios=None, android=None, winphone=None): payload['android'] = android if winphone is not None: payload['winphone'] = winphone + if hmos is not None: + payload['hmos'] = hmos if not payload: raise ValueError("Notification body may not be empty") return payload @@ -48,6 +51,9 @@ def ios(alert=None, badge='+1', sound=None, content_available=False, :keyword extras: A set of key/value pairs to include in the push payload sent to the device. :keyword sound_disalbe: Disable sound to implement slient push. + :keyword mutable_content: If True, enables modifying notification content in iOS service extension. + :keyword category: String category for iOS notification action buttons. + :keyword thread_id: String identifier to group related notifications in iOS. >>> ios(alert='Hello!', sound='cat.caf', ... extras={'articleid': '12345'}) @@ -147,6 +153,38 @@ def winphone(alert, title=None, _open_page=None, extras=None): payload['extras'] = extras return payload +def hmos(alert, title=None, category=None, large_icon=None, intent=None, extras=None, style=None, inbox=None): + """Hmos specific platform override payload. + more info:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push#hmos + + :keyword alert: String alert text. + :keyword title: String + :keyword category: String + :keyword large_icon: String + :keyword intent: A set of key/value pairs to include in the push payload + :keyword extras: A set of key/value pairs to include in the push payload + :keyword style: String + :keyword inbox: String + """ + payload = {} + if alert is not None: + payload['alert'] = alert + if title is not None: + payload['title'] = title + if category is not None: + payload['category'] = category + if large_icon is not None: + payload['large_icon'] = large_icon + if intent is not None: + payload['intent'] = intent + if extras is not None: + payload['extras'] = extras + if style is not None: + payload['style'] = style + if inbox is not None: + payload['inbox'] = inbox + return payload + def message(msg_content, title=None, content_type=None, extras=None): """Inner-conn push message payload creation. @@ -199,7 +237,7 @@ def platform(*types): if len(types) == 1 and types[0] == 'all': return 'all' for t in types: - if t not in ('ios', 'android', 'winphone'): + if t not in ('ios', 'android', 'winphone', 'hmos'): raise ValueError("Invalid platform '%s'" % t) return [t for t in types] diff --git a/setup.py b/setup.py index ea8c366..6e1f410 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ try: from setuptools import setup except (ImportError): - from distutils.core import setup + from distutils.core import setup _version_re = re.compile(r'__version__\s+=\s+(.*)') @@ -16,7 +16,7 @@ name='jpush', version=version, description='JPush\'s officially supported Python client library', - keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push'), + keywords=('JPush', 'JPush API', 'Android Push', 'iOS Push', 'HMOS Push'), license='MIT License', long_description=open("README.rst", "r").read(), long_description_content_type="text/markdown", diff --git a/tests/devices/test_devices.py b/tests/devices/test_devices.py index 96851a9..9bc0d54 100644 --- a/tests/devices/test_devices.py +++ b/tests/devices/test_devices.py @@ -19,7 +19,7 @@ def test_create_device(self): def test_aliasuser(self): alias = "alias1" - platform = "android,ios" + platform = "android,ios,hmos" result = device.get_aliasuser(alias, platform) self.assertEqual(result.status_code, 200) @@ -44,13 +44,13 @@ def test_get_device(self): def test_remove_alias(self): alias = "alias1" - platform = "android,ios" + platform = "android,ios,hmos" result = device.delete_alias(alias, platform) self.assertEqual(result.status_code, 200) def test_remove_tags(self): tag = "ddd" - platform = "android,ios" + platform = "android,ios,hmos" result = device.delete_tag(tag, platform) self.assertEqual(result.status_code, 200) diff --git a/tests/push/test_message.py b/tests/push/test_message.py index 13188bb..48dae4d 100644 --- a/tests/push/test_message.py +++ b/tests/push/test_message.py @@ -33,6 +33,12 @@ def test_winphone(self): jpush.notification(winphone=jpush.winphone(alert="Hello", extras={'k3':'v3'})), {'winphone': {'extras': {'k3': 'v3'}, 'alert': 'Hello'}} ) + + def test_hmos(self): + self.assertEqual( + jpush.notification(hmos=jpush.hmos(alert="Hello", title="Title", extras={'k4':'v4'})), + {'hmos': {'extras': {'k4': 'v4'}, 'alert': 'Hello', 'title': 'Title'}} + ) def test_push(self): _jpush = jpush.JPush(app_key, master_secret)