//调用百度接口获取短连接
shareModalComponent.prototype.getShortLink = function (longLink, type) {
var _this = this;
var that = this;
var sentUrl = 'https://dwz.cn/admin/v2/create';
var token = 'xxxx';
var headers = new _angular_common_http__WEBPACK_IMPORTED_MODULE_8__["HttpHeaders"]();
headers = headers.append('Token', token);
var options = { "headers": headers };
this.http.post(sentUrl, {
Url: longLink,
TermOfValidity: '1-year'
}, options).subscribe(function (result) {
console.log(result);
// if (r.ok) {
// let result = JSON.parse(r._body);
//百度短链接接口报文
// {
// "Code": 0,
// "ShortUrl": "https://dwz.cn/de3rp2Fl",
// "LongUrl": "http://www.baidu.com",
// "ErrMsg": ""
// }
if (result && result.Code == 0) {
if (!_this.codeUrl || !_this.codeUrlForHomepage) {
if (type == 1) {
_this.codeUrl = result.ShortUrl;
setTimeout(function () {
if (document.getElementsByTagName("qrcode")[0]) {
var image = document.getElementsByTagName("qrcode")[0].getElementsByTagName("canvas")[0].toDataURL();
if (!image && image == '') {
image = document.getElementsByTagName("qrcode")[0].getElementsByTagName("img")[0].src;
}
that.qrImg = image;
}
}, 1000);
}
else if (type == 2) {
_this.codeUrlForHomepage = result.ShortUrl;
setTimeout(function () {
if (document.getElementById("qr-code-homepage")) {
var image = document.getElementById("qr-code-homepage").getElementsByTagName("canvas")[0].toDataURL();
if (!image && image == '') {
image = document.getElementById("qr-code-homepage").getElementsByTagName("img")[0].src;
}
that.qrImgHomePage = image;
}
}, 1000);
}
}
}
else {
// this.sendErrorMsg()
_this.getShortLink2(longLink, type);
}
// } else {
// // this.sendErrorMsg()
// this.getShortLink2(longLink, type);
// }
}, function (err) {
// this.sendErrorMsg()
_this.getShortLink2(longLink, type);
});
};
前端调用百度短网址转换接口
于 2022-04-08 14:25:16 首次发布