排行榜按收益/流水排序;小程序配置与页面资源入库可后台管理
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
# dingdan/tongzhi_tasks.py
|
||||
# dingdan/tongzhi_tasks.py
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
|
||||
from a_long_dianjing.celery import app
|
||||
from utils.weixin_broadcast import WeixinBroadcastSender
|
||||
@@ -24,7 +25,7 @@ def dingdan_guangbo(self, order_info):
|
||||
"""
|
||||
Celery:并发向所有关注服务号的用户推送订单模板消息
|
||||
"""
|
||||
if not getattr(settings, 'WEIXIN_BROADCAST_ENABLED', True):
|
||||
if not wx_cfg.WEIXIN_BROADCAST_ENABLED:
|
||||
return {'success': True, 'msg': '广播已关闭'}
|
||||
|
||||
order_id = order_info.get('dingdan_id')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
import os
|
||||
from django.db.models import F
|
||||
from django.shortcuts import render
|
||||
from rest_framework.permissions import AllowAny # 新增这行
|
||||
@@ -16,6 +16,7 @@ import uuid
|
||||
from decimal import Decimal
|
||||
from django.db import transaction
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions, status
|
||||
@@ -256,10 +257,10 @@ class CreateOrderView(APIView):
|
||||
"""
|
||||
try:
|
||||
# 微信支付配置
|
||||
APPID = getattr(settings, 'WEIXIN_APPID', '')
|
||||
MCHID = getattr(settings, 'WEIXIN_MCHID', '')
|
||||
KEY = getattr(settings, 'WEIXIN_SHANGHUMIYAO', '')
|
||||
NOTIFY_URL = getattr(settings, 'WEIXIN_NOTIFY_URL', '')
|
||||
APPID = wx_cfg.WEIXIN_APPID
|
||||
MCHID = wx_cfg.WEIXIN_MCHID
|
||||
KEY = wx_cfg.WEIXIN_SHANGHUMIYAO
|
||||
NOTIFY_URL = wx_cfg.WEIXIN_NOTIFY_URL
|
||||
|
||||
if not all([APPID, MCHID, KEY, NOTIFY_URL]):
|
||||
raise Exception('微信支付配置不完整')
|
||||
@@ -428,6 +429,7 @@ from decimal import Decimal
|
||||
from django.db import transaction, models
|
||||
from django.core.cache import cache
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions, status
|
||||
@@ -505,7 +507,7 @@ class WechatPayNotifyView(APIView):
|
||||
# 按key排序
|
||||
sorted_keys = sorted(data.keys())
|
||||
stringA = '&'.join([f"{k}={data[k]}" for k in sorted_keys])
|
||||
stringSignTemp = f"{stringA}&key={settings.WEIXIN_SHANGHUMIYAO}"
|
||||
stringSignTemp = f"{stringA}&key={wx_cfg.WEIXIN_SHANGHUMIYAO}"
|
||||
calc_sign = hashlib.md5(stringSignTemp.encode('utf-8')).hexdigest().upper()
|
||||
logger.debug(f"计算签名: {calc_sign}, 微信签名: {sign}")
|
||||
return calc_sign == sign
|
||||
@@ -828,9 +830,9 @@ class PaymentVerifyView(APIView):
|
||||
调用微信支付订单查询接口,返回 (trade_state, transaction_id)
|
||||
若查询失败,抛出异常
|
||||
"""
|
||||
appid = settings.WEIXIN_APPID
|
||||
mch_id = settings.WEIXIN_MCHID
|
||||
key = settings.WEIXIN_SHANGHUMIYAO
|
||||
appid = wx_cfg.WEIXIN_APPID
|
||||
mch_id = wx_cfg.WEIXIN_MCHID
|
||||
key = wx_cfg.WEIXIN_SHANGHUMIYAO
|
||||
nonce_str = self._generate_nonce_str()
|
||||
|
||||
params = {
|
||||
@@ -917,6 +919,7 @@ from decimal import Decimal
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from django.db import transaction
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
@@ -1089,8 +1092,8 @@ class VirtualCreateOrderView(APIView):
|
||||
"""
|
||||
url = 'https://api.weixin.qq.com/sns/jscode2session'
|
||||
params = {
|
||||
'appid': settings.WEIXIN_APPID,
|
||||
'secret': settings.WEIXIN_SECRET,
|
||||
'appid': wx_cfg.WEIXIN_APPID,
|
||||
'secret': wx_cfg.WEIXIN_SECRET,
|
||||
'js_code': code,
|
||||
'grant_type': 'authorization_code'
|
||||
}
|
||||
@@ -1378,7 +1381,7 @@ class VirtualPayNotifyView(APIView):
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
print(f"[获取AccessToken-步骤1] 开始获取 access_token")
|
||||
print(f"[获取AccessToken-步骤1] AppID: {settings.WEIXIN_APPID}")
|
||||
print(f"[获取AccessToken-步骤1] AppID: {wx_cfg.WEIXIN_APPID}")
|
||||
print(f"{'='*60}")
|
||||
|
||||
cache_key = "virtual_payment_access_token"
|
||||
@@ -1398,8 +1401,8 @@ class VirtualPayNotifyView(APIView):
|
||||
"https://api.weixin.qq.com/cgi-bin/token",
|
||||
params={
|
||||
"grant_type": "client_credential",
|
||||
"appid": settings.WEIXIN_APPID,
|
||||
"secret": settings.WEIXIN_SECRET,
|
||||
"appid": wx_cfg.WEIXIN_APPID,
|
||||
"secret": wx_cfg.WEIXIN_SECRET,
|
||||
},
|
||||
timeout=10,
|
||||
)
|
||||
@@ -1816,8 +1819,8 @@ class VirtualPaymentVerifyView(APIView):
|
||||
"https://api.weixin.qq.com/cgi-bin/token",
|
||||
params={
|
||||
"grant_type": "client_credential",
|
||||
"appid": settings.WEIXIN_APPID,
|
||||
"secret": settings.WEIXIN_SECRET,
|
||||
"appid": wx_cfg.WEIXIN_APPID,
|
||||
"secret": wx_cfg.WEIXIN_SECRET,
|
||||
},
|
||||
timeout=10,
|
||||
)
|
||||
@@ -3584,6 +3587,7 @@ class ShangjiaTuikuanShenqingView(APIView):
|
||||
import threading
|
||||
import requests
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
|
||||
def send_refund_notify():
|
||||
url = f"{settings.PARTNER_BASE_URL}{settings.PARTNER_REFUND_NOTIFY_URL}"
|
||||
@@ -4103,6 +4107,7 @@ from rest_framework.permissions import IsAuthenticated
|
||||
from django.utils import timezone
|
||||
from django.db.models import F
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
@@ -5065,6 +5070,7 @@ from tencentcloud.common import credential
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.sts.v20180813 import sts_client, models
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
@@ -5420,6 +5426,7 @@ from tencentcloud.common import credential
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
from tencentcloud.sts.v20180813 import sts_client, models
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
@@ -6923,6 +6930,7 @@ import xml.etree.ElementTree as ET
|
||||
from decimal import Decimal
|
||||
from django.db import transaction
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
@@ -7152,13 +7160,13 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
|
||||
# 构造请求参数
|
||||
refund_data = {
|
||||
'appid': settings.WEIXIN_APPID,
|
||||
'mch_id': settings.WEIXIN_MCHID,
|
||||
'appid': wx_cfg.WEIXIN_APPID,
|
||||
'mch_id': wx_cfg.WEIXIN_MCHID,
|
||||
'nonce_str': hashlib.md5(str(time.time()).encode()).hexdigest(),
|
||||
'out_refund_no': refund_id,
|
||||
'total_fee': total_fee_in_fen,
|
||||
'refund_fee': total_fee_in_fen,
|
||||
'op_user_id': settings.WEIXIN_MCHID,
|
||||
'op_user_id': wx_cfg.WEIXIN_MCHID,
|
||||
'refund_account': 'REFUND_SOURCE_UNSETTLED_FUNDS'
|
||||
}
|
||||
# 优先使用 transaction_id,否则用 out_trade_no
|
||||
@@ -7170,7 +7178,7 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
# 生成签名
|
||||
sorted_params = sorted(refund_data.items())
|
||||
sign_string = '&'.join([f"{k}={v}" for k, v in sorted_params if v])
|
||||
sign_string += f"&key={settings.WEIXIN_SHANGHUMIYAO}"
|
||||
sign_string += f"&key={wx_cfg.WEIXIN_SHANGHUMIYAO}"
|
||||
sign = hashlib.md5(sign_string.encode()).hexdigest().upper()
|
||||
refund_data['sign'] = sign
|
||||
|
||||
@@ -7180,7 +7188,7 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
url,
|
||||
data=xml_data.encode('utf-8'),
|
||||
headers={'Content-Type': 'application/xml'},
|
||||
cert=(settings.WEIXIN_CERT_PATH, settings.WEIXIN_KEY_PATH),
|
||||
cert=(wx_cfg.WEIXIN_CERT_PATH, wx_cfg.WEIXIN_KEY_PATH),
|
||||
timeout=30
|
||||
)
|
||||
|
||||
@@ -7229,6 +7237,7 @@ from rest_framework.parsers import JSONParser
|
||||
from rest_framework import status
|
||||
from django.db import transaction
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
import logging
|
||||
import time
|
||||
import random
|
||||
@@ -7251,6 +7260,7 @@ from rest_framework.parsers import JSONParser
|
||||
from rest_framework import status
|
||||
from django.db import transaction
|
||||
from django.conf import settings
|
||||
from utils.xcx_sys_config import wx_cfg
|
||||
import logging
|
||||
import time
|
||||
import random
|
||||
@@ -7530,21 +7540,21 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
|
||||
# 准备微信退款参数
|
||||
refund_data = {
|
||||
'appid': settings.WEIXIN_APPID,
|
||||
'mch_id': settings.WEIXIN_MCHID,
|
||||
'appid': wx_cfg.WEIXIN_APPID,
|
||||
'mch_id': wx_cfg.WEIXIN_MCHID,
|
||||
'nonce_str': hashlib.md5(str(time.time()).encode()).hexdigest(),
|
||||
'out_trade_no': dingdan_id, # 商户订单号(我们的订单ID)
|
||||
'out_refund_no': refund_id, # 商户退款单号
|
||||
'total_fee': total_fee_in_fen, # 订单总金额(分)
|
||||
'refund_fee': total_fee_in_fen, # 退款金额(分),全额退款
|
||||
'op_user_id': settings.WEIXIN_MCHID, # 操作员ID,默认为商户号
|
||||
'op_user_id': wx_cfg.WEIXIN_MCHID, # 操作员ID,默认为商户号
|
||||
'refund_account': 'REFUND_SOURCE_UNSETTLED_FUNDS' # 退款资金来源
|
||||
}
|
||||
|
||||
# 生成签名
|
||||
sorted_params = sorted(refund_data.items())
|
||||
sign_string = '&'.join([f"{key}={value}" for key, value in sorted_params if value])
|
||||
sign_string += f"&key={settings.WEIXIN_SHANGHUMIYAO}"
|
||||
sign_string += f"&key={wx_cfg.WEIXIN_SHANGHUMIYAO}"
|
||||
sign = hashlib.md5(sign_string.encode()).hexdigest().upper()
|
||||
refund_data['sign'] = sign
|
||||
|
||||
@@ -7563,7 +7573,7 @@ class AdTongYiTuiKuanPingTai(APIView):
|
||||
weixin_refund_url,
|
||||
data=xml_data.encode('utf-8'),
|
||||
headers=headers,
|
||||
cert=(settings.WEIXIN_CERT_PATH, settings.WEIXIN_KEY_PATH),
|
||||
cert=(wx_cfg.WEIXIN_CERT_PATH, wx_cfg.WEIXIN_KEY_PATH),
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user