channel_special_replace.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import file_utils
  2. import os
  3. from print_log import printlog
  4. from xml.etree import ElementTree as ET
  5. from xml.etree.ElementTree import SubElement
  6. androidNS = 'http://schemas.android.com/apk/res/android'
  7. scheme = '{' + androidNS + '}scheme'
  8. name_key = '{' + androidNS + '}name'
  9. def HuaweiReplace(prj_path, key, value):
  10. if key == 'agconnect-services.json':
  11. printlog('replace huawei agconnect-services.json')
  12. huawei_sdk_config_path = os.path.join(prj_path, 'assets', key)
  13. file_utils.copy_file(value, huawei_sdk_config_path)
  14. pass
  15. def YingYongBaoReplace(prj_path, key, value):
  16. if key == "IS_SAND_BOX":
  17. ysdk_sand_url = "https://ysdktest.qq.com"
  18. ysdk_online_url = "https://ysdk.qq.com"
  19. if value == "1":
  20. ysdk_url = ysdk_sand_url
  21. else:
  22. ysdk_url = ysdk_online_url
  23. file_utils.replace_assets_param("%s/assets/ysdkconf.ini" % prj_path, "YSDK_URL", ysdk_url)
  24. return
  25. if key == "QQ_APP_ID" or key == "WX_APP_ID":
  26. manifest = os.path.join(prj_path, 'AndroidManifest.xml')
  27. ysdk_conf_path = os.path.join(prj_path, 'assets', 'ysdkconf.ini')
  28. ET.register_namespace('android', androidNS)
  29. tree = ET.parse(manifest)
  30. root = tree.getroot()
  31. appNode = root.find('application')
  32. if appNode is None:
  33. return 1
  34. metaNodeList = appNode.findall('meta-data')
  35. if metaNodeList is None:
  36. return 1
  37. activityNodeList = appNode.findall('activity')
  38. if activityNodeList is None:
  39. return 1
  40. for activityNode in activityNodeList:
  41. activityName = activityNode.get(name_key)
  42. if activityName == 'com.tencent.tauth.AuthActivity' and key == "QQ_APP_ID":
  43. intentFilters = activityNode.findall('intent-filter')
  44. if intentFilters is not None and len(intentFilters) > 0:
  45. for intentNode in intentFilters:
  46. dataNode = intentNode.find('data')
  47. intentNode.remove(dataNode)
  48. dataNode = SubElement(intentNode, 'data')
  49. dataNode.set(scheme, 'tencent' + value)
  50. printlog("path ysdkconfig.ini:%s" % ysdk_conf_path)
  51. file_utils.replace_assets_param(ysdk_conf_path, key, value)
  52. file_utils.replace_assets_param(ysdk_conf_path, 'OFFER_ID', value)
  53. for metaNode in metaNodeList:
  54. name = metaNode.get(key)
  55. if name == 'MAIN_ACTIVITY':
  56. metaNode.set(value, 'com.ftt.hwal2.gl.cn.chinamain.ChinaMainActivity')
  57. break
  58. if activityName == 'com.tencent.ysdk.module.user.impl.freelogin.FreeLoginInfoActivity'\
  59. and key == "QQ_APP_ID":
  60. intentFilters = activityNode.findall('intent-filter')
  61. if intentFilters is not None and len(intentFilters) > 0:
  62. for intentNode in intentFilters:
  63. dataNode = intentNode.find('data')
  64. intentNode.remove(dataNode)
  65. dataNode = SubElement(intentNode, 'data')
  66. dataNode.set(scheme, 'tencentysdk' + value)
  67. if activityName == 'com.tencent.ysdk.module.user.impl.freelogin.FreeLoginInfoActivity'\
  68. and key == "WX_APP_ID":
  69. intentFilters = activityNode.findall('intent-filter')
  70. if intentFilters is not None and len(intentFilters) > 0:
  71. for intentNode in intentFilters:
  72. dataNode = intentNode.find('data')
  73. intentNode.remove(dataNode)
  74. dataNode = SubElement(intentNode, 'data')
  75. dataNode.set(scheme, 'tencentysdk' + value)
  76. if activityName.endswith('WXEntryActivity') and key == "WX_APP_ID":
  77. intentFilters = activityNode.findall('intent-filter')
  78. if intentFilters is not None and len(intentFilters) > 0:
  79. for intentNode in intentFilters:
  80. dataNode = intentNode.find('data')
  81. intentNode.remove(dataNode)
  82. dataNode = SubElement(intentNode, 'data')
  83. dataNode.set(scheme, value)
  84. file_utils.replace_assets_param(ysdk_conf_path, key, value)
  85. tree.write(manifest, 'UTF-8')
  86. specialReplace = {
  87. "huawei": HuaweiReplace,
  88. "yingyongbao": YingYongBaoReplace
  89. }
  90. def get_special_replace(sdk_name):
  91. if sdk_name in specialReplace:
  92. return specialReplace[sdk_name]
  93. else:
  94. return None
  95. pass