39
+                    </select>
40
+                </div>
41
+            </div>
42
+            <div class="weui_cell">
43
+                <div class="weui_cell_hd"><label for="" class="weui_label">手机号</label></div>
44
+                <div class="weui_cell_bd weui_cell_primary">
45
+                    <input id="phone" class="weui_input" type="text" required="required" pattern="[0-9]{11}" value="{{ lensman_info.phone }}" placeholder="请输入手机号">
46
+                </div>
47
+            </div>
48
+            <div class="weui_cell">
49
+                <div class="weui_cell_hd"><label for="" class="weui_label">地址</label></div>
50
+                <div class="weui_cell_bd weui_cell_primary">
51
+                    <input id="location" class="weui_input" type="text" value="{{ lensman_info.location }}" placeholder="请输入地址">
52
+                </div>
53
+            </div>
54
+        </div>
55
+
56
+        <br>
57
+
58
+        <button id="submit" class="weui_btn weui_btn_warn">确认</button>
59
+
60
+        <div class="weui_dialog_alert" id="dialog" style="display: none">
61
+            <div class="weui_mask"></div>
62
+            <div class="weui_dialog">
63
+                <div class="weui_dialog_hd"><strong id="title" class="weui_dialog_title">弹窗标题</strong></div>
64
+                <div id="content" class="weui_dialog_bd">弹窗内容,告知当前页面信息等</div>
65
+                <div class="weui_dialog_ft">
66
+                    <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
67
+                </div>
68
+            </div>
69
+        </div>
70
+
71
+        <div id="toast" style="display: none;">
72
+            <div class="weui_mask_transparent"></div>
73
+            <div class="weui_toast">
74
+                <i class="weui_icon_toast"></i>
75
+                <p class="weui_toast_content">已完成</p>
76
+            </div>
77
+        </div>
78
+    </div>
79
+
80
+    <script src="//cdn.bootcss.com/zepto/1.1.6/zepto.min.js"></script>
81
+    <script>
82
+        $(function() {
83
+            function getURLParameter(name) {
84
+              return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
85
+            }
86
+
87
+            function show_error_dialog(title, content) {
88
+                $('#dialog #title').text(title);
89
+                $('#dialog #content').text(content);
90
+                $('#dialog').show();
91
+            }
92
+            
93
+            function data_check() {
94
+                var unionid = getURLParameter('unionid');
95
+                if (!unionid) {
96
+                    show_error_dialog('微信授权', '微信授权失败,请重新打开页面');
97
+                    return false;
98
+                }
99
+
100
+                var name = $('#name').val();
101
+                if (!name) {
102
+                    show_error_dialog('姓名', '姓名错误,请检查重新输入');
103
+                    return false;
104
+                }
105
+
106
+                var phone_valid = $('#phone').is(':valid');
107
+                if (!phone_valid) {
108
+                    show_error_dialog('手机号', '手机号错误,请检查重新输入');
109
+                    return false;
110
+                }
111
+
112
+                var location = $('#location').val();
113
+                if (!location) {
114
+                    show_error_dialog('地址', '地址错误,请检查重新输入');
115
+                    return false;
116
+                }
117
+
118
+                return {
119
+                    unionid: unionid,
120
+                    name: name,
121
+                    sex: $('#sex option:checked').val(),
122
+                    phone: $('#phone').val(),
123
+                    location: location,
124
+                }
125
+            }
126
+
127
+            $('#submit').click(function () {
128
+                var check_result = data_check();
129
+                if (check_result){
130
+                    $.ajax({
131
+                        type: 'POST',
132
+                        url: 'l/submit',
133
+                        data: check_result,
134
+                        success: function(data) {
135
+                            if (data.status == 200) {
136
+                                $('#toast').show();
137
+                                setTimeout(function () {
138
+                                    $('#toast').hide();
139
+                                }, 1000);
140
+                            } else {
141
+                                show_error_dialog('错误', data.description);
142
+                            }
143
+                        }
144
+                    })
145
+                }
146
+            });
147
+
148
+            $('#dialog .weui_btn_dialog').click(function () {
149
+                $('#dialog').hide();
150
+            })
151
+        });
152
+    </script>
153
+</body>
154
+</html>

+ 15 - 0
page/views.py

@@ -2,6 +2,8 @@
2 2
 
3 3
 from django.shortcuts import render
4 4
 
5
+from account.models import LensmanInfo
6
+
5 7
 
6 8
 def user_agreement(request):
7 9
     return render(request, 'page/user_agreement.html', {})
@@ -9,3 +11,16 @@ def user_agreement(request):
9 11
 
10 12
 def contact_us(request):
11 13
     return render(request, 'page/contact_us.html', {})
14
+
15
+
16
+def lensman_oauth(request):
17
+    unionid = request.GET.get('unionid', '')
18
+
19
+    try:
20
+        lensman = LensmanInfo.objects.get(unionid=unionid)
21
+    except LensmanInfo.DoesNotExist:
22
+        lensman = None
23
+
24
+    return render(request, 'page/lensman_oauth.html', {
25
+        'lensman_info': lensman and lensman.data
26
+    })

+ 8 - 0
pai2/urls.py

@@ -23,6 +23,7 @@ from rest_framework import routers
23 23
 
24 24
 from account import views as account_views
25 25
 from group import views as group_views
26
+from group import lensman_views
26 27
 from page import views as page_views
27 28
 from photo import views as photo_views
28 29
 from website import views as website_views
