瀏覽代碼

自动识别和支付openid与appid不匹配问题处理

xjc 2 年之前
父節點
當前提交
ee6e48cf3e
共有 6 個文件被更改,包括 5175 次插入5108 次删除
  1. 10 0
      src/common/core_views.py
  2. 1 0
      src/common/models.py
  3. 5089 5074
      src/tools/code.csv
  4. 34 21
      src/utils/ocrmanage.py
  5. 28 4
      src/weixin/control_auth.py
  6. 13 9
      src/weixin/controls.py

+ 10 - 0
src/common/core_views.py

@@ -111,6 +111,12 @@ def api_wapper(handler, request, is_vauth, *args, **kwargs):
     req_path = request.META["PATH_INFO"]
     ip = request.META.get("HTTP_X_REAL_IP","")
     token = request.META.get("HTTP_AUTHORIZATION")
+
+    agent = request.META.get("HTTP_USER_AGENT")
+    xcxflag = False
+    if agent and ("wechatdevtools" in agent or "MiniProgram" in agent):
+        xcxflag = True
+
     if is_vauth:
         if token:
             dec_name = aescbc.decrypt(token)
@@ -120,6 +126,10 @@ def api_wapper(handler, request, is_vauth, *args, **kwargs):
 
             if not user:
                 return JsonResponse({"code":403,"data":{},"pass":0})
+            if xcxflag:
+                #if not user["openid"] or not user["openid"].startswith("test"):
+                if not user["openid"] or not user["openid"].startswith("odN-"):
+                    return JsonResponse({"code":403,"data":{},"pass":0})
             cur_match_id = ccc.get_cur_match().id
 
             setattr(request, "ip", get_ip(request))

+ 1 - 0
src/common/models.py

@@ -28,6 +28,7 @@ class UserInfo(models.Model):
     player_type = models.SmallIntegerField(u"选手类型,0/游客,1/普通选手,2/种子选手,3/开户选手",default=0)
     comment_status = models.SmallIntegerField(u"1/正常,0/拉黑",default=1)
     unionid = models.CharField(u"微信unionid", max_length=64, blank=True,null=True)
+    app_openid = models.CharField(u"微信openid", max_length=64, blank=True,null=True)
 
     ctime = models.DateTimeField(u"创建时间", auto_now_add=True)
 

File diff suppressed because it is too large
+ 5089 - 5074
src/tools/code.csv


+ 34 - 21
src/utils/ocrmanage.py

@@ -83,20 +83,11 @@ class OcrManage:
             asset = self.caculateAsset(list,'总资产')
 
 
-        if self.floatValue(asset) >= 0:
-            today = 0
-            if '万' in asset:
-                today = self.floatValue(asset)
-            else:
-                today = self.floatValue(asset)/10000.0
-
-            dic['today'] = round(today,2)
-        else:
-            dic['today'] = 0
         
-        dic['list'] = self.lookMarket(list)
+        dic['today'] = self.wangWord(asset)
+        dic['list']  = self.lookMarket(list)
 
-        print(dic)
+        # print(dic)
         return dic
     @classmethod
     def lookMarket(self,list):
@@ -115,17 +106,15 @@ class OcrManage:
                     mloc = mdic['location']
                     loc  = dic['location']
                     nstr = mdic['words']
-                    if len(nstr) == 6 and ((',' not in nstr) or ('.' not in nstr)):
+                    if len(nstr) == 6 and ((',' not in nstr) or ('.' not in nstr)) and self.isNumber(nstr):
                         continue
                     if float(mloc['left']) < (float(loc['left']) + float(loc['width'])):
                         market = mdic['words']
                         break
                 
-                if '万' in market:
-                    fund = self.floatValue(market)
-                else:
-                    fund = self.floatValue(market)/10000.0
                 
+                fund = self.wangWord(market)
+
                 if fund > 0:
                     ndic = {}
                     ndic['name'] = codeName['name']
@@ -195,10 +184,7 @@ class OcrManage:
                         # print('market:' + str(mdic))
                         break
                 
-                if '万' in market:
-                    fund = self.floatValue(market)
-                else:
-                    fund = self.floatValue(market)/10000.0
+                fund = self.wangWord(market)
                 
                 if fund > 0:
                     ndic = {}
@@ -228,6 +214,11 @@ class OcrManage:
                     if jx < ix and ix < (jx + width):
                         strAsset = ndic['words']
                         break
+                
+                if self.wangWord(strAsset) == 0:
+                    if i+1 < len(list):
+                        ndic = list[i+1]
+                        strAsset = ndic['words']
 
         return strAsset
     
@@ -525,6 +516,28 @@ class OcrManage:
 
         return float(word)
     
