Python 为UnityAndroid端自动化接入Tradplus广告SDK
- Tradplus介绍
- 常规接入
- 进入Android开发文档
- 选择渠道配置
- 生成接入代码
- 人工依赖
- 下载官网同版本的 Unity插件
- 使用自动化工具接入
- 首次 你需要打两个标记来定位
- 运行工具 控制台会列出最新的十个Tradplus版本 任选其一
- 然后拖入项目路径后回车开始植入最新版
- 植入完成后 控制台会输出 end. 这时候工具运行目录下 会自动下载好指定Tradplus版本的Unity插件
- 其它声明
- 渠道配置
- ADMOB BIDDING自定义配置
- 源码
Tradplus介绍
常规接入
进入Android开发文档
技术文档: https://docs.tradplusad.com/docs/tradplussdk_android_doc_v6/download
选择渠道配置
生成接入代码
人工依赖
容易出错 新人入手也比较麻烦
下载官网同版本的 Unity插件
使用自动化工具接入
首次 你需要打两个标记来定位
在Traplus接入开头处 加上
/// TradPlus Start //
在Tradplus接入结尾处 加上
/// TradPlus End //
运行工具 控制台会列出最新的十个Tradplus版本 任选其一
然后拖入项目路径后回车开始植入最新版
植入完成后 控制台会输出 end. 这时候工具运行目录下 会自动下载好指定Tradplus版本的Unity插件
其它声明
渠道配置
修改配置文件 ads 需要接入的广告渠道配置
仅需要在第一次和每次运营更换广告渠道的时候 配置一次
ADMOB BIDDING自定义配置
一般情况下这个版本号是Tradplus官方的人来告诉你这是哪个版本号 改一次就好了
源码
主运行脚本
#默认服务端口import requests
import time
import implant
import downloadUnityPluginsapi = 'https://www.geek7.top:8000/api'
adsChannel = ['UnityAds']
region = '2' # 1: 中国 2: 其它地区adsChannel.clear()
sdkversionList = []
versionstr = ""
def log( msg ):print( msg )def InitChannel():adsChannel.clear()with open('./bin/ads','r') as fp:for line in fp.readlines():adsChannel.append(line.replace('\n',''))def Run( sdk_version = "10.2.0.1",overrid = True ):global versionstrInitChannel()data = {'token' : time.time(),'pipe':'tradplussdk','code':829,'adchannels':','.join(adsChannel),'version':sdk_version,'region' : region}res = requests.get(api,data) j = res.json()if 'version' not in j:log('erro: not foud version property in result.data')returnif 'data' not in j:log('erro: data not in depends')returnappGradleCode = j['data']if None == appGradleCode:log('GetDependencies fail')else:print('input you "Assets\\Plugins\\Android" full path')print('example: D:\\Git\\2dtoilet\\2dtoilet-client\\Assets\\Plugins')print('Or you can try the Android folder to this window.')print('current tradplus version list:')v = j['version']versionstr = '|'.join(v.split(',')[0:10])print(versionstr)if not overrid:sdkversionList.clear()sdkversionList.extend(v.split(','))returnsrcpath = input('input proj:\n')realpath = srcpath.replace('\\','/')implant.Run(realpath,appGradleCode)u3dzip = j['u3dzip']print(f'download unity plugin: {u3dzip}')downloadUnityPlugins.dowanlodZip(u3dzip,'./tradplus_unity_plugin_zips')if __name__ == "__main__":log('begin.')Run( "10.2.0.1", False )version = ""while True:version = input('input you tradplus version: ')print(f'pulling the current version dependency of Tradplus: {version}')if version in sdkversionList:breakelse:print(f'current version fail. :{version}')print(versionstr)Run( version )input('end.')
自动化植入mainTemplate.gradle脚本
import osdef Run( projpath, dependsContent ):print(f'project path: {projpath}')print(f'depend content: {dependsContent}')if not projpath.endswith('mainTemplate.gradle'):projpath = os.path.join(projpath,'mainTemplate.gradle')filterstr = ''dependlines = dependsContent.splitlines()tradplusContent = Falseadmob = Falseadmob_bidding = Falseadmob_bidding_str = "22.1.0.0"with open('./bin/ADMOB BIDDING','r') as fp:lines = fp.readlines()if len(lines) > 0:admob_bidding_str = lines[0]print(f"ADMOB BIDDING : {admob_bidding_str}")for l in dependlines:if l.startswith('dependencies {'):tradplusContent = Trueelif l.startswith('android {'):filterstr = filterstr[0:-2]breakelif tradplusContent:real = l.replace('\"','\'')if admob:admob = Falsesi = real.find('\'')ei = real.find('\'',si+1)com = real[si:ei+1]_import = ''' implementation(%s) {exclude module: "play-services-measurement-sdk-api"}\n'''%(com)filterstr += _importadmob_bidding = Truecontinueif admob_bidding and '// ' in real:_import = ''' //ADMOB BIDDINGimplementation ('com.applovin.mediation:google-adapter:%s'){exclude module: "play-services-measurement-sdk-api"}\n'''%(admob_bidding_str)filterstr += _importadmob_bidding = Falseif '// Admob' in real:admob = Truefilterstr += f'{real}\n'output = ''with open(projpath,'r',encoding='UTF-8') as fp:begin_write = Falselines = fp.readlines()for line in lines:if line.startswith(' /// TradPlus Start //'):output += ' /// TradPlus Start //\n'output += filterstrbegin_write = Trueelif line.startswith(' /// TradPlus End //'):output += ' /// TradPlus End //\n'begin_write = Falseelif not begin_write:output += lineif len(output) != 0 and output != '':print('Under implantation.')with open(projpath,'w',encoding='UTF-8') as fp:fp.write(output)print('Complete implantation.')else:print('got a little problem')
下载unity最新插件脚本
import requests
import zipfile
import tempfile
import osdef get_data( url ):response = requests.get(url)return url, response.contentdef dowanlodZip( url , dest = "./zip"):url, data = get_data( url ) # data为byte字节_tmp_file = tempfile.TemporaryFile() # 创建临时文件print(_tmp_file)_tmp_file.write(data) # byte字节数据写入临时文件# _tmp_file.seek(0)print(f'extract to: {os.path.join(os.getcwd(),dest)}')zf = zipfile.ZipFile(_tmp_file, mode='r')for names in zf.namelist():f = zf.extract(names, dest) # 解压到zip目录文件下print(f)zf.close()print('extract completed')