Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.core
Commits
3bd5249c
Commit
3bd5249c
authored
Sep 24, 2019
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_subscription_request: Automaically jump to the final page after user scan the QRCode
parent
487cd5dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
18 deletions
+42
-18
master/bt5/slapos_subscription_request/ExtensionTemplateItem/portal_components/extension.erp5.WechatUtils.py
...plateItem/portal_components/extension.erp5.WechatUtils.py
+40
-8
master/bt5/slapos_subscription_request/ExtensionTemplateItem/portal_components/extension.erp5.WechatUtils.xml
...lateItem/portal_components/extension.erp5.WechatUtils.xml
+2
-10
No files found.
master/bt5/slapos_subscription_request/ExtensionTemplateItem/portal_components/extension.erp5.WechatUtils.py
View file @
3bd5249c
import
sys
import
random
,
string
,
hashlib
,
urllib2
try
:
import
xml.etree.cElementTree
as
ET
except
ImportError
:
import
xml.etree.ElementTree
as
ET
reload
(
sys
)
sys
.
setdefaultencoding
(
'utf-8'
)
class
WechatException
(
Exception
):
def
__init__
(
self
,
msg
):
super
(
WechatException
,
self
).
__init__
(
msg
)
# RapidSpace Wechat acocunt configuration
...
...
@@ -17,6 +17,7 @@ API_KEY = "" # Wechat merchant platform(pay.weixin.qq.com) -->账户设置 -->A
CREATE_IP
=
""
# The IP address which request the order to Wechat, aka: instance IP
UFDODER_URL
=
"https://api.mch.weixin.qq.com/pay/unifiedorder"
# Wechat unified order API
NOTIFY_URL
=
"your IP: port/Method"
# Wechat payment callback method
QUERY_URL
=
"https://api.mch.weixin.qq.com/pay/orderquery"
def
generateRandomStr
(
random_length
=
24
):
...
...
@@ -161,20 +162,51 @@ def receiveWechatPaymentNotify(self, request, *args, **kwargs):
recalcualted_sign
=
calculateSign
(
params
,
API_KEY
)
if
recalcualted_sign
==
sign
:
if
params
.
get
(
"result_code"
,
None
)
==
"SUCCESS"
:
# payment is ok
pass
# order number
# out_trade_no = params.get("out_trade_no")
# Wechat payment order ID
# This is what we should use when we search the order in the wechat
# transaction_id = params.get("out_trade_no")
# Save the wechat payment order ID in somewhere.
# We recevied the payment...
# Process something
# XXX: display the page the payment received.
# container.REQUEST.RESPONSE.redirect("%s/#wechat_payment_confirmed")
# We must tell Wechat we received the response. Otherwise wechat will keep send it within 24 hours
# xml_str = convert_dict_to_xml({"return_code": "SUCCESS"})
return
True
# HttpResponse
(xml_str)
# return container.REQUEST.RESPONSE
(xml_str)
else
:
print
(
"{0}:{1}"
.
format
(
params
.
get
(
"err_code"
),
params
.
get
(
"err_code_des"
)))
else
:
# Error information
print
(
params
.
get
(
"return_msg"
).
encode
(
"utf-8"
))
else
:
# Error information
print
(
params
.
get
(
"return_msg"
).
encode
(
"utf-8"
))
def
queryWechatOrderStatus
(
self
,
dict_content
):
'''
query url: https://api.mch.weixin.qq.com/pay/orderquery
documentation(Chinese): https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2
The dict_content atleast should contains one of following:
- transaction_id (str): wechat order number, use this in higher priority, it will return in the payment notify callback
- out_trade_no(str): The order ID used inside ERP5, less than 32 characters, digits, alphabets, and "_-|*@", unique in ERP5
'''
if
"transaction_id"
not
in
dict_content
and
"out_trade_no"
not
in
dict_content
:
raise
WechatException
(
"transaction_id or out_trade_no is needed for query the Wechat Order"
)
params
=
{
"appid"
:
APP_ID
,
"mch_id"
:
MCH_ID
,
"nonce_str"
:
generateRandomStr
(),
"transaction_id"
:
dict_content
.
get
(
"transaction_id"
,
""
),
"out_trade_no"
:
dict_content
.
get
(
"out_trade_no"
,
""
),
}
sign
=
calculateSign
(
params
,
API_KEY
)
params
[
"sign"
]
=
sign
# xml_str = convert_dict_to_xml(params)
return
"SUCCESS"
# result = urllib2.Request(QUERY_URL, data=xml_str)
# result_data = urllib2.urlopen(result)
# result_read = result_data.read()
#result_dict_content = convert_xml_to_dict(result_read)
# TBC
\ No newline at end of file
master/bt5/slapos_subscription_request/ExtensionTemplateItem/portal_components/extension.erp5.WechatUtils.xml
View file @
3bd5249c
...
...
@@ -46,16 +46,8 @@
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple>
<string>
W: 9, 0: Cannot decode using encoding "ascii", unexpected byte at position 64 (invalid-encoded-data)
</string>
<string>
W: 13, 0: Cannot decode using encoding "ascii", unexpected byte at position 21 (invalid-encoded-data)
</string>
<string>
W: 24, 0: Cannot decode using encoding "ascii", unexpected byte at position 233 (invalid-encoded-data)
</string>
<string>
W: 7, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 8, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 9, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 11, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 12, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 13, 0: Unnecessary semicolon (unnecessary-semicolon)
</string>
<string>
W: 21, 2: Unreachable code (unreachable)
</string>
<string>
W: 15, 0: Cannot decode using encoding "ascii", unexpected byte at position 63 (invalid-encoded-data)
</string>
<string>
W: 86, 2: Unreachable code (unreachable)
</string>
</tuple>
</value>
</item>
...
...
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