Test.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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('devToken',None)
  28. import jpush as jpush
  29. # 此处换成各自的app_key和master_secret
  30. app_key = 'b85cd8c899fa549535e61ecc'
  31. master_secret = '6ce8d1ce403ae102661ca3b8'
  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:
  43. print("Exception")
  44. return response.json(0)
  45. def post(self, request, *args, **kwargs):
  46. response = ResponseObject()
  47. data = request.POST.dict()
  48. signature = data["sign"]
  49. data.pop('sign')
  50. print(json.dumps(data))
  51. print(signature)
  52. # verify
  53. app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
  54. alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
  55. alipay = AliPay(
  56. appid="2016092200569234",
  57. app_notify_url=None, # the default notify path
  58. app_private_key_string=app_private_key_string,
  59. alipay_public_key_string=alipay_public_key_string,
  60. sign_type="RSA2", # RSA or RSA2
  61. debug=False # False by default
  62. )
  63. success = alipay.verify(data, signature)
  64. if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
  65. print("trade succeed")
  66. return response.json(0, signature)
  67. # 修改 资源改变
  68. def put(self, request):
  69. response = ResponseObject()
  70. return response.json(0, '')
  71. # 修改 属性改变
  72. def PATCH(self, request):
  73. response = ResponseObject()
  74. return response.json(0)
  75. # 删除
  76. def delete(self, request):
  77. response = ResponseObject()
  78. return response.json(0)
  79. def validation(self, request_dict, *args, **kwargs):
  80. response = ResponseObject()
  81. return response.json(0)