:art: Compatible with code_ticket which starts with 'http(s)://'

huangqimin лет %!s(int64=5): %!d(string=назад)
Родитель
Сommit
c5cdc2da5e
1 измененных файлов с 12 добавлено и 10 удалено
  1. 12 10
      api/encrypt_views.py

+ 12 - 10
api/encrypt_views.py

@@ -3,6 +3,7 @@
3 3
 from __future__ import division
4 4
 
5 5
 import random
6
+import re
6 7
 
7 8
 from django.conf import settings
8 9
 from django.db import transaction
@@ -204,18 +205,20 @@ def decrypt2(request):
204 205
     code = request.POST.get('code', '')
205 206
     user_id = request.POST.get('user_id', '')
206 207
 
207
-    try:
208
-        user = UserInfo.objects.get(user_id=user_id)
209
-    except UserInfo.DoesNotExist:
210
-        return response(UserStatusCode.USER_NOT_FOUND)
208
+    if code_ticket and user_id:
209
+        code_ticket = re.sub(r'http://|https://', '', code_ticket)
210
+        try:
211
+            user = UserInfo.objects.get(user_id=user_id)
212
+        except UserInfo.DoesNotExist:
213
+            return response(UserStatusCode.USER_NOT_FOUND)
211 214
 
212
-    wxcfg = WECHAT.get('JSAPI', {})
215
+        wxcfg = WECHAT.get('JSAPI', {})
213 216
 
214
-    appid = wxcfg.get('appID')
215
-    secret = wxcfg.get('appsecret')
217
+        appid = wxcfg.get('appID')
218
+        secret = wxcfg.get('appsecret')
216 219
 
217
-    if code_ticket:
218
-        code_info = tickettocode(code_ticket=code_ticket, openid=user.openid_miniapp, appid=appid, secret=secret, token=None, storage=RedisStorage(r))
220
+        code_info = tickettocode(code_ticket=code_ticket, openid=user.openid_miniapp, appid=appid, secret=secret,
221
+                                 token=None, storage=RedisStorage(r))
219 222
 
220 223
         code = code_info.get('code', '')
221 224
 
@@ -228,7 +231,6 @@ def decrypt2(request):
228 231
             mieli = MchInfoEncryptLogInfo.objects.get(code_url=code)
229 232
         except MchInfoEncryptLogInfo.DoesNotExist:
230 233
             return response()
231
-    
232 234
 
233 235
     plaintext = mieli.plaintext
234 236