Test.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. import json
  21. from alipay import AliPay
  22. import time
  23. # 测试接口sdk
  24. class Test(View):
  25. def get(self, request, *args, **kwargs):
  26. response = ResponseObject()
  27. devToken = request.GET.get('devToken', '')
  28. app_key = request.GET.get('app_key', '')
  29. master_secret = request.GET.get('master_secret', '')
  30. import jpush as jpush
  31. # 此处换成各自的app_key和master_secret
  32. _jpush = jpush.JPush(app_key, master_secret)
  33. push = _jpush.create_push()
  34. # if you set the logging level to "DEBUG",it will show the debug logging.
  35. _jpush.set_logging("DEBUG")
  36. # push.audience = jpush.all_
  37. push.audience = jpush.registration_id(devToken)
  38. push.notification = jpush.notification(alert="hello python jpush api")
  39. push.platform = jpush.all_
  40. try:
  41. response = push.send()
  42. except Exception as e:
  43. print("Exception")
  44. return response.json(10,repr(e))
  45. return response.json(0)
  46. def post(self, request, *args, **kwargs):
  47. response = ResponseObject()
  48. data = request.POST.dict()
  49. signature = data["sign"]
  50. data.pop('sign')
  51. print(json.dumps(data))
  52. print(signature)
  53. # verify
  54. app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
  55. alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
  56. alipay = AliPay(
  57. appid="2016092200569234",
  58. app_notify_url=None, # the default notify path
  59. app_private_key_string=app_private_key_string,
  60. alipay_public_key_string=alipay_public_key_string,
  61. sign_type="RSA2", # RSA or RSA2
  62. debug=False # False by default
  63. )
  64. success = alipay.verify(data, signature)
  65. if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
  66. print("trade succeed")
  67. return response.json(0, signature)
  68. # 修改 资源改变
  69. def put(self, request):
  70. response = ResponseObject()
  71. return response.json(0, '')
  72. # 修改 属性改变
  73. def PATCH(self, request):
  74. response = ResponseObject()
  75. return response.json(0)
  76. # 删除
  77. def delete(self, request):
  78. response = ResponseObject()
  79. return response.json(0)
  80. def validation(self, request_dict, *args, **kwargs):
  81. response = ResponseObject()
  82. return response.json(0)