+    @classmethod
+    def wangWord(self,word):
+        print(word)
+
+        isWang = 0
+        if '万' in word:
+            wlist = self.seperateChinense(word)
+            if len(wlist) > 0:
+                word  = wlist[0]
+                isWang = 1
+
+        
+        if self.floatValue(word) >= 0:
+            if isWang == 1:
+                nvalue = self.floatValue(word)
+            else:
+                nvalue = self.floatValue(word)/10000.0
+            word = round(nvalue,2)
+        else:
+            word = 0
+
+        return word
 
 if __name__ == '__main__':
     print('ocr')

+ 28 - 4
src/weixin/control_auth.py

@@ -109,6 +109,11 @@ def login_user_v3(request):
     phcode = info.get('phcode')
     unionid = info.get('unionid','')
 
+    agent = request.META.get("HTTP_USER_AGENT")
+    xcxflag = False
+    if agent and ("wechatdevtools" in agent or "MiniProgram" in agent):
+        xcxflag = True
+
     #if not openid and not unionid:
     #    raise ce.TipException(u"缺少openid!")
     if not openid and not phone:
@@ -137,9 +142,15 @@ def login_user_v3(request):
     if not user:
         #新用户
         usercode = gen_code()
-        user,flag = cm.UserInfo.objects.get_or_create(
-            openid = openid,  
-        )
+        if xcxflag == True and openid:
+            user,flag = cm.UserInfo.objects.get_or_create(
+                openid = openid,  
+            )
+        else:
+            user,flag = cm.UserInfo.objects.get_or_create(
+                app_openid = openid,  
+            )
+
 
         user.avatar  = avatar
         user.nickname = nickname
@@ -157,7 +168,11 @@ def login_user_v3(request):
         user.avatar  = avatar
         user.nickname = nickname
         user.is_bind = 1
-        user.username = nickname
+        #user.username = nickname
+        if xcxflag:
+            user.openid = openid
+        else:
+            user.app_openid = openid
         user.unionid = unionid
         user.save()
 
@@ -196,6 +211,11 @@ def get_wxauth_info_v3(request):
 
     user = None
 
+    agent = request.META.get("HTTP_USER_AGENT")
+    xcxflag = False
+    if agent and ("wechatdevtools" in agent or "MiniProgram" in agent):
+        xcxflag = True
+
     #if openid:
     #    user = cm.UserInfo.objects.filter(openid=openid).values().first()
     #else:
@@ -223,6 +243,10 @@ def get_wxauth_info_v3(request):
 
     if not user:
         return {}
+    else:
+        if xcxflag and user.get("openid") != openid:
+            return {}
+
     cur_match_id = ccc.get_signup_match().id
     gt_time = datetime.timedelta(days=-365)+datetime.datetime.now()
     player = cm.Player.objects.filter(user_id=user["id"]).order_by("-id").first()

+ 13 - 9
src/weixin/controls.py

@@ -3280,7 +3280,7 @@ def get_opmode_group_rank_list(**kwargs):
         else:
             tmp_dct[key].append(item)
 
-        if len(tmp_dct[key]) > 5:
+        if len(tmp_dct[key]) > 2:
             break
 
     data = []
@@ -3290,11 +3290,12 @@ def get_opmode_group_rank_list(**kwargs):
         win_5 = qset.filter(today_income__gte=0.05).count()
         loss_5 = qset.filter(today_income__lte=0.05).count()
         item = {
-            "opmode_name":opmode_name,     
-            "opmode_id":opmode_id,     
-            "list":v,
-            "win_5":win_5,
-            "loss_5":loss_5
+            "name":opmode_name,     
+            "id":opmode_id,     
+            "players":v,
+            "win_count":win_5,
+            "loss_count":loss_5,
+            "opmodel":1,
         }
         data.append(item)
 
@@ -3322,6 +3323,8 @@ def get_opmode_group_statistic(**kwargs):
     today_fund_total = qset.aggregate(total=Sum("today_fund"))["total"]
     #初始资产
     init_fund_total = qset.aggregate(total=Sum("init_fund"))["total"]
+
+    total_income = (today_fund_total - init_fund_total)/init_fund_total
     
     #持股前10
     user_stock_top10 = list(qset_user_stock.values("stock_id","stock_name")\
@@ -3329,9 +3332,10 @@ def get_opmode_group_statistic(**kwargs):
 
     statistic = {
         "total_man":total,     
-        "today_income_avg":today_income_avg,     
-        "today_fund_total":today_fund_total,     
-        "today_init_total":init_fund_total,     
+        "today_income_avg":"{}%".format(round(today_income_avg*100,2)),     
+        "today_fund_total":round(today_fund_total,2),     
+        "today_init_total":round(init_fund_total,2),
+        "total_income":"{}%".format(round(total_income*100,2)),     
         "user_stock_top10":user_stock_top10     
     }
     return statistic