xjc 2 سال پیش
والد
کامیت
4125b1c4d1
4فایلهای تغییر یافته به همراه34 افزوده شده و 11 حذف شده
  1. 11 1
      src/utils/wxpay/base.py
  2. 4 4
      src/utils/wxpay/pay.py
  3. 18 5
      src/weixin/controls.py
  4. 1 1
      src/weixin/views.py

+ 11 - 1
src/utils/wxpay/base.py

@@ -17,7 +17,7 @@ class WechatPayDALBase(object):
     def __init__(self):
         self.mch_appid = "wxc37e33635b5bd6c1"
         self.mchid = "1625494503"
-        self.v3key = "1625494503"
+        self.v3key = "658fc1c41537bfde4be19bcc63c0c063"
         # serial_no可通过openssl直接获取, 例: openssl x509 -in 1900009191_20180326_cert.pem -noout -serial
         self.serial_no = "3463FC952F40D348FB6877C210B0029F980710E5"
         self.client_key = os.path.join(os.path.dirname(os.path.abspath(__file__)),"cert/apiclient_key.pem")
@@ -68,6 +68,16 @@ class WechatPayDALBase(object):
         ret = aesgcm.decrypt(nonce_bytes, data, ad_bytes)
         return ret
 
+    def decrypt_nofify_v3(self, dct):
+        key_bytes = self.v3key.encode()
+        nonce_bytes = dct['resource']['nonce'].encode()
+        ad_bytes = dct['resource']['associated_data'].encode()
+        data = base64.b64decode(dct['resource']['ciphertext'])
+
+        aesgcm = AESGCM(key_bytes)
+        ret = aesgcm.decrypt(nonce_bytes, data, ad_bytes)
+        return ret
+
     def make_headers_v3(self, url, headers=None, body='', method='GET'):
         '''
         微信支付V3版本签名header生成函数

+ 4 - 4
src/utils/wxpay/pay.py

@@ -38,10 +38,10 @@ class WechatPayDAL(WechatPayDALBase):
         '''
         url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/app'
         ndt = datetime.now()
-        out_trade_no = self.generate_partner_trade_no(ndt)
-        data = {
+        #out_trade_no = self.generate_partner_trade_no(ndt)
+        params = {
             'mchid': self.mchid,
-            'out_trade_no': out_trade_no,
+            'out_trade_no': data['out_trade_no'],
             'appid': self.mch_appid,
             'description': data['subject'],
             'notify_url': callback_url,
@@ -51,7 +51,7 @@ class WechatPayDAL(WechatPayDALBase):
             },
             'time_expire': (ndt + timedelta(minutes=5)).strftime('%Y-%m-%dT%H:%M:%S+08:00')
         }
-        jdata = json.dumps(data, separators=[',', ':'])
+        jdata = json.dumps(params, separators=[',', ':'])
         headers = {'Content-Type': 'application/json'}
         # 第一次签名, 直接请求微信后端
         headers = self.make_headers_v3(url, headers=headers, body=jdata, method='POST')

+ 18 - 5
src/weixin/controls.py

@@ -2054,7 +2054,10 @@ def do_wx_pay(request):
         if not match_group:
             match_group = cm.MatchGroup.objects.filter(match_id=match_id,charge=0).first().id
 
-    out_trade_no = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + str(int(time.time()*1000))
+    if pay_type == "wxapppay":
+        out_trade_no = "WXAPP"+datetime.datetime.now().strftime("%Y%m%d%H%M%S") + str(int(time.time()*1000))
+    else:
+        out_trade_no = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + str(int(time.time()*1000))
 
     #游客和普通选手付费报名
    #gt_time = datetime.timedelta(days=-365)+datetime.datetime.now()
@@ -2077,8 +2080,9 @@ def do_wx_pay(request):
         #支付
         if pay_type == "wxapppay":
             total_fee = str(int(float(order.total_fee)*100))
-            notify_url = "https://api.hunanwanzhu.com/api/wx/v3/signup/notify"
-            data = {"subject":u"%s报名费" % match_name,"price":total_fee}
+            notify_url = "https://test.hunanwanzhu.com/api/wx/v3/signup/notify"
+            #notify_url = "https://test.hunanwanzhu.com"
+            data = {"subject":u"%s报名费" % match_name,"price":total_fee,"out_trade_no":out_trade_no}
             wxapppay = WechatPayDAL()
             prepayinfo = wxapppay.create_order_info(data,notify_url)
             return prepayinfo
@@ -2140,7 +2144,13 @@ def do_wx_pay(request):
 
 def do_wxpay_notify(request):                                                      
     qdata = request.json                                                           
-    flag,res = wxpay.check_notify_valid(request.body)                              
+    if qdata.get("resource_type") == "encrypt-resource":
+        wxapppay = WechatPayDAL()
+        res = wxapppay.decrypt_nofify_v3(qdata)
+        res = json.loads(res)
+        flag = True
+    else:
+        flag,res = wxpay.check_notify_valid(request.body)                              
     if flag:                                                                       
         out_trade_no = res.get("out_trade_no")                                     
         transaction_id = res.get("transaction_id")                                 
@@ -3093,11 +3103,14 @@ def get_match_winlost_top5(**kwargs):
     """
     """
     data = []
-    matchs = cm.Match.objects.filter(id__gte=8).order_by("id")
+    cur_match_id = ccc.get_cur_match().id
+    matchs = cm.Match.objects.filter(id__gte=8).order_by("-id")
     for match in matchs:
         match_id = match.id
         match_name = match.name
         end_time = match.end_time
+        if cur_match_id == match_id:
+            end_time = get_today_date()
         records = cm.PlayerRecord.get_db_model(match_id).objects.filter(stock_date=end_time)
         total_income_up   = copy.copy(records)
         total_income_up   = total_income_up.order_by("-total_income")

+ 1 - 1
src/weixin/views.py

@@ -1436,7 +1436,7 @@ class TypeArticleTop5ListView(cv.AuthView):
             return cv.to_fail(e)
 
 
-class MatchWinlostTop5ListView(cv.AuthView):
+class MatchWinlostTop5ListView(cv.BaseView):
     def get(self, request):                                                        
         """#每届比赛收益top5(小程序)
         """