Loading…

short chain conversion

# Preface This tutorial is based on the "apifm-wxapi" module and teaches you how to quickly implement small program development, so you may need to understand the following knowledge points first: ["Creating HelloWorld Project"](https://www.yuque.com/apifm/doc/hezlrm) ["Use "apifm-wxapi" to quickly develop small programs"](https://www.yuque.com/apifm/doc/mdldsd) # Function description Long links are not conducive to memory. At the same time, because they are too long, they are not conducive to use in text messages, WeChat, Weibo, and advertising and marketing. Therefore, there is a need to convert long links into end-to-end links; This example will help you achieve rapid conversion with just one line of code. Of course, we have to use "apifm-wxapi", a small program development tool! # Effect demonstration ![](https://dcdn.it120.cc/yuque/0/2019/png/572726/1572848578844-f4afa76e-6ebb-454a-af9c-fc5a9d9cb742.png) ## wxml code ```plain Conversion result {{ queryResult }} Copy ``` ## js code ```plain const WXAPI = require('apifm-wxapi') Page({ data: { url: undefined, queryResult: undefined, }, onLoad: function (options) { }, onShow: function () { }, urlChange(e){ this.setData({ url: e.detail.value, queryResult: null }) }, shortUrl() { if (!this.data.url){ wx.showToast({ title: 'Barcode cannot be empty', icon: 'none' }) return } WXAPI.shortUrl(this.data.url).then(res => { console.log(res) if (res.code == 0) { wx.showToast({ title: 'Conversion successful', icon: 'success' }) this.setData({ queryResult: res.data }) } else { wx.showToast({ title: res.msg, icon: 'none' }) } }) }, copyUrl(){ wx.setClipboardData({ data: this.data.queryResult, success(res) { wx.getClipboardData({ success(res) { wx.showToast({ title: 'Copy successfully', icon: 'success' }) } }) } }) } }) ``` > WXAPI.init('gooking') This code links your mini program to your backend, where gooking is your exclusive domain name (please check the chapter about exclusive domain names in the preface); > # Summary This case mainly uses the following methods of apifm-wxapi: ```plain WXAPI.shortUrl(url) ``` _More usage methods about apifm-wxapi: _ ["apifm-wxapi Instructions for Use"](https://github.com/gooking/apifm-wxapi/blob/master/instructions.md) _Download the Demo code of this case: _ ["apifm-wxapi using Demo program"](https://github.com/gooking/apifm-wxapi-demo) Looking forward to your progress! grateful!