哈哈,别惊讶,就是引用变量,真想骂人,基础不牢靠,就这么个知识点,我捣鼓了半天,才算搞明白。。。我已经开始怀疑自己的智商了。
场景是这样的,字典里引用变量,字典里是需要加引号的,而直接给变量,使用引号,那就不是变量了,废话不多说,直接上例子。
import execjs
class DataHanding():
def encrpt_pwd(self, telephone, password):
# 前端加密的代码
js_str = """
const CryptoJS = require ('crypto-js/crypto-js')
function getKey(key) {
var realKey = CryptoJS.SHA1(key)
realKey = CryptoJS.SHA1(realKey).toString().substring(0, 32)
return realKey
}
function encrypt(data, key) {
var realKey = getKey(key)
var encrypt = CryptoJS.AES.encrypt(data, CryptoJS.enc.Hex.parse(realKey), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypt.ciphertext.toString(CryptoJS.enc.Base64)
}
"""
exec_js = execjs.compile(js_str)
return str(exec_js.call("encrypt", password, telephone))
if __name__ == '__main__':
d = DataHanding()
print(d.encrpt_pwd('************', '***********'))
print("\'")
首先是这个,因为是数字,刚开始没加引号。。。JavaScript就当成整型了,报错。这个没花多长时间就解决了。重点在下面。
import requests
import json
import execjs
class Incoming():
def __init__(self):
self.URL = "https://bmp-test.iboxpay.com"
self.telephone1 = ***********
self.password1 = **********
def build_uri(self, endpoint):
return '/'.join([self.URL, endpoint])
def better_output(self, json_str):
return json.dumps(json.loads(json_str), indent=4)
def request_method(self, result):
print("hello,world")
json = {"userPhone": "%s" % self.telephone1, "userPwd": "%s" % result}
print(json)
response = requests.post(self.build_uri("nf_gateway/nf_user_auth_web/ignore_tk/uc/agent/v1/login_default.json"),
headers={"Content-Type": "application/json"},
json={"userPhone": "%s" % self.telephone1, "userPwd": "%s" % result})
print(self.better_output(response.content))
print(response.status_code)
def encrpt_pwd(self, telephone, password):
js_str = """
const CryptoJS = require ('crypto-js/crypto-js')
function getKey(key) {
var realKey = CryptoJS.SHA1(key)
realKey = CryptoJS.SHA1(realKey).toString().substring(0, 32)
return realKey
}
function encrypt(data, key) {
var realKey = getKey(key)
var encrypt = CryptoJS.AES.encrypt(data, CryptoJS.enc.Hex.parse(realKey), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypt.ciphertext.toString(CryptoJS.enc.Base64)
}
"""
print(js_str)
exec_js = execjs.compile(js_str)
print(exec_js)
return str(exec_js.call("encrypt", password, telephone))
if __name__ == '__main__':
print("this is main method")
i = Incoming()
result = i.encrpt_pwd("*********", "**********")
i.request_method(result)
json = {"userPhone": "%s" % self.telephone1, "userPwd": "%s" % result}
重点就是这条,你要说这个知识点会不会吧,没谁能说不会,但是。。。明知是坑还是义无反顾。
print_r('点个赞吧');
var_dump('点个赞吧');
NSLog(@"点个赞吧!")
System.out.println("点个赞吧!");
console.log("点个赞吧!");
print("点个赞吧!");
printf("点个赞吧!\n");
cout << "点个赞吧!" << endl;
Console.WriteLine("点个赞吧!");
fmt.Println("点个赞吧!")
Response.Write("点个赞吧");
alert(’点个赞吧’)