Browse Source

修改微信回调格式

lang 3 years ago
parent
commit
787bd44342
2 changed files with 12 additions and 6 deletions
  1. 11 5
      Controller/CloudStorage.py
  2. 1 1
      Object/WechatPayObject.py

+ 11 - 5
Controller/CloudStorage.py

@@ -960,14 +960,11 @@ class CloudStorageView(View):
             trade_status = data['result_code']  # 业务结果  SUCCESS/FAIL
             out_trade_no = data['out_trade_no']  # 商户订单号
             order_qs = Order_Model.objects.filter(orderID=out_trade_no, status=0)
-            logger.info(data)
             if trade_status == "SUCCESS":
                 check_sign = pay.get_notifypay(data)
                 if not check_sign:
                     return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '签名失败'}))
-                logger.info('签名成功')
                 orderID = out_trade_no
-
                 #redis加锁,防止订单重复
                 redisObj = RedisObject()
                 isLock = redisObj.CONN.setnx(orderID + 'do_notify', 1)
@@ -979,7 +976,14 @@ class CloudStorageView(View):
                 order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
                                              "userID__userID", "userID__username","status")
 
+                if order_list[0]['status'] == 1:
+                    return HttpResponse("<xml>\
+                                          <return_code><![CDATA[SUCCESS]]></return_code>\
+                                          <return_msg><![CDATA[OK]]></return_msg>\
+                                        </xml>")
+
                 logger.info(order_list[0]['UID'])
+                logger.info(orderID)
 
                 userid = order_list[0]['userID__userID']
                 username = order_list[0]['userID__username']
@@ -1053,9 +1057,11 @@ class CloudStorageView(View):
                                          'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on ' + time.strftime(
                                              "%b %dth,%Y", time.localtime())]
                     self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
-                    logger.info(pay.xml_to_dict({'return_code': 'SUCCESS', 'return_msg': 'OK'}))
                     redisObj.del_data(key=orderID + 'do_notify')
-                    return HttpResponse(pay.xml_to_dict({'return_code': 'SUCCESS', 'return_msg': 'OK'}))
+                    return HttpResponse("<xml>\
+                      <return_code><![CDATA[SUCCESS]]></return_code>\
+                      <return_msg><![CDATA[OK]]></return_msg>\
+                    </xml>")
             else:
                 order_qs.update(status=10, promotion_rule_id=promotion_rule_id)
             return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '参数格式校验错误'}))

+ 1 - 1
Object/WechatPayObject.py

@@ -199,7 +199,7 @@ class WechatPayObject:
         for k, v in params.items():
             # v = v.encode('utf8')
             # k = k.encode('utf8')
-            xml += '<' + k + '><![CDATA[' + v + ']]></' + k + '>'
+            xml += '<' + k + '>' + v + '</' + k + '>'
         xml += "</xml>"
         return xml