作者 vanwhebin

修改企业微信的配置

... ... @@ -7,9 +7,6 @@ from rest_framework.generics import CreateAPIView, RetrieveAPIView, UpdateAPIVie
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from rest_framework.exceptions import ValidationError
from rest_framework.views import APIView
from rest_framework.response import Response
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from .serializers import ProjectSerializer
from .models import Auditor, Project, Result
... ... @@ -17,11 +14,7 @@ from utils.helpers import WxPushHelper
from utils.pagination import MyPageNumberPagination
from utils.util import response
from wxProject.settings import FRONT_URL
AUDITORS = (
(1, '邓望明'),
(2, '杜波')
)
from wxProject.qywx_settings import Conf, project_conf
class CreateProject(CreateAPIView):
... ... @@ -30,7 +23,7 @@ class CreateProject(CreateAPIView):
def post(self, request, *args, **kwargs):
super(CreateProject, self).__init__()
wx_client = WxPushHelper()
wx_client = WxPushHelper(Conf[project_conf['APP_ID']])
serializer = ProjectSerializer(data=request.data)
if not serializer.is_valid():
raise ValidationError(serializer.errors)
... ... @@ -106,7 +99,7 @@ class AuditProject(UpdateAPIView):
result.memo = request.data.get('memo', '')
result.save()
wx_client = WxPushHelper()
wx_client = WxPushHelper(Conf[project_conf['APP_ID']])
full_audit_done = self._check_audit(obj)
url = re.sub("PK", str(obj.id), FRONT_URL['flow_detail'])
url = re.sub("REDIRECT_URL", parse.quote(url, safe=''), FRONT_URL['wx_authorize'])
... ...
... ... @@ -8,10 +8,17 @@ django-filter==2.4.0
djangorestframework==3.12.1
djangorestframework-simplejwt==4.4.0
idna==2.10
lml==0.1.0
mysqlclient==2.0.1
Pillow==7.2.0
pyexcel==0.6.5
pyexcel-io==0.6.4
pyexcel-xls==0.6.1
PyJWT==1.7.1
pytz==2020.1
requests==2.24.0
sqlparse==0.3.1
texttable==1.6.3
urllib3==1.25.10
xlrd==1.2.0
xlwt==1.3.0
... ...
from django.contrib import admin
# Register your models here.
... ...
from django.apps import AppConfig
class SkuConfig(AppConfig):
name = 'sku'
... ...
from django.db import models
# Create your models here.
... ...
from django.test import TestCase
# Create your tests here.
... ...
from django.shortcuts import render
# Create your views here.
... ...
... ... @@ -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'])
... ...
# _*_ coding: utf-8 _*_
# @Time : 2020/11/2 18:01
# @Author vanwhebin
from wxProject.settings import DEBUG
DEBUG = DEBUG
# 企业微信的一些配置项
project_conf = {
"title": "产品立项",
"CORP_ID": "ww0f3efc2873ad11c3",
"APP_ID": '1000078',
"APP_SECRET": "7MHpdQICiegx9rIc4iZrEPunb1aYUqdJYKSW9v7a1A8",
}
sku_conf = {
"title": "sku条目审批应用",
"CORP_ID": "ww0f3efc2873ad11c3",
"APP_ID": '1000081',
"APP_SECRET": "_O_MrxbQO1vojzNBPAiaF_MdzikHRbnVfFc3v8iOtKo",
}
Conf = {
"1000078": project_conf,
"1000081": sku_conf
}
... ...