12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
- @AUTHOR: ASJRD018
- @NAME: Ansjer
- @software: PyCharm
- @DATE: 2018/5/22 13:58
- @Version: python3.6
- @MODIFY DECORD:ansjer dev
- @file: Test.py
- @Contact: chanjunkai@163.com
- """
- from django.views.generic.base import View
- '''
- 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()
- devToken = request.get('devToken',None)
- import jpush as jpush
- # 此处换成各自的app_key和master_secret
- app_key = 'b85cd8c899fa549535e61ecc'
- master_secret = '6ce8d1ce403ae102661ca3b8'
- _jpush = jpush.JPush(app_key, master_secret)
- push = _jpush.create_push()
- # if you set the logging level to "DEBUG",it will show the debug logging.
- _jpush.set_logging("DEBUG")
- # push.audience = jpush.all_
- push.audience = jpush.registration_id(devToken)
- push.notification = jpush.notification(alert="hello python jpush api")
- push.platform = jpush.all_
- try:
- response = push.send()
- except:
- print("Exception")
- return response.json(0)
- def post(self, request, *args, **kwargs):
- response = ResponseObject()
- data = request.POST.dict()
- signature = data["sign"]
- 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, '')
- # 修改 属性改变
- def PATCH(self, request):
- response = ResponseObject()
- return response.json(0)
- # 删除
- def delete(self, request):
- response = ResponseObject()
- return response.json(0)
- def validation(self, request_dict, *args, **kwargs):
- response = ResponseObject()
- return response.json(0)
|