45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
import re
|
|
|
|
with open("C:\\Users\\Jone\\Documents\\HBuilderProjects\\crmeb\\pages\\annex\\web_view\\index.vue", "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
# Find and replace the whole _applyIdentity method
|
|
pattern = r'(\t\t_applyIdentity\(targetUrl, openid, unionid, urlOpenid\) \{[^}]+\}[^}]+?this\._finalizeUrl\(targetUrl\);)'
|
|
replacement = """\t\t_applyIdentity(targetUrl, openid, unionid, urlOpenid) {
|
|
\t\t\tif (urlOpenid && urlOpenid !== openid) {
|
|
\t\t\t\ttargetUrl = stripAuthParams(targetUrl);
|
|
\t\t\t\tconst joiner = targetUrl.indexOf('?') !== -1 ? '&' : '?';
|
|
\t\t\t\tconst t = Math.floor(Date.now() / 1000);
|
|
\t\t\t\ttargetUrl = targetUrl + joiner + 'openid=' + encodeURIComponent(openid);
|
|
\t\t\t\tif (unionid) targetUrl += '&unionid=' + encodeURIComponent(unionid);
|
|
\t\t\t\ttargetUrl += '&t=' + t;
|
|
\t\t\t\tconsole.log('[web_view] 替换为当前用户身份');
|
|
\t\t\t} else if (!urlOpenid) {
|
|
\t\t\t\ttargetUrl = stripAuthParams(targetUrl);
|
|
\t\t\t\tconst joiner = targetUrl.indexOf('?') !== -1 ? '&' : '?';
|
|
\t\t\t\tconst t = Math.floor(Date.now() / 1000);
|
|
\t\t\t\ttargetUrl = targetUrl + joiner + 'openid=' + encodeURIComponent(openid);
|
|
\t\t\t\tif (unionid) targetUrl += '&unionid=' + encodeURIComponent(unionid);
|
|
\t\t\t\ttargetUrl += '&t=' + t;
|
|
\t\t\t\tconsole.log('[web_view] 补充身份参数');
|
|
\t\t\t} else {
|
|
\t\t\t\tconsole.log('[web_view] 身份一致,保留原 URL');
|
|
\t\t\t}
|
|
\t\t\tthis.debugMsg += ' [最终URL] ' + targetUrl.substring(0, 120);
|
|
\t\t\tthis._finalizeUrl(targetUrl);
|
|
\t\t},"""
|
|
|
|
if re.search(pattern, c, re.DOTALL):
|
|
c = re.sub(pattern, replacement, c, count=1, flags=re.DOTALL)
|
|
with open("C:\\Users\\Jone\\Documents\\HBuilderProjects\\crmeb\\pages\\annex\\web_view\\index.vue", "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
script = c[c.find("<script>"):c.find("</script>")]
|
|
print(f"Balance: {script.count('{') - script.count('}')}")
|
|
print("SUCCESS")
|
|
else:
|
|
print("Pattern not found")
|
|
# Debug: show what's around _applyIdentity
|
|
idx = c.find("_applyIdentity")
|
|
if idx > 0:
|
|
print(c[idx:idx+500])
|