|
@@ -18,78 +18,68 @@ http://192.168.136.40:8077/Test
|
|
|
'''
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
+import json
|
|
|
+from alipay import AliPay
|
|
|
+import time
|
|
|
|
|
|
# 测试接口sdk
|
|
|
class Test(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
response = ResponseObject()
|
|
|
- from alipay import AliPay, ISVAliPay
|
|
|
- import time
|
|
|
+
|
|
|
app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
|
|
|
alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
|
|
|
- orderID = int(time.time())+int(time.time())
|
|
|
+ orderID = int(time.time()) + int(time.time())
|
|
|
alipay = AliPay(
|
|
|
appid="2016092200569234",
|
|
|
app_notify_url=None, # the default notify path
|
|
|
app_private_key_string=app_private_key_string,
|
|
|
# alipay public key, do not use your own public key!
|
|
|
alipay_public_key_string=alipay_public_key_string,
|
|
|
- sign_type="RSA", # RSA or RSA2
|
|
|
+ sign_type="RSA2", # RSA or RSA2
|
|
|
debug=False # False by default
|
|
|
)
|
|
|
order_string = alipay.api_alipay_trade_wap_pay(
|
|
|
out_trade_no=str(orderID),
|
|
|
total_amount=0.01,
|
|
|
subject="实用性充气式玩具",
|
|
|
- return_url="https://test.dvema.com",
|
|
|
- # notify_url="https://example.com/notify" # this is optional
|
|
|
+ return_url="http://192.168.136.40:8077/",
|
|
|
+ notify_url="http://test.dvema.com/Test" # this is optional
|
|
|
)
|
|
|
print(order_string)
|
|
|
from django.http import HttpResponseRedirect
|
|
|
# return response.json(0,"https://openapi.alipay.com/gateway.do? + {order_string}".format(order_string=order_string))
|
|
|
print(order_string)
|
|
|
- return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?"+order_string)
|
|
|
- return HttpResponseRedirect("https://openapi.alipay.com/gateway.do?"+order_string)
|
|
|
- # # 增加
|
|
|
- # def get(self, request, *args, **kwargs):
|
|
|
- # response = ResponseObject()
|
|
|
- # from alipay import AliPay, ISVAliPay
|
|
|
- # import time
|
|
|
- # app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
|
|
|
- # alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
|
|
|
- # orderID = int(time.time())+int(time.time())
|
|
|
- # alipay = AliPay(
|
|
|
- # appid="2016092200569234",
|
|
|
- # app_notify_url=None, # the default notify path
|
|
|
- # app_private_key_string=app_private_key_string,
|
|
|
- # # alipay public key, do not use your own public key!
|
|
|
- # alipay_public_key_string=alipay_public_key_string,
|
|
|
- # sign_type="RSA", # RSA or RSA2
|
|
|
- # debug=False # False by default
|
|
|
- # )
|
|
|
- # order_string = alipay.api_alipay_trade_wap_pay(
|
|
|
- # out_trade_no=str(orderID),
|
|
|
- # total_amount=0.01,
|
|
|
- # subject="实用性充气版玩具",
|
|
|
- # return_url="https://test.dvema.com",
|
|
|
- # # notify_url="https://example.com/notify" # this is optional
|
|
|
- # )
|
|
|
- # print(order_string)
|
|
|
- # from django.http import HttpResponseRedirect
|
|
|
- # # return response.json(0,"https://openapi.alipay.com/gateway.do? + {order_string}".format(order_string=order_string))
|
|
|
- # print(order_string)
|
|
|
- # return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?"+order_string)
|
|
|
- # # 增加
|
|
|
+ return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?" + order_string)
|
|
|
+ return HttpResponseRedirect("https://openapi.alipay.com/gateway.do?" + order_string)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
+ data = request.POST
|
|
|
response = ResponseObject()
|
|
|
- return response.json(0)
|
|
|
+ signature = data.pop("sign")
|
|
|
+ print(json.dumps(data))
|
|
|
+ print(signature)
|
|
|
+ # verify
|
|
|
+ app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
|
|
|
+ alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
|
|
|
+ alipay = AliPay(
|
|
|
+ appid="2016092200569234",
|
|
|
+ app_notify_url=None, # the default notify path
|
|
|
+ app_private_key_string=app_private_key_string,
|
|
|
+ alipay_public_key_string=alipay_public_key_string,
|
|
|
+ sign_type="RSA2", # RSA or RSA2
|
|
|
+ debug=False # False by default
|
|
|
+ )
|
|
|
+ success = alipay.verify(data, signature)
|
|
|
+ if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
+ print("trade succeed")
|
|
|
+ return response.json(0, signature)
|
|
|
|
|
|
# 修改 资源改变
|
|
|
def put(self, request):
|
|
|
response = ResponseObject()
|
|
|
- return response.json(0)
|
|
|
+ return response.json(0, '')
|
|
|
|
|
|
# 修改 属性改变
|
|
|
def PATCH(self, request):
|