Skip to content

Commit b79aebc

Browse files
committed
feat: 支持自定义网络接入点
Signed-off-by: 金喜 <[email protected]>
1 parent a1a7fdd commit b79aebc

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

dingtalk_stream/stream.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
from .frames import EventMessage
2323
from .frames import CallbackMessage
2424
from .log import setup_default_logger
25-
from .utils import DINGTALK_OPENAPI_ENDPOINT
25+
from .utils import get_dingtalk_endpoint
2626
from .version import VERSION_STRING
2727

2828

2929
class DingTalkStreamClient(object):
30-
OPEN_CONNECTION_API = DINGTALK_OPENAPI_ENDPOINT + '/v1.0/gateway/connections/open'
30+
OPEN_CONNECTION_API = get_dingtalk_endpoint() + '/v1.0/gateway/connections/open'
3131
TAG_DISCONNECT = 'disconnect'
3232

3333
def __init__(self, credential: Credential, logger: logging.Logger = None):
@@ -191,7 +191,8 @@ def get_access_token(self):
191191
'appSecret': self.credential.client_secret,
192192
}
193193
try:
194-
response = requests.post(DINGTALK_OPENAPI_ENDPOINT + '/v1.0/oauth2/accessToken',
194+
url = get_dingtalk_endpoint() + '/v1.0/oauth2/accessToken'
195+
response = requests.post(url,
195196
headers=request_headers,
196197
data=json.dumps(values))
197198
response.raise_for_status()

dingtalk_stream/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# -*- coding:utf-8 -*-
22

3+
import os
4+
35
DINGTALK_OPENAPI_ENDPOINT = "https://api.dingtalk.com"
6+
7+
def get_dingtalk_endpoint():
8+
endpoint_env = os.getenv('DINGTALK_OPENAPI_ENDPOINT')
9+
if endpoint_env:
10+
return endpoint_env
11+
return DINGTALK_OPENAPI_ENDPOINT

dingtalk_stream/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION_STRING = '0.19.1'
1+
VERSION_STRING = '0.20.0'

0 commit comments

Comments
 (0)