源代码是这样的,然后调用的时候就会报错,报错信息
thirdScriptError
undefined;at pages/mypersonal/mypersonal onLoad function;at api getNetworkType success callback function
undefined
var privateKey_pkcs1 = '-----BEGIN RSA PRIVATE KEY-----' +
...省略...
'----- END RSA PRIVATE KEY-----'
var publicKey_pkcs1 = '-----BEGIN PUBLIC KEY-----' +
...省略...
'----- END PUBLIC KEY-----'
// header 头部
function reqHeader() {
var header = {
'content-type': 'application/x-www-form-urlencoded'
}
return header
}
var sendrsadata = function (url, method, data, header) {
const RSA = require('./wxapp_rsa.js');
var status = true;
var promise = new Promise(function (resolve, reject) {
wx.getNetworkType({
success: function (res) {
// 返回网络类型2g,3g,4g,wifi, none, unknown
var networkType = res.networkType
if (networkType == "none") {
wx.hideLoading();
//没有网络连接
wx.showModal({
title: '提示',
content: '网络连接失败,请检查您的网络设置',
showCancel: false,
success: function (res) {
if (res.confirm) {
//返回res.confirm为true时,表示用户点击确定按钮
console.log('表示用户点击确定按钮')
}
}
})
status = false;
} else if (networkType == "unknown") {
wx.hideLoading();
//未知的网络类型
wx.showModal({
title: '提示',
content: '未知的网络类型,请检查您的网络设置',
showCancel: false,
success: function (res) {
if (res.confirm) {
//返回res.confirm为true时,表示用户点击确定按钮
console.log('表示用户点击确定按钮')
}
}
})
status = false;
} else {
// 加密 【加密字段长度不大于117】
var encrypt_rsa = new RSA.RSAKey();
encrypt_rsa = RSA.KEYUTIL.getKey(publicKey_pkcs1);// 这句话就会报错,报错信息是thirdScriptError undefined;at pages/mypersonal/mypersonal onLoad function;at api getNetworkType success callback function undefined
var encStr = encrypt_rsa.encrypt(data)
data = RSA.hex2b64(encStr);
wx.request({
url: url,
data: data,
method: method,
header: header,
success: resolve,
fail: reject
})
}
}
})
return status
});
return promise;
};
module.exports = {
reqHeader: reqHeader,
sendrsadata: sendrsadata
}