@@ -121,8 +121,17 @@ def DJANGO_FILE_UPLOAD_CALLBACK_FUNC(request, file_path=None, file_url=None): |
||
121 | 121 |
file_path = os.path.join(settings.MEDIA_ROOT, file_path) |
122 | 122 |
zbars = zbar(file_path) |
123 | 123 |
|
124 |
- for i in range(len(zbars)): |
|
125 |
- zbars[i] = zbars[i].strip() |
|
124 |
+ return { |
|
125 |
+ 'zbars': zbars, |
|
126 |
+ } |
|
127 |
+ |
|
128 |
+ zbar2 = int(request.POST.get('zbar2', 0)) |
|
129 |
+ if zbar2: |
|
130 |
+ import os |
|
131 |
+ from utils.zbar.zbar2 import zbar2 |
|
132 |
+ |
|
133 |
+ file_path = os.path.join(settings.MEDIA_ROOT, file_path) |
|
134 |
+ zbars = zbar2(file_path) |
|
126 | 135 |
|
127 | 136 |
return { |
128 | 137 |
'zbars': zbars, |
@@ -412,6 +412,9 @@ COMPONENT_CALLBACK_CONFIG = { |
||
412 | 412 |
'tousername': 'brand_id', |
413 | 413 |
} |
414 | 414 |
|
415 |
+# 测试文件 |
|
416 |
+TESTING_ZBAR = os.path.join(BASE_DIR, 'utils/zbar/zbar.jpg').replace('\\', '/') |
|
417 |
+ |
|
415 | 418 |
# 开发调试相关配置 |
416 | 419 |
if DEBUG: |
417 | 420 |
try: |
@@ -8,4 +8,5 @@ pywe-pay==1.0.12 |
||
8 | 8 |
pywe-pay-notify==1.0.4 |
9 | 9 |
pywe-response==1.0.1 |
10 | 10 |
pywe-sign==1.1.0 |
11 |
+pywe-wxa-cv==1.0.0 |
|
11 | 12 |
pywe-xml==1.0.6 |
@@ -1,5 +1,6 @@ |
||
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
+from django.conf import settings |
|
3 | 4 |
from PIL import Image, ImageEnhance |
4 | 5 |
from pyzbar import pyzbar |
5 | 6 |
|
@@ -33,8 +34,14 @@ def zbar(path): |
||
33 | 34 |
# barcodeData = barcode.data.decode("utf-8") |
34 | 35 |
# print(barcodeData) |
35 | 36 |
|
36 |
- return [bar.data.decode('utf-8') for bar in barcodes] |
|
37 |
+ return [bar.data.decode('utf-8').strip() for bar in barcodes] |
|
38 |
+ |
|
39 |
+ |
|
40 |
+def test_zbar(): |
|
41 |
+ # In[4]: test_zbar() |
|
42 |
+ # [u'189415'] |
|
43 |
+ print zbar(settings.TESTING_ZBAR) |
|
37 | 44 |
|
38 | 45 |
|
39 | 46 |
if __name__ == '__main__': |
40 |
- print zbar('zbar.jpg') |
|
47 |
+ test_zbar() |
@@ -0,0 +1,31 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+from django.conf import settings |
|
4 |
+from pywe_storage import RedisStorage |
|
5 |
+from pywe_wxa_cv import cv_qrcode |
|
6 |
+ |
|
7 |
+from utils.redis.connect import r |
|
8 |
+ |
|
9 |
+ |
|
10 |
+WECHAT = settings.WECHAT |
|
11 |
+ |
|
12 |
+ |
|
13 |
+def zbar2(path): |
|
14 |
+ wxcfg = WECHAT.get('MINIAPP', {}) |
|
15 |
+ |
|
16 |
+ appid = wxcfg.get('appID') |
|
17 |
+ secret = wxcfg.get('appsecret') |
|
18 |
+ |
|
19 |
+ # In[5]: test_zbar2() |
|
20 |
+ # {u'code_results': [{u'type_name': u'CODE_39', u'data': u'189415'}], u'img_size': {u'h': 1440, u'w': 1080}, u'errcode': 0, u'errmsg': u'ok'} |
|
21 |
+ img_infos = cv_qrcode(img_file_path=path, appid=appid, secret=secret, storage=RedisStorage(r)) |
|
22 |
+ |
|
23 |
+ code_results = img_infos.get('code_results', []) |
|
24 |
+ |
|
25 |
+ return [code.get('data', '').strip() for code in code_results] |
|
26 |
+ |
|
27 |
+ |
|
28 |
+def test_zbar2(): |
|
29 |
+ # In[5]: test_zbar() |
|
30 |
+ # [u'189415'] |
|
31 |
+ print zbar2(settings.TESTING_ZBAR) |