Test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: Ansjer
  7. @software: PyCharm
  8. @DATE: 2018/5/22 13:58
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: Test.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. from django.views.generic.base import View
  15. '''
  16. http://192.168.136.40:8077/Test
  17. '''
  18. from Object.ResponseObject import ResponseObject
  19. from Ansjer.config import BASE_DIR
  20. # 测试接口sdk
  21. class Test(View):
  22. def get(self, request, *args, **kwargs):
  23. response = ResponseObject()
  24. from alipay import AliPay, ISVAliPay
  25. import time
  26. app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
  27. alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
  28. orderID = int(time.time())+int(time.time())
  29. alipay = AliPay(
  30. appid=str(orderID),
  31. app_notify_url=None, # the default notify path
  32. app_private_key_string=app_private_key_string,
  33. # alipay public key, do not use your own public key!
  34. alipay_public_key_string=alipay_public_key_string,
  35. sign_type="RSA", # RSA or RSA2
  36. debug=False # False by default
  37. )
  38. order_string = alipay.api_alipay_trade_wap_pay(
  39. out_trade_no="20161112",
  40. total_amount=0.01,
  41. subject="实用性充气版玩具",
  42. return_url="https://test.dvema.com",
  43. # notify_url="https://example.com/notify" # this is optional
  44. )
  45. print(order_string)
  46. from django.http import HttpResponseRedirect
  47. # return response.json(0,"https://openapi.alipay.com/gateway.do? + {order_string}".format(order_string=order_string))
  48. print(order_string)
  49. return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?"+order_string)
  50. # 增加
  51. def post(self, request, *args, **kwargs):
  52. response = ResponseObject()
  53. return response.json(0)
  54. # 修改 资源改变
  55. def put(self, request):
  56. response = ResponseObject()
  57. return response.json(0)
  58. # 修改 属性改变
  59. def PATCH(self, request):
  60. response = ResponseObject()
  61. return response.json(0)
  62. # 删除
  63. def delete(self, request):
  64. response = ResponseObject()
  65. return response.json(0)
  66. def validation(self, request_dict, *args, **kwargs):
  67. response = ResponseObject()
  68. return response.json(0)