| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | 
							- #!/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):
 
-         import json
 
-         import requests
 
-         data = {
 
-             "key1": "abc",
 
-             "key2": "def"
 
-         }
 
-         json_data = {
 
-             "collapse_key": "WhatYouWant",
 
-             "data": data,
 
-             "delay_while_idle": False,
 
-             "time_to_live": 3600,
 
-             "registration_ids": [
 
-                 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
 
-         }
 
-         url = 'https://android.googleapis.com/gcm/send'
 
-         serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
 
-         data = json.dumps(json_data).encode('utf-8')
 
-         headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
 
-         req = requests.post(url, data, headers=headers)
 
-         response = ResponseObject()
 
-         return response.json(0)
 
-     def jgPush(self, request):
 
-         response = ResponseObject()
 
-         devToken = request.GET.get('devToken', '')
 
-         app_key = request.GET.get('app_key', '')
 
-         master_secret = request.GET.get('master_secret', '')
 
-         import jpush as jpush
 
-         # 此处换成各自的app_key和master_secret
 
-         _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:
 
-             res = push.send()
 
-         except Exception as e:
 
-             print("Exception")
 
-             return response.json(10, repr(e))
 
-         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)
 
 
  |