@@ -149,6 +149,35 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
|
||
| 149 | 149 |
|
| 150 | 150 |
MEDIA_URL = '/media/' |
| 151 | 151 |
|
| 152 |
+# logger setting |
|
| 153 |
+LOGGING = {
|
|
| 154 |
+ 'version': 1, |
|
| 155 |
+ 'disable_existing_loggers': False, |
|
| 156 |
+ 'formatters': {
|
|
| 157 |
+ 'verbose': {
|
|
| 158 |
+ 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' |
|
| 159 |
+ }, |
|
| 160 |
+ 'simple': {
|
|
| 161 |
+ 'format': '%(levelname)s %(message)s' |
|
| 162 |
+ }, |
|
| 163 |
+ }, |
|
| 164 |
+ 'handlers': {
|
|
| 165 |
+ 'logit': {
|
|
| 166 |
+ 'level': 'DEBUG', |
|
| 167 |
+ 'class': 'logging.FileHandler', |
|
| 168 |
+ 'filename': '/tmp/logit.log', |
|
| 169 |
+ 'formatter': 'verbose' |
|
| 170 |
+ }, |
|
| 171 |
+ }, |
|
| 172 |
+ 'loggers': {
|
|
| 173 |
+ 'logit': {
|
|
| 174 |
+ 'handlers': ['logit'], |
|
| 175 |
+ 'level': 'DEBUG', |
|
| 176 |
+ 'propagate': True, |
|
| 177 |
+ }, |
|
| 178 |
+ }, |
|
| 179 |
+} |
|
| 180 |
+ |
|
| 152 | 181 |
# REST_FRAMEWORK 设置 |
| 153 | 182 |
# See http://www.django-rest-framework.org/#example |
| 154 | 183 |
REST_FRAMEWORK = {
|
@@ -180,16 +209,18 @@ REDIS_EXPIRED_YEAR = 31622400 # 366 * 24 * 60 * 60 |
||
| 180 | 209 |
|
| 181 | 210 |
# 微信设置 |
| 182 | 211 |
WECHAT = {
|
| 183 |
- 'token': '5201314', |
|
| 184 |
- 'appID': '', |
|
| 185 |
- 'appsecret': '', |
|
| 186 |
- 'mchID': '', |
|
| 187 |
- 'apiKey': '', |
|
| 212 |
+ 'JSAPI': {
|
|
| 213 |
+ 'token': '5201314', |
|
| 214 |
+ 'appID': '', |
|
| 215 |
+ 'appsecret': '', |
|
| 216 |
+ 'mchID': '', |
|
| 217 |
+ 'apiKey': '', |
|
| 218 |
+ }, |
|
| 188 | 219 |
} |
| 189 | 220 |
|
| 190 |
-WECHAT_GET_CODE = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect' |
|
| 221 |
+WECHAT_GET_CODE_BASE = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect' |
|
| 191 | 222 |
WECHAT_GET_CODE_USERINFO = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=%s#wechat_redirect' |
| 192 |
-WECHAT_GET_ACCESS_TOKEN = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code' |
|
| 223 |
+WECHAT_GET_OAUTH2_ACCESS_TOKEN = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code' |
|
| 193 | 224 |
|
| 194 | 225 |
WECHAT_GET_USERINFO = 'https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s' |
| 195 | 226 |
|
@@ -10,16 +10,18 @@ from pay.models import OrderInfo |
||
| 10 | 10 |
from utils.error.errno_utils import OrderStatusCode |
| 11 | 11 |
from utils.error.response_utils import response |
| 12 | 12 |
|
| 13 |
+from logit import logit |
|
| 14 |
+ |
|
| 13 | 15 |
from TimeConvert import TimeConvert as tc |
| 14 | 16 |
from wechatpy import WeChatPay, WeChatPayException |
| 15 | 17 |
|
| 16 | 18 |
import xmltodict |
| 17 | 19 |
|
| 18 |
-WECHAT = settings.WECHAT |
|
| 19 | 20 |
|
| 20 |
-wxpay = WeChatPay(WECHAT['appID'], WECHAT['apiKey'], WECHAT['mchID']) |
|
| 21 |
+WECHAT = settings.WECHAT |
|
| 21 | 22 |
|
| 22 | 23 |
|
| 24 |
+@logit |
|
| 23 | 25 |
@transaction.atomic |
| 24 | 26 |
def wx_order_create_api(request): |
| 25 | 27 |
""" |
@@ -37,6 +39,11 @@ def wx_order_create_api(request): |
||
| 37 | 39 |
# JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付,统一下单接口trade_type的传参可参考这里 |
| 38 | 40 |
trade_type = request.POST.get('trade_type', '')
|
| 39 | 41 |
|
| 42 |
+ # 根据 trade_type 获取 wechat 配置 |
|
| 43 |
+ wechat = WECHAT.get(trade_type, {})
|
|
| 44 |
+ # WeChatPay 初始化 |
|
| 45 |
+ wxpay = WeChatPay(wechat.get('appID'), wechat.get('apiKey'), wechat.get('mchID'))
|
|
| 46 |
+ |
|
| 40 | 47 |
# 生成订单 |
| 41 | 48 |
order = OrderInfo.objects.create(from_uid=from_uid, to_lid=to_lid, to_uid=to_uid, total_fee=total_fee) |
| 42 | 49 |
|
@@ -74,6 +81,7 @@ def order_paid_success(order): |
||
| 74 | 81 |
order.save() |
| 75 | 82 |
|
| 76 | 83 |
|
| 84 |
+@logit |
|
| 77 | 85 |
@transaction.atomic |
| 78 | 86 |
def wx_notify_url_api(request): |
| 79 | 87 |
""" |
@@ -4,6 +4,7 @@ MySQL-python==1.2.5 |
||
| 4 | 4 |
TimeConvert==1.1.6 |
| 5 | 5 |
cryptography==1.2.1 |
| 6 | 6 |
django-curtail-uuid==1.0.0 |
| 7 |
+django-logit==1.0.0 |
|
| 7 | 8 |
django-multidomain==1.1.4 |
| 8 | 9 |
django-shortuuidfield==0.1.3 |
| 9 | 10 |
djangorestframework==3.3.1 |