Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tamp_course_order
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
tamp_course_order
Commits
8fcd5db0
Commit
8fcd5db0
authored
Nov 25, 2020
by
pengxiong@wealthgrow.cn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token鉴权,充值订单成功业务
parent
81692534
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
427 additions
and
35 deletions
+427
-35
__main__.py
app/api/__main__.py
+1
-1
config.yaml
app/config/config.yaml
+26
-20
errors.py
app/config/errors.py
+5
-2
errorhandler.py
app/controller/errorhandler.py
+14
-2
order.py
app/controller/order.py
+2
-2
order_service.py
app/service/order_service.py
+38
-0
alipayWap.py
app/utils/alipay/alipayWap.py
+2
-6
wx_app_pay.py
app/utils/wxpay/wx_app_pay.py
+2
-2
tamp_course_order.log
logs/tamp_course_order.log
+337
-0
No files found.
app/api/__main__.py
View file @
8fcd5db0
...
@@ -9,5 +9,5 @@
...
@@ -9,5 +9,5 @@
from
app.api.app
import
app
from
app.api.app
import
app
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
'
127.0.0.1
'
,
port
=
8000
,
debug
=
True
)
app
.
run
(
'
0.0.0.0
'
,
port
=
8000
,
debug
=
True
)
app/config/config.yaml
View file @
8fcd5db0
...
@@ -15,7 +15,8 @@ dev:
...
@@ -15,7 +15,8 @@ dev:
filemode
:
a
filemode
:
a
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
token_auth_url
:
https://devtamper.tanpuyun.com/fatools/token/auth
test
:
test
:
MySQL
:
MySQL
:
tamp_user_db
:
tamp_user
tamp_user_db
:
tamp_user
...
@@ -24,16 +25,17 @@ test:
...
@@ -24,16 +25,17 @@ test:
port
:
3306
port
:
3306
user
:
root
user
:
root
password
:
'
@imeng123'
password
:
'
@imeng123'
redis
:
redis
:
host
:
localhost
host
:
localhost
port
:
6379
port
:
6379
db
:
0
db
:
0
log
:
log
:
filename
:
/logs/tamp_course_order.log
filename
:
/logs/tamp_course_order.log
filemode
:
a
filemode
:
a
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
token_auth_url
:
https://testtamper.tanpuyun.com/fatools/token/auth
prod
:
prod
:
MySQL
:
MySQL
:
tamp_user_db
:
tamp_user
tamp_user_db
:
tamp_user
...
@@ -42,12 +44,16 @@ prod:
...
@@ -42,12 +44,16 @@ prod:
port
:
3306
port
:
3306
user
:
tamp_pay
user
:
tamp_pay
password
:
'
@imeng123'
password
:
'
@imeng123'
redis
:
redis
:
host
:
localhost
host
:
localhost
port
:
6379
port
:
6379
db
:
0
db
:
0
log
:
log
:
filename
:
/logs/tamp_course_order.log
filename
:
/logs/tamp_course_order.log
filemode
:
a
filemode
:
a
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
format
:
"
%(asctime)s
%(name)s
%(levelname)s
%(message)s"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
datefmt
:
"
%Y-%m-%d
%H:%M:%S
%a"
token_auth_url
:
https://tamper.tanpuyun.com/fatools/token/auth
app/config/errors.py
View file @
8fcd5db0
...
@@ -9,8 +9,11 @@
...
@@ -9,8 +9,11 @@
class
Errors
:
class
Errors
:
""""""
""""""
USER_ALREADY_EXISTS
=
20001
TOKEN_INVALID
=
'9001'
USER_ALREADY_EXISTS
=
'9002'
MSG
=
{
MSG
=
{
USER_ALREADY_EXISTS
:
'用户已经存在'
TOKEN_INVALID
:
'TOKEN失效'
,
USER_ALREADY_EXISTS
:
'用户已经存在'
,
}
}
app/controller/errorhandler.py
View file @
8fcd5db0
...
@@ -6,7 +6,10 @@
...
@@ -6,7 +6,10 @@
# @Email : acepengxiong@163.com
# @Email : acepengxiong@163.com
# @Software : PyCharm
# @Software : PyCharm
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
import
requests
from
flask
import
jsonify
,
make_response
,
request
from
flask
import
jsonify
,
make_response
,
request
from
app.api.engine
import
config
,
env
from
app.config.errors
import
Errors
from
app.config.errors
import
Errors
...
@@ -27,7 +30,7 @@ class CustomFlaskErr(Exception):
...
@@ -27,7 +30,7 @@ class CustomFlaskErr(Exception):
rv
=
dict
(
self
.
payload
or
())
rv
=
dict
(
self
.
payload
or
())
# 增加 dict key: return code
# 增加 dict key: return code
rv
[
'
return_c
ode'
]
=
self
.
return_code
rv
[
'
statusC
ode'
]
=
self
.
return_code
# 增加 dict key: message, 具体内容由常量定义文件中通过 return_code 转化而来
# 增加 dict key: message, 具体内容由常量定义文件中通过 return_code 转化而来
rv
[
'message'
]
=
Errors
.
MSG
[
self
.
return_code
]
rv
[
'message'
]
=
Errors
.
MSG
[
self
.
return_code
]
...
@@ -47,7 +50,16 @@ def add_errorhandler(app):
...
@@ -47,7 +50,16 @@ def add_errorhandler(app):
@
app
.
before_request
@
app
.
before_request
def
before_request
():
def
before_request
():
request
.
return_success
=
{
'return_code'
:
0
,
'message'
:
'ok'
}
# token鉴权
token
=
request
.
headers
.
get
(
'tampToken'
,
''
)
# token = 'eyJhbHQiOiJIUzI1NiIsImFsZyI6IkhTMjU2IiwidHlwIjoiSldUIn0.eyJwYXlsb2FkIjoidGFtcC8xOTM3NzkzMDc5NzY5NDE1NjgiLCJpc3MiOiJjYWl4aWFvcXVhbiIsImlhdCI6MTYwNjI5MDYzMH0.WnADEiWd27A8wr2DmOyX1kcs0dWLxpoO-k1yiF0qbBk'
url
=
config
[
env
][
'token_auth_url'
]
res
=
requests
.
get
(
url
,
{
'tampToken'
:
token
})
resp
=
res
.
json
()
if
resp
[
'statusCode'
]
!=
"0000"
:
raise
CustomFlaskErr
(
Errors
.
TOKEN_INVALID
)
request
.
user_id
=
resp
[
'attributes'
]
request
.
return_success
=
{
'statusCode'
:
"0000"
,
'message'
:
'ok'
}
@
app
.
after_request
@
app
.
after_request
def
after_request
(
response
):
def
after_request
(
response
):
...
...
app/controller/order.py
View file @
8fcd5db0
...
@@ -30,7 +30,7 @@ class TopUpOrder(Resource):
...
@@ -30,7 +30,7 @@ class TopUpOrder(Resource):
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
data
=
order_service
.
TopUpOrderService
()
.
get_order
(
args
)
data
=
order_service
.
TopUpOrderService
()
.
get_order
(
args
)
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'
data
'
]
=
data
resp
[
'
attributes
'
]
=
data
return
resp
return
resp
def
post
(
self
):
def
post
(
self
):
...
@@ -64,7 +64,7 @@ class ConsumeOrder(Resource):
...
@@ -64,7 +64,7 @@ class ConsumeOrder(Resource):
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
data
=
order_service
.
CurriculumOrderService
()
.
get_order
(
args
)
data
=
order_service
.
CurriculumOrderService
()
.
get_order
(
args
)
resp
=
request
.
return_success
resp
=
request
.
return_success
resp
[
'
data
'
]
=
data
resp
[
'
attributes
'
]
=
data
return
resp
return
resp
def
post
(
self
):
def
post
(
self
):
...
...
app/service/order_service.py
View file @
8fcd5db0
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
import
time
import
time
from
app.api.engine
import
tamp_pay_session
,
tamp_user_session
from
app.api.engine
import
tamp_pay_session
,
tamp_user_session
from
app.model.account_balance
import
AccountBalance
from
app.model.account_topup_order
import
AccountTopupOrder
from
app.model.account_topup_order
import
AccountTopupOrder
from
app.model.curriculum_order
import
CurriculumOrder
from
app.model.curriculum_order
import
CurriculumOrder
from
app.model.tamp_user_models
import
CurriculumPrice
,
CurriculumColumn
,
CurriculumRes
from
app.model.tamp_user_models
import
CurriculumPrice
,
CurriculumColumn
,
CurriculumRes
...
@@ -67,4 +68,41 @@ class CurriculumOrderService:
...
@@ -67,4 +68,41 @@ class CurriculumOrderService:
return
True
return
True
def
topUpSuccessAction
(
order_no
):
"""."""
topup_order
=
tamp_pay_session
.
query
(
AccountTopupOrder
)
.
filter
(
AccountTopupOrder
.
order_no
==
order_no
)
.
first
()
# 幂等校验
if
topup_order
.
order_status
==
1
:
return
False
tamp_pay_session
.
query
(
AccountTopupOrder
)
.
filter
(
AccountTopupOrder
.
order_no
==
order_no
)
.
update
({
'order_status'
:
1
})
# 账户充值
account_topup_order
=
tamp_pay_session
.
query
(
AccountTopupOrder
)
.
filter
(
AccountTopupOrder
.
order_no
==
order_no
)
.
first
()
if
account_topup_order
.
pay_method
==
4
:
# 苹果支付
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
all
():
tamp_pay_session
.
add
(
AccountBalance
(
apple_balance
=
account_topup_order
.
amount
))
else
:
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
update
({
'apple_balance'
:
AccountBalance
.
apple_balance
+
account_topup_order
.
amount
})
else
:
# 支付宝,微信支付
if
not
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
all
():
tamp_pay_session
.
add
(
AccountBalance
(
android_balance
=
account_topup_order
.
amount
))
else
:
tamp_pay_session
.
query
(
AccountBalance
)
.
filter
(
AccountBalance
.
user_id
==
account_topup_order
.
user_id
)
.
update
({
'apple_balance'
:
AccountBalance
.
android_balance
+
account_topup_order
.
amount
})
tamp_pay_session
.
commit
()
def
consumeSucessAction
(
order_no
):
"""."""
curriculum_order
=
tamp_pay_session
.
query
(
CurriculumOrder
.
order_no
==
order_no
)
.
all
()
# 幂等校验
if
curriculum_order
.
order_status
==
1
:
return
False
# tamp_pay_session.query(CurriculumOrder).filter(CurriculumOrder.order_no == )
\ No newline at end of file
app/utils/alipay/alipayWap.py
View file @
8fcd5db0
...
@@ -29,7 +29,7 @@ alipay_public_key_string = '''-----BEGIN PUBLIC KEY-----
...
@@ -29,7 +29,7 @@ alipay_public_key_string = '''-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhTT+Cn3Y+BYysAqXsjAqjJ14aUzvUHKz0LnaAifTE10IRyzzcFn+8SXIhzHoJ/OQrj7DPoDV18iSX7PcHPDdRCFyOBP1RQkxFLmnpqFY6BRoEm6kaWea0rfg44EXgZSCO0e7gwjez8W4zO7S9w+HOECbB61ZfmsM+oTT41kUyXmcpUgvkSiayxyeNcnzSiS06GuoMbSpaVSjAoTAiFZdyaB51+wDXf3JvZARnlvnD2Jk5sFDzZbeVIfygInFo/ICIQRr96Jfwcey9ZO3PfvxZlDqa0cbCmZi7PyMIlwVf/bHF+rwiXboJm+rauu+Py4ch5BrakWVF/kty+jitLxD6QIDAQAB
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhTT+Cn3Y+BYysAqXsjAqjJ14aUzvUHKz0LnaAifTE10IRyzzcFn+8SXIhzHoJ/OQrj7DPoDV18iSX7PcHPDdRCFyOBP1RQkxFLmnpqFY6BRoEm6kaWea0rfg44EXgZSCO0e7gwjez8W4zO7S9w+HOECbB61ZfmsM+oTT41kUyXmcpUgvkSiayxyeNcnzSiS06GuoMbSpaVSjAoTAiFZdyaB51+wDXf3JvZARnlvnD2Jk5sFDzZbeVIfygInFo/ICIQ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4L0UNGi7i8dGFnp1BtOQ==
hwtSuAgS7rSrMeMS9omsZro9L1eHDjA8Ja4L0UNGi7i8dGFnp1BtOQ==
-----END
RSA
PRIVATE KEY-----'''
-----END PRIVATE KEY-----'''
APP_ID
=
'2021002112638152'
APP_ID
=
'2021002112638152'
URL_PREFIX
=
'https://tampe.tanpuyun.com'
URL_PREFIX
=
'https://tampe.tanpuyun.com'
...
@@ -86,11 +86,7 @@ def prePay(subject, out_trade_no, total_amount, notify_path='/webservice/notify'
...
@@ -86,11 +86,7 @@ def prePay(subject, out_trade_no, total_amount, notify_path='/webservice/notify'
)
)
if
not
result
:
if
not
result
:
return
False
return
False
result
=
unquote
(
result
)
# res = dict(parse_qs(result))
# res = {k: v[0] for k, v in res.items()}
print
(
result
)
print
(
result
)
# pay_url = 'https://openapi.alipay.com/gateway.do?' + result
return
result
return
result
def
alipay_transfer
():
def
alipay_transfer
():
...
...
app/utils/wxpay/wx_app_pay.py
View file @
8fcd5db0
...
@@ -116,8 +116,8 @@ class WXPay(object):
...
@@ -116,8 +116,8 @@ class WXPay(object):
def
getPaySign
(
self
):
def
getPaySign
(
self
):
"""."""
"""."""
sign_string
=
'appId={0}&nonceStr={1}&package=prepay_id={2}&signType={3}&timeStamp={4}&key={5}'
.
format
(
sign_string
=
'appId={0}&nonceStr={1}&package=
{6}
prepay_id={2}&signType={3}&timeStamp={4}&key={5}'
.
format
(
self
.
appid
,
self
.
nonce_str
,
self
.
prepay_id
,
self
.
sign_type
,
self
.
timeStamp
,
self
.
key
)
self
.
appid
,
self
.
nonce_str
,
self
.
prepay_id
,
self
.
sign_type
,
self
.
timeStamp
,
self
.
key
,
'Sign=WXPay'
)
self
.
paySign
=
hashlib
.
md5
(
sign_string
.
encode
(
"utf-8"
))
.
hexdigest
()
.
upper
()
self
.
paySign
=
hashlib
.
md5
(
sign_string
.
encode
(
"utf-8"
))
.
hexdigest
()
.
upper
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
logs/tamp_course_order.log
View file @
8fcd5db0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment