小程序分销

This commit is contained in:
jeremygan2021
2026-02-17 11:32:16 +08:00
parent 315f461a20
commit db401a7103
4 changed files with 29 additions and 3 deletions

View File

@@ -30,7 +30,11 @@ from django.conf import settings
import requests
import random
import threading
import logging
import string
from django.core.cache import cache
logger = logging.getLogger(__name__)
from time import sleep
# 猴子补丁:绕过微信支付响应签名验证
@@ -1463,9 +1467,15 @@ class DistributorViewSet(viewsets.GenericViewSet):
distributor = user.distributor
if distributor.qr_code_url:
return Response({'qr_code_url': distributor.qr_code_url})
# 确保有邀请码
if not distributor.invite_code:
distributor.invite_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
distributor.save()
access_token = get_access_token()
if not access_token:
logger.error("Failed to get access token for invite generation")
return Response({'error': 'Failed to get access token'}, status=500)
# 微信小程序码接口 B适用于需要的码数量极多的业务场景
@@ -1490,8 +1500,14 @@ class DistributorViewSet(viewsets.GenericViewSet):
return Response({'qr_code_url': qr_url})
else:
# 如果是 JSON 错误信息
return Response({'error': 'WeChat API error', 'detail': res.json()}, status=500)
logger.error(f"WeChat API error in invite: {res.status_code} - {res.text}")
try:
detail = res.json()
except:
detail = res.text
return Response({'error': 'WeChat API error', 'detail': detail}, status=500)
except Exception as e:
logger.error("Exception in invite view: %s", str(e), exc_info=True)
import traceback
traceback.print_exc()
return Response({'error': str(e), 'traceback': traceback.format_exc()}, status=500)