@@ -65,6 +66,8 @@ urlpatterns += [
65 66
 urlpatterns += [
66 67
     url(r'^page/user_agreement$', page_views.user_agreement, name='user_agreement'),  # 用户协议页面
67 68
     url(r'^page/contact_us$', page_views.contact_us, name='contact_us'),  # 联系我们页面
69
+
70
+    url(r'^page/lensman$', page_views.lensman_oauth, name='lensman_oauth'),  # 摄影师授权页面
68 71
 ]
69 72
 
70 73
 urlpatterns += [
@@ -75,6 +78,11 @@ urlpatterns += [
75 78
     url(r'^termofservice$', website_views.pai2_termofservice, name='pai2_termofservice'),  # 官网服务条款
76 79
 ]
77 80
 
81
+# 摄影师相关
82
+urlpatterns += [
83
+    url(r'^page/l/submit$', lensman_views.lensman_submit_api, name='lensman_submit_api'),  # 摄影师登录
84
+]
85
+
78 86
 # Wire up our API using automatic URL routing.
79 87
 # Additionally, we include login URLs for the browsable API.
80 88
 urlpatterns += [

+ 2 - 0
requirements.txt

@@ -11,12 +11,14 @@ django-logit==1.0.2
11 11
 django-multidomain==1.1.4
12 12
 django-shortuuidfield==0.1.3
13 13
 djangorestframework==3.3.1
14
+furl==0.4.95
14 15
 hiredis==0.2.0
15 16
 ipdb==0.8.1
16 17
 ipython==4.0.0
17 18
 jsonfield==1.0.3
18 19
 kkconst==1.1.2
19 20
 pep8==1.6.2
21
+pysnippets==1.0.2
20 22
 pytz==2015.7
21 23
 records==0.4.3
22 24
 redis==2.10.5

+ 2 - 0
utils/error/errno_utils.py

@@ -19,6 +19,8 @@ class LensmanStatusCode(BaseStatusCode):
19 19
     LENSMAN_NOT_FOUND = StatusCodeField(400001, u'Lensman Not Found', description=u'摄影师不存在')
20 20
     LENSMAN_PASSWORD_ERROR = StatusCodeField(400002, u'Lensman Password Error', description=u'摄影师密码错误')
21 21
 
22
+    LENSMAN_PHONE_ALREADY_EXISTS = StatusCodeField(400005, u'Lensman Phone Already Exists', description=u'手机号已经存在')
23
+
22 24
 
23 25
 class UserStatusCode(BaseStatusCode):
24 26
     """ 用户相关错误码  4001xx """

+ 33 - 0
wechat/views.py

@@ -1,10 +1,16 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 import time
4
+import urllib
4 5
 
6
+import requests
5 7
 import shortuuid
8
+from CodeConvert import CodeConvert as cc
6 9
 from django.conf import settings
10
+from django.shortcuts import redirect
11
+from furl import furl
7 12
 from json_response import auto_response
13
+from pysnippets import dictsnippets as dsnippets
8 14
 from wechatpy import WeChatClient
9 15
 
10 16
 
@@ -13,6 +19,33 @@ WECHAT = settings.WECHAT
13 19
 JSAPI = WECHAT.get('JSAPI', {})
14 20
 
15 21
 
22
+def get_openid(request):
23
+    scope = request.GET.get('scope', 'snsapi_userinfo')
24
+    redirect_url = request.GET.get('redirect_url', '')
25
+    default_url = request.GET.get('default_url', '')
26
+
27
+    if request.weixin:
28
+        authorize_url = settings.WECHAT_GET_CODE_USERINFO if scope == 'snsapi_userinfo' else settings.WECHAT_GET_CODE_BASE
29
+        get_code_url = authorize_url % (JSAPI['appID'], urllib.quote_plus(settings.WECHAT_REDIRECT_URI), urllib.quote_plus(redirect_url))
30
+        return redirect(get_code_url)
31
+
32
+    return redirect(default_url if default_url else redirect_url)
33
+
34
+
35
+def to_redirect(request):
36
+    code = request.GET.get('code', '')
37
+    state = request.GET.get('state', '')
38
+
39
+    access_info = requests.get(settings.WECHAT_GET_OAUTH2_ACCESS_TOKEN % (JSAPI['appID'], JSAPI['appsecret'], code), verify=False).json()
40
+    unionid, openid, access_token = access_info.get('unionid', ''), access_info.get('openid', ''), access_info.get('access_token', '')
41
+
42
+    res = requests.get(settings.WECHAT_GET_USERINFO % (access_token, openid), verify=False)
43
+    res.encoding = 'utf-8'
44
+    userinfo = res.json()
45
+
46
+    return redirect(furl(state).add(cc.Convert2Utf8(dsnippets.filter(userinfo, ['unionid', 'openid', 'nickname', 'headimgurl']))).url)
47
+
48
+
16 49
 @auto_response
17 50
 def wx_jsapi_signature_api(request):
18 51
     url = request.GET.get('url', '')

kodo - Gogs: Go Git Service

暫無描述

Kimi.Huang: 9b138d3560 @logit(res=True) 6 年之前
..
migrations ac895ae2cd Add new api get_userinfo_api 9 年之前
__init__.py ac895ae2cd Add new api get_userinfo_api 9 年之前
admin.py ac895ae2cd Add new api get_userinfo_api 9 年之前
models.py ac895ae2cd Add new api get_userinfo_api 9 年之前
tests.py ac895ae2cd Add new api get_userinfo_api 9 年之前
views.py 9b138d3560 @logit(res=True) 6 年之前