diff --git a/api/examples/AppChatTest.py b/api/examples/AppChatTest.py index aed9add..e2fc940 100644 --- a/api/examples/AppChatTest.py +++ b/api/examples/AppChatTest.py @@ -12,7 +12,7 @@ # import sys -sys.path.append("../src/") +sys.path.append("D:/Python/weworkapi_python/api/src") import random @@ -29,14 +29,14 @@ CORP_API_TYPE['APP_CHAT_CREATE'], { 'name' : 'appchat_test', - 'owner' : 'ZhuBiaoYi', - 'userlist' : ['LiShuang', 'ZhuShengBen', 'LinJianEn', 'ZhuBiaoYi', 'XuBin', 'yangpeiyi', 'HaLuoTeQu', 'lucky', 'raindong', 'simon', 'Wang', 'ZhaoDong', 'DengLinSheng', 'Li'], + 'owner' : 'penghaifeng', + 'userlist' : ['penghf', 'shanli', 'penghaifeng', ], 'chatid' : chatid, }) - print response + print (response) chatid = response['chatid'] except ApiException as e : - print e.errCode, e.errMsg + print (e.errCode, e.errMsg) try : ## @@ -45,10 +45,10 @@ { 'chatid' : chatid, 'name' : 'appchat_test_new_name', - 'owner' : 'ZhuShengBen', - 'add_user_list' : ['huqiqi', 'Wang'] + 'owner' : 'shanli', + 'add_user_list' : ['penghaifeng', 'penghf'] }) - print response + print (response) ## response = api.httpCall( @@ -56,50 +56,50 @@ { 'chatid' : chatid, 'name' : '应用发消息测试', - 'owner' : 'ZhuBiaoYi', - 'del_user_list' : 'huqiqi', + 'owner' : 'penghaifeng', + 'del_user_list' : 'penghf', }) - print response + print (response) ## - response = api.httpCall( - CORP_API_TYPE['APP_CHAT_SEND'], - { - 'chatid':chatid, - 'msgtype' : 'text', - 'text' : {'content':'我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党'}, - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), - 'safe' : 1, - }) - print response + #response = api.httpCall( + # CORP_API_TYPE['APP_CHAT_SEND'], + # { + # 'chatid':chatid, + # 'msgtype' : 'text', + # 'text' : {'content':'我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党'}, + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'safe' : 1, + # }) + #print (response) ## - response = api.httpCall( - CORP_API_TYPE['APP_CHAT_SEND'], - { - 'chatid':chatid, - 'msgtype' : 'image', - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), - 'image' : { - 'media_id':'3A9Jo9CHit_5UTfOVE38_067dUJQlLs30mOa9FC0a4jEGeoQgpLCZgc7rEza6TbfB', - }, - 'safe' : 1, - }) - print response + #response = api.httpCall( + # CORP_API_TYPE['APP_CHAT_SEND'], + # { + # 'chatid':chatid, + # 'msgtype' : 'image', + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'image' : { + # 'media_id':'3lpbB2Z89bBmqYRVMIcpPF7zl1h-V-6oCZRxT3ewRzPQ', + # }, + # 'safe' : 1, + # }) + #print (response) ## - response = api.httpCall( - CORP_API_TYPE['APP_CHAT_SEND'], - { - 'chatid':chatid, - 'msgtype' : 'file', - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), - 'file' : { - 'media_id':'35L7MmcpGdyFfqjbGhbECCkGcaNsUajaPQifGLJq_H5E', - }, - 'safe' : 1, - }) - print response + #response = api.httpCall( + # CORP_API_TYPE['APP_CHAT_SEND'], + # { + # 'chatid':chatid, + # 'msgtype' : 'file', + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'file' : { + # 'media_id':'363LmmkUIEYosxmHDp8AZyC485ii7EFEdIFAHYnjy1s4', + # }, + # 'safe' : 1, + # }) + #print (response) ## @@ -107,64 +107,65 @@ CORP_API_TYPE['APP_CHAT_SEND'], { 'chatid':chatid, - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), 'msgtype' : 'voice', 'voice' : { - 'media_id':'3x1yb34061fDXjyUXy2rWNd-a-hWe-l8eTw2VKyh3bDQ', + 'media_id':'3VIIMc7QzZJqEGxJ8ALwnevPGFksjX0SSV7IhYl0H7YI', }, 'safe' : 1, }) - print response + print (response) ## - response = api.httpCall( - CORP_API_TYPE['APP_CHAT_SEND'], - { - 'chatid':chatid, - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), - 'msgtype' : 'video', - 'video' : { - 'media_id':'3neA1ypnC3k5QnAZqvyVvCesFYUrXietU5F-Ipnj6ZobiD-PuFlXngzPplWXibw9r', - }, - 'safe' : 1, - }) - print response + #response = api.httpCall( + # CORP_API_TYPE['APP_CHAT_SEND'], + # { + # 'chatid':chatid, + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'msgtype' : 'video', + # 'video' : { + # 'media_id':'3jtU3eCcZUpa_aSUGmOUH4PL46ENkQLkdDFU3TL7xgcy2gsKhGl4y4ojwhZX1h8B3', + # }, + # 'safe' : 1, + # }) + #print (response) ## response = api.httpCall( CORP_API_TYPE['APP_CHAT_SEND'], { 'chatid':chatid, - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), 'msgtype' : 'news', "news" : { "articles" : [ { "title" : "图文消息", "description" : "今年中秋节公司有豪礼相送", - "url" : "URL", + "url" : "https://work.weixin.qq.com/", "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", "btntxt":"更多", }, { "title" : "图文消息", "description" : "今年中秋节公司有豪礼相送", - "url" : "URL", + "url" : "https://work.weixin.qq.com/", "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", "btntxt":"更多", }, { "title" : "图文消息", "description" : "今年中秋节公司有豪礼相送", - "url" : "URL", + "url" : "https://work.weixin.qq.com/", "picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", "btntxt":"更多", }, - ]}, - 'safe' : 1, - }, + ] + }, + 'safe' : 0, + }, ) - print response + print (response) ## response = api.httpCall( @@ -172,7 +173,7 @@ { 'chatid':chatid, 'msgtype' : 'textcard', - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), 'textcard' : { 'title':'我是文本卡片消息', 'description' : 'aaaaaaa', @@ -181,7 +182,7 @@ }, 'safe' : 1, }) - print response + print (response) ## response = api.httpCall( @@ -193,31 +194,31 @@ "articles" : [ { "title" : "图文消息(mpnews)", - "thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc", + "thumb_media_id" : "3lpbB2Z89bBmqYRVMIcpPF7zl1h-V-6oCZRxT3ewRzPQ", "author" : "author", "content" : "content", "digest" : "我是图文" }, { "title" : "图文消息(mpnews)", - "thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc", + "thumb_media_id" : "3lpbB2Z89bBmqYRVMIcpPF7zl1h-V-6oCZRxT3ewRzPQ", "author" : "author", "content" : "content", "digest" : "我是图文" }, { "title" : "图文消息(mpnews)", - "thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc", + "thumb_media_id" : "3lpbB2Z89bBmqYRVMIcpPF7zl1h-V-6oCZRxT3ewRzPQ", "author" : "author", "content" : "content", "digest" : "我是图文" }, ] }, - 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), + # 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), 'safe' : 1, }) - print response + print (response) except ApiException as e : - print e.errCode, e.errMsg + print (e.errCode, e.errMsg) diff --git a/api/examples/MessageTest.py b/api/examples/MessageTest.py index c07b005..f44cba6 100644 --- a/api/examples/MessageTest.py +++ b/api/examples/MessageTest.py @@ -12,7 +12,7 @@ # import sys -sys.path.append("../src/") +sys.path.append("D:/Python/weworkapi_python/api/src") import random @@ -27,16 +27,16 @@ response = api.httpCall( CORP_API_TYPE['MESSAGE_SEND'], { - "touser": "ZhuShengBen", - "agentid": 1000002, + "touser": "penghaifeng", + "agentid": 1000015, 'msgtype' : 'text', 'climsgid' : 'climsgidclimsgid_%f' % (random.random()), 'text' : { - 'content':'方法论', + 'content':'Hello,方法论', }, 'safe' : 0, }) - print response + print (response) except ApiException as e : - print e.errCode, e.errMsg + print (e.errCode, e.errMsg) diff --git a/api/examples/TestConf.py b/api/examples/TestConf.py index 9cb01af..075b3a2 100644 --- a/api/examples/TestConf.py +++ b/api/examples/TestConf.py @@ -16,14 +16,14 @@ TestConf = { # 企业的id,在管理端->"我的企业" 可以看到 - "CORP_ID" : "ww55ca070cb9b7eb22", + "CORP_ID" : "wwbd8f59458c7449bd", # "通讯录同步"应用的secret, 开启api接口同步后,可以在管理端->"通讯录同步"看到 - "CONTACT_SYNC_SECRET" : "ktmzrVIlUH0UW63zi7-JyzsgTL9NfwUhHde6or6zwQY", + "CONTACT_SYNC_SECRET" : "cwcGb7p0IGlqoLn16wPONKn-mPzdcpeUpyKZesaIKJQ", # 某个自建应用的id及secret, 在管理端 -> 企业应用 -> 自建应用, 点进相应应用可以看到 - "APP_ID" : 1000002, - "APP_SECRET" : "v1Z2KSw2WqPFECAwn2R0a1dFsanVF5sE4IE6X5ogveQ", + "APP_ID" : 1000015, + "APP_SECRET" : "u8T0E4LqtwpAoFNGwureZlMbV4U5iY7IZf9k9P3NJ04", # 打卡应用的 id 及secrete, 在管理端 -> 企业应用 -> 基础应用 -> 打卡, # 点进去,有个"api"按钮,点开后,会看到 diff --git a/api/examples/UserTest.py b/api/examples/UserTest.py index 1dd6677..9f9876f 100644 --- a/api/examples/UserTest.py +++ b/api/examples/UserTest.py @@ -12,7 +12,7 @@ # import sys -sys.path.append("../src/") +sys.path.append("D:/Python/weworkapi_python/api/src") from CorpApi import * from TestConf import * @@ -29,9 +29,9 @@ 'name' : 'zhangsanfeng', 'mobile' : '131488888888', 'email' : 'zhangsan@ipp.cas.cn', - 'department' : 1, + 'department' : '1', }) - print response + print (response) ## response = api.httpCall( @@ -39,7 +39,7 @@ { 'userid' : 'zhangsan', }) - print response + print (response) ## response = api.httpCall( @@ -47,10 +47,10 @@ { 'userid' : 'zhangsan', }) - print response + print (response) except ApiException as e : - print e.errCode, e.errMsg + print (e.errCode, e.errMsg) ## response = api.httpCall( @@ -58,6 +58,6 @@ { 'userid' : 'zhangsan', }) - print response + print (response) diff --git a/api/src/AbstractApi.py b/api/src/AbstractApi.py index 9c15796..c34dbb5 100644 --- a/api/src/AbstractApi.py +++ b/api/src/AbstractApi.py @@ -18,7 +18,7 @@ import json import requests -sys.path.append("../../") +sys.path.append("D:/Python/weworkapi_python") from conf import DEBUG @@ -105,7 +105,7 @@ def __httpPost(self, url, args) : realUrl = self.__appendToken(url) if DEBUG is True : - print realUrl, args + print (realUrl, args) return requests.post(realUrl, data = json.dumps(args, ensure_ascii = False).encode('utf-8')).json() @@ -113,7 +113,7 @@ def __httpGet(self, url) : realUrl = self.__appendToken(url) if DEBUG is True : - print realUrl + print (realUrl) return requests.get(realUrl).json()