Preauth

Brightcells 6 anos atrás
pai
commit
b7caee0a32
3 arquivos alterados com 49 adições e 1 exclusões
  1. 8 0
      kodo/oauth_settings.py
  2. 34 0
      page/preauth_views.py
  3. 7 1
      page/urls.py

+ 8 - 0
kodo/oauth_settings.py

@@ -1,8 +1,12 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+from django.conf import settings
4
+
3 5
 
4 6
 def DJANGO_WE_CFG_FUNC(request, state=None):
5 7
     """ WeChat CFG Callback Func """
8
+    if state in ['component_auth', 'component_callback', 'component_preauth_callback']:
9
+        return settings.WECHAT.get('COMPONENT')
6 10
 
7 11
 
8 12
 def DJANGO_WE_QUOTE_STATE_FUNC(request, state):
@@ -31,6 +35,10 @@ def DJANGO_WE_SHARE_FUNC(request, state=None):
31 35
 
32 36
 def DJANGO_WE_MESSAGE_CALLBACK_FUNC(request, data, decrypted=None):
33 37
     """ WeChat Message Callback Func """
38
+
39
+
40
+def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None):
41
+    """ WeChat Component Message Callback Func """
34 42
     from account.models import UserInfo
35 43
 
36 44
     event = data.get('Event', '')

+ 34 - 0
page/preauth_views.py

@@ -0,0 +1,34 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from __future__ import division
4
+
5
+from django.conf import settings
6
+from django.shortcuts import render
7
+from pywe_component import get_pre_auth_url
8
+from pywe_component_preauthcode import component_preauthcode
9
+from pywe_storage import RedisStorage
10
+
11
+from utils.redis.connect import r
12
+
13
+
14
+COMPONENT = settings.WECHAT.get('COMPONENT', {})
15
+
16
+
17
+def preauth(request):
18
+    return render(request, 'page/preauth/preauth.html', {
19
+        'domain': settings.DOMAIN,
20
+        'preauthurl': settings.DJANGO_DEBUG_PREAUTHURL or get_pre_auth_url(
21
+            COMPONENT.get('appID'),
22
+            pre_auth_code=component_preauthcode(appid=COMPONENT['appID'], secret=COMPONENT['appsecret'], storage=RedisStorage(r)),
23
+            redirect_uri=settings.DJANGO_WE_COMPONENT_REDIRECT_URI,
24
+            auth_type=3,
25
+            mobi=request.weixin,
26
+        ),
27
+    })
28
+
29
+
30
+def preauth_success(request):
31
+    return render(request, 'page/preauth/preauth_success.html', {
32
+        'domain': settings.DOMAIN,
33
+        'authorizer_appid': settings.DJANGO_DEBUG_AUTHORIZER_APPID,
34
+    })

+ 7 - 1
page/urls.py

@@ -4,7 +4,7 @@ from django.conf.urls import url
4 4
 
5 5
 from account import tourguide_views
6 6
 from group import lensman_views
7
-from page import info_views, oauth_views, page_views, sale_views, screen_views
7
+from page import info_views, oauth_views, page_views, preauth_views, sale_views, screen_views
8 8
 
9 9
 
10 10
 urlpatterns = [
@@ -34,6 +34,12 @@ urlpatterns = [
34 34
     url(r'^clerk/info$', info_views.clerk_info_oauth, name='clerk_info_oauth'),  # 店员信息授权页面
35 35
 ]
36 36
 
37
+# 微信第三方平台
38
+urlpatterns += [
39
+    url(r'^preauth$', preauth_views.preauth, name='preauth'),
40
+    url(r'^preauth/success$', preauth_views.preauth_success, name='preauth_success'),
41
+]
42
+
37 43
 urlpatterns += [
38 44
     url(r'^qr$', screen_views.screen_admin_oauthqr, name='oauthqr'),
39 45
     url(r'^screen/admin/oauth$', screen_views.screen_admin_oauth, name='screen_admin_oauth'),