xjc 2 rokov pred
rodič
commit
1b8c7a6a15

+ 1 - 1
src/manage/controls.py

@@ -335,7 +335,7 @@ def get_search_list(cls,**kwargs):
             data = []
     elif model_name == "Stock":
         if kwargs.get("name"):
-            qset = qset.filter(name__icontains=kwargs.get("name"))
+            qset = qset.filter(Q(name__icontains=kwargs.get("name"))|Q(code__icontains=kwargs.get("name")))
             data = list(qset.values("id","name","code"))
             for item in data:
                 item["label"] = "%s(%s)" % (item["name"],item["code"])

+ 34 - 0
src/utils/baiduai.py

@@ -0,0 +1,34 @@
+#-*-coding:utf-8 -*-
+from aip import AipContentCensor
+
+APP_ID = "33751511"
+API_KEY = "gd8nik5KMNIbh76KGqYbFOCc"
+SECRET_KEY = "1m6HfzQVURFcu9ghmFHPje587slp5XG6"
+
+def get_file_content(filePath):
+    with open(filePath, 'rb') as fp:
+        return fp.read()
+
+def baidu_ai_detect_image(imgpath):
+    """
+    """
+    client = AipContentCensor(APP_ID, API_KEY, SECRET_KEY)
+    if "http://" or "https://" in imgpath:
+        result = client.imageCensorUserDefined(imgpath)
+    else:
+        result = client.imageCensorUserDefined(get_file_content(imgpath))
+
+    return result
+
+def baidu_ai_detect_txt(content):
+    """
+    """
+    result = textCensorUserDefined(content)
+    return result
+
+
+
+if __name__ == "__main__":
+    imgpath = "/tmp/test.png"
+    baidu_ai_detect_image(imgpath)
+

+ 2 - 0
src/weixin/urls_backstage.py

@@ -95,5 +95,7 @@ urlpatterns = [
     url(r'^v3/baike/random$', views.BaikeRandomListView.as_view()),
     url(r'^v3/type/article/top5$', views.TypeArticleTop5ListView.as_view()),
     url(r'^v3/match/winlost/top5$', views.MatchWinlostTop5ListView.as_view()),
+    url(r'^v3/ai/detect/image$', views.AiDetectImageView.as_view()),
+    url(r'^v3/ai/detect/txt$', views.AiDetectTxtView.as_view()),
 ]
 

+ 32 - 0
src/weixin/views.py

@@ -16,6 +16,7 @@ import weixin.control_auth as ca
 import weixin.controls as ctl
 import weixin.wzhifuSDK as wzf
 from utils.upload_to_oss import hnoss
+from utils.baiduai import baidu_ai_detect_image,baidu_ai_detect_txt
 
 
 class OpenidView(cv.BaseView):
@@ -1446,3 +1447,34 @@ class MatchWinlostTop5ListView(cv.AuthView):
         except Exception as e:
             cv.tracefail()
             return cv.to_fail(e)
+
+
+class AiDetectImageView(cv.BaseView):
+    def post(self, request):
+        """
+        #ai图片检测(小程序)
+        @imgurl:"",图片地址
+        """
+        qdata = request.json
+        try:
+            imgurl = qdata.get("imgurl") 
+            rst = baidu_ai_detect_image(imgurl)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+class AiDetectTxtView(cv.BaseView):
+    def post(self, request):
+        """
+        #ai文本检测(小程序)
+        @content:"",检测文本
+        """
+        qdata = request.json
+        try:
+            content = qdata.get("content") 
+            rst = baidu_ai_detect_image(content)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)