PYTHON SDK
v2.0.3
add_messages_json.py
이 파일의 문서화 페이지로 가기
1 # vi:set sw=4 ts=4 expandtab:
2 # -*- coding: utf8 -*-
3 
4 import sys
5 import json
6 
7 sys.path.insert(0, "../../")
8 
9 from sdk.api.group_message import GroupMessage
10 from sdk.exceptions import CoolsmsException
11 
12 ## @brief This sample code demonstrate how to add messages into group through CoolSMS Rest API
13 if __name__ == "__main__":
14 
15  # set api key, api secret
16  api_key = "#ENTER_YOUR_OWN#"
17  api_secret = "#ENTER_YOUR_OWN#"
18 
19  # Options(group_id, to, from, text) are mandatory. must be filled
20  group_id = "GID57A82D462CBBF" # Group ID
21 
22  json_data = list()
23  params = dict()
24  params["type"] = "sms" # Message type ( sms, lms, mms, ata )
25  params['to'] = '01000000000' # Recipients Number '01000000000,01000000001'
26  params['from'] = '01000000000' # Sender number
27  params['text'] = 'Test Message' # Message
28 
29  # Optional parameters for your own needs
30  # params["image_id"] = "image_id" # image_id. type must be set as 'MMS'
31  # params["refname"] = "" # Reference name
32  # params["country"] = "82" # Korea(82) Japan(81) America(1) China(86) Default is Korea
33  # params["datetime"] = "20140106153000" # Format must be(YYYYMMDDHHMISS) 2014 01 06 15 30 00 (2014 Jan 06th 3pm 30 00)
34  # params["subject"] = "Message Title" # set msg title for LMS and MMS
35  # params["delay"] = "10") # '0~20' delay messages
36  # params["sender_key"] = "5554025sa8e61072frrrd5d4cc2rrrr65e15bb64" # 알림톡 사용을 위해 필요합니다. 신청방법 : http://www.coolsms.co.kr/AboutAlimTalk
37  # params["template_code"] = "C004" # 알림톡 template code 입니다. 자세한 설명은 http://www.coolsms.co.kr/AboutAlimTalk을 참조해주세요.
38 
39  json_data.append(params) # 원하는 만큼 params를 넣어줍니다
40  json_data = json.dumps(json_data)
41 
42  cool = GroupMessage(api_key, api_secret)
43 
44  try:
45  response = cool.add_messages_json(group_id, json_data)
46  for data in response:
47  print("Success Count : %s" % data['success_count'])
48  print("Error Count : %s" % data['error_count'])
49 
50  if "error_list" in response:
51  print("Error List : %s" % response['error_list'])
52 
53  except CoolsmsException as e:
54  print("Error Code : %s" % e.code)
55  print("Error Message : %s" % e.msg)
56 
57  sys.exit()
management group message, using Rest API