1.pip install pyexecjs
2.js文件如下
```javascript
function encode2(phone) {
return 'hahaha'+phone
}
3.调用
```python
import os
import execjs
def testPy(phone: str):
print('当前目录是:', os.getcwd())
#调用js步骤1
rFile = open(r"D:\pythonprojects\python-auto-test\anshiyatai\fzx_khd\js_test\jsencrypt.min.js", 'r',
encoding='UTF-8')
testResult = execjs.compile(rFile.read()).call('encode2', phone)
return testResult
def get_jiami(phone: str):
# 运行环境:JScript,Node,PhantomJS
# 调用js步骤2
os.environ["EXECJS_RUNTIME"] = "Node"
return testPy(phone)
if __name__ == '__main__':
print(get_jiami('111111'))
4.结果