...
|
...
|
@@ -12,6 +12,7 @@ from libs.qywx.conf import Conf |
|
|
from libs.qywx.CorpApi import CorpApi, CORP_API_TYPE
|
|
|
from usercenter.models import UserManager, User
|
|
|
from utils.util import response
|
|
|
from wxProject.qywx_settings import Conf
|
|
|
|
|
|
|
|
|
class WxRequiredMixin(View):
|
...
|
...
|
@@ -27,9 +28,13 @@ class WxRequiredMixin(View): |
|
|
|
|
|
class WxPushHelper:
|
|
|
api = None
|
|
|
conf = None
|
|
|
|
|
|
def __init__(self):
|
|
|
self.api = CorpApi(Conf['CORP_ID'], Conf['APP_SECRET'])
|
|
|
def __init__(self, conf):
|
|
|
if not conf:
|
|
|
raise ValueError("企业微信配置有误,配置项不能为空")
|
|
|
self.conf = conf
|
|
|
self.api = CorpApi(self.conf['CORP_ID'], self.conf['APP_SECRET'])
|
|
|
|
|
|
def get_corp_user_id_by_code(self, code):
|
|
|
return self.api.httpCall(CORP_API_TYPE['GET_USER_INFO_BY_CODE'], {"CODE": code})
|
...
|
...
|
@@ -39,7 +44,7 @@ class WxPushHelper: |
|
|
|
|
|
def push_text(self, user_wx_id, content):
|
|
|
data = {
|
|
|
"agentid": Conf['APP_ID'], # 企业应用ID
|
|
|
"agentid": self.conf['APP_ID'], # 企业应用ID
|
|
|
"msgtype": 'text', # 消息类型为文本
|
|
|
"touser": user_wx_id, # 接受消息的对象
|
|
|
"text": {
|
...
|
...
|
@@ -52,7 +57,7 @@ class WxPushHelper: |
|
|
data = {
|
|
|
"touser": str(user_wx_id),
|
|
|
"msgtype": "textcard",
|
|
|
"agentid": Conf['APP_ID'], # 企业应用ID
|
|
|
"agentid": self.conf['APP_ID'], # 企业应用ID
|
|
|
"textcard": {
|
|
|
"title": "产品立项流程通知",
|
|
|
"description": description,
|
...
|
...
|
@@ -72,8 +77,8 @@ class WxUserlogin(APIView): |
|
|
permission_classes = (AllowAny, )
|
|
|
|
|
|
@staticmethod
|
|
|
def _get_user_info(code):
|
|
|
client = WxPushHelper()
|
|
|
def _get_user_info(code, app_id):
|
|
|
client = WxPushHelper(Conf[app_id])
|
|
|
corp_user = client.get_corp_user_id_by_code(code)
|
|
|
if "errcode" in corp_user and corp_user['errcode'] == 0 and "UserId" in corp_user:
|
|
|
return client.get_user_info_by_corp_user_id(corp_user['UserId'])
|
...
|
...
|
|