自定义封装:
callback为回调函数
var wxUtils = {
getSignature: function (callback) {
var ticket = this.getTicket();
var url = window.location.href.split('#')[0];
axios.get("http://www.esgz.com:9093/wx/getSignature", {
params: {
ticket: ticket,
url: url
}
}).then(function (res) {
// console.log("getSignature:" + res.data.errcode);
callback(res);
}).catch(function (err) {
weui.alert("获取签名信息失败:"+err, {
title:'系统提示'
});
});
}
调用:
定义一个函数,否则,虽然能够正常执行,但是上述catch会抛出callback not a function错误,
function signatureCallBack(resp) {
timestamp = resp.data.timestamp;
nonceStr = resp.data.nonceStr;
corpId = resp.data.corpId;
signature = resp.data.signature;
console.log("回调:");
console.log("回调:" + timestamp);
console.log("回调:" + nonceStr);
console.log("回调:" + corpId);
console.log("回调:" + signature);
};
wxUtils.getAccessToken();
var ticket = wxUtils.getTicket();
var timestamp = "";
var nonceStr = "";
var corpId = "";
var signature = "";
//回调
wxUtils.getSignature(signatureCallBack);