# -*- coding: UTF-8 -*-
# Copyright (c) 2014 The CCP project authors. All Rights Reserved.
#
# Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
# that can be found in the LICENSE file in the root of the web site.
#
# http://www.yuntongxun.com
#
# An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
from hashlib import md5
import base64
import datetime
from urllib import request as urllib2
import json
from .xmltojson import xmltojson
class REST:
AccountSid = ''
AccountToken = ''
AppId = ''
SubAccountSid = ''
SubAccountToken = ''
ServerIP = ''
ServerPort = ''
SoftVersion = ''
Iflog = False # 是否打印日志
Batch = '' # 时间戳
BodyType = 'xml' # 包体格式,可填值:json 、xml
# 初始化
# @param serverIP 必选参数 服务器地址
# @param serverPort 必选参数 服务器端口
# @param softVersion 必选参数 REST版本号
def __init__(self, ServerIP, ServerPort, SoftVersion):
self.ServerIP = ServerIP
self.ServerPort = ServerPort
self.SoftVersion = SoftVersion
# 设置主帐号
# @param AccountSid 必选参数 主帐号
# @param AccountToken 必选参数 主帐号Token
def setAccount(self, AccountSid, AccountToken):
self.AccountSid = AccountSid
self.AccountToken = AccountToken
# 设置子帐号
#
# @param SubAccountSid 必选参数 子帐号
# @param SubAccountToken 必选参数 子帐号Token
def setSubAccount(self, SubAccountSid, SubAccountToken):
self.SubAccountSid = SubAccountSid
self.SubAccountToken = SubAccountToken
# 设置应用ID
#
# @param AppId 必选参数 应用ID
def setAppId(self, AppId):
self.AppId = AppId
def log(self, url, body, data):
print('这是请求的URL:')
print(url)
print('这是请求包体:')
print(body)
print('这是响应包体:')
print(data)
print('********************************')
# 创建子账号
# @param friendlyName 必选参数 子帐号名称
def CreateSubAccount(self, friendlyName):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
# 生成sig
signature = self.AccountSid + self.AccountToken + self.Batch
sig = md5(signature.encode()).hexdigest().upper()
# 拼接URL
url = "https://" + self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/SubAccounts?sig=" + sig
# 生成auth
src = self.AccountSid + ":" + self.Batch
auth = base64.encodebytes(src.encode()).decode().strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
# xml格式
body = '''<?xml version="1.0" encoding="utf-8"?><SubAccount><appId>%s</appId>\
<friendlyName>%s</friendlyName>\
</SubAccount>\
''' % (self.AppId, friendlyName)
if self.BodyType == 'json':
# json格式
body = '''{"friendlyName": "%s", "appId": "%s"}''' % (friendlyName, self.AppId)
data = ''
req.data = body.encode()
try:
res = urllib2.urlopen(req)
data = res.read()
res.close()
if self.BodyType == 'json':
# json格式
locations = json.loads(data)
else:
# xml格式
xtj = xmltojson()
locations = xtj.main(data)
if self.Iflog:
self.log(url, body, data)
return locations
except Exception as error:
if self.Iflog:
self.log(url, body, data)
return {'172001': '网络错误'}
# 获取子帐号
# @param startNo 可选参数 开始的序号,默认从0开始
# @param offset 可选参数 一次查询的最大条数,最小是1条,最大是100条
def getSubAccounts(self, startNo, offset):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
# 生成sig
signature = self.AccountSid + self.AccountToken + self.Batch
sig = md5(signature.encode()).hexdigest().upper()
# 拼接URL
url = "https://" + self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/GetSubAccounts?sig=" + sig
# 生成auth
src = self.AccountSid + ":" + self.Batch
# auth = base64.encodestring(src).strip()
auth = base64.encodebytes(src.encode()).decode().strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
# xml格式
body = '''<?xml version="1.0" encoding="utf-8"?><SubAccount><appId>%s</appId>\
<startNo>%s</startNo><offset>%s</offset>\
</SubAccount>\
''' % (self.AppId, startNo, offset)
if self.BodyType == 'json':
# json格式
body = '''{"appId": "%s", "startNo": "%s", "offset": "%s"}''' % (self.AppId, startNo, offset)
data = ''
req.data = body.encode()
try:
res = urllib2.urlopen(req)
data = res.read()
res.close()
if self.BodyType == 'json':
# json格式
locations = json.loads(data)
else:
# xml格式
xtj = xmltojson()
locations = xtj.main(data)
if self.Iflog:
self.log(url, body, data)
return locations
except Exception as error:
if self.Iflog:
self.log(url, body, data)
return {'172001': '网络错误'}
# 子帐号信息查询
# @param friendlyName 必选参数 子帐号名称
def querySubAccount(self, friendlyName):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
# 生成sig
signature = self.AccountSid + self.AccountToken + self.Batch
sig = md5(signature.encode()).hexdigest().upper()
# 拼接URL
url = "https://" + self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/QuerySubAccountByName?sig=" + sig
# 生成auth
src = self.AccountSid + ":" + self.Batch
# auth = base64.encodestring(src).strip()
auth = base64.encodebytes(src.encode()).decode().strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
# 创建包体
body = '''<?xml version="1.0" encoding="utf-8"?><SubAccount><appId>%s</appId>\
<friendlyName>%s</friendlyName>\
</SubAccount>\
''' % (self.AppId, friendlyName)
if self.BodyType == 'json':
body = '''{"friendlyName": "%s", "appId": "%s"}''' % (friendlyName, self.AppId)
data = ''
req.data = body.encode()
try:
res = urllib2.urlopen(req)
data = res.read()
res.close()
if self.BodyType == 'json':
# json格式
locations = json.loads(data)
else:
# xml格式
xtj = xmltojson()
locations = xtj.main(data)
if self.Iflog:
self.log(url, body, data)
return locations
except Exception as error:
if self.Iflog:
self.log(url, body, data)
return {'172001': '网络错误'}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目是一款基于Python和跨平台技术的Calabash Brothers游戏开发源码,包含1716个文件,涵盖634个JavaScript文件、296个CSS文件、196个PNG图片文件、170个LESS文件、136个HTML文件、72个Python文件、30个SCSS文件、29个Markdown文件、19个TrueType字体文件、16个JSON文件。代码集合中包含了丰富的前端和后端资源,适用于多平台游戏开发需求。
资源推荐
资源详情
资源评论
收起资源包目录
基于Python和跨平台技术的Calabash Brothers游戏开发源码 (1729个子文件)
sui.min.css 220KB
sui.min.css 220KB
bootstrap.css 143KB
bootstrap.css 143KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
samples.css 64KB
samples.css 64KB
font-awesome.css 37KB
font-awesome.css 37KB
main.css 36KB
main.css 36KB
editor_ie7.css 33KB
editor_ie7.css 33KB
editor_iequirks.css 31KB
editor_iequirks.css 31KB
editor_ie8.css 31KB
editor_ie8.css 31KB
editor_ie.css 31KB
editor_ie.css 31KB
font-awesome.min.css 30KB
font-awesome.min.css 30KB
editor_gecko.css 30KB
editor_gecko.css 30KB
editor.css 30KB
editor.css 30KB
bootstrap-theme.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
bootstrap-theme.min.css 23KB
sui-append.min.css 21KB
sui-append.min.css 21KB
dialog_ie7.css 15KB
dialog_ie7.css 15KB
dialog_ie8.css 14KB
dialog_ie8.css 14KB
dialog_iequirks.css 14KB
dialog_iequirks.css 14KB
dialog_ie.css 14KB
dialog_ie.css 14KB
dialog.css 13KB
dialog.css 13KB
page-sj-qa-tagDetail.css 11KB
page-sj-qa-tagDetail.css 11KB
page-sj-person-myfile.css 11KB
page-sj-person-myfile.css 11KB
page-sj-person-myreaded.css 10KB
page-sj-person-myreaded.css 10KB
page-sj-makeFriends-list.css 10KB
page-sj-makeFriends-list.css 10KB
page-sj-headline-login.css 9KB
page-sj-headline-login.css 9KB
page-headline-logined.css 9KB
page-headline-logined.css 9KB
page-sj-person-dynamic.css 9KB
page-sj-person-dynamic.css 9KB
page-sj-person-myanswer.css 9KB
page-sj-person-myanswer.css 9KB
page-sj-person-mycollect.css 9KB
page-sj-person-mycollect.css 9KB
page-sj-makeFriends-index.css 8KB
page-sj-makeFriends-index.css 8KB
page-sj-person-homepage.css 8KB
page-sj-person-homepage.css 8KB
normalize.css 8KB
normalize.css 8KB
page-sj-makeFriends-edit.css 8KB
page-sj-makeFriends-edit.css 8KB
page-sj-person-myfocus.css 8KB
page-sj-person-myfocus.css 8KB
page-sj-makeFriends-talk.css 8KB
page-sj-makeFriends-talk.css 8KB
page-sj-person-account.css 7KB
page-sj-person-account.css 7KB
page-sj-headline-submit.css 7KB
page-sj-headline-submit.css 7KB
chat.css 7KB
chat.css 7KB
page-sj-person-myquestion.css 6KB
page-sj-person-myquestion.css 6KB
page-sj-person-myshare.css 6KB
page-sj-person-myshare.css 6KB
page-sj-qa-logined.css 6KB
page-sj-qa-logined.css 6KB
page-sj-qa-login.css 6KB
page-sj-qa-login.css 6KB
page-sj-acticle-editorGrammar.css 6KB
page-sj-acticle-editorGrammar.css 6KB
widget-submit-headline.css 6KB
widget-submit-headline.css 6KB
page-sj-qa-detail.css 5KB
page-sj-qa-detail.css 5KB
widget-tabtags-bottom-line.css 5KB
widget-tabtags-bottom-line.css 5KB
page-sj-acticle-feedback.css 5KB
page-sj-acticle-feedback.css 5KB
page-sj-recruit-area.css 5KB
page-sj-recruit-area.css 5KB
page-sj-recruit-job.css 5KB
page-sj-recruit-job.css 5KB
共 1729 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
lsx202406
- 粉丝: 2452
- 资源: 5591
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功