var querystring = require('querystring')
function main() {
    let long_url = args[0]
    let isRestful = payload.get().path == '/api/utils/sortUrl'
    if (isRestful) {
        long_url = payload.get().body?.toString()
        if (long_url == '') {
            long_url = payload.get().query.url[0]
        }
    }
    // console.log(long_url)
    let req = {
        url: 'https://sms.yunpian.com/v2/short_url/shorten.json',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: querystring.stringify({
            apikey: '75fd56f3de776f96aca27801f981dd8f',
            long_url: long_url,
        }),
    }

    let res = request.parse(req).body.toObject()

    if (isRestful) {
        return okMsg(res.short_url)
    }

    // console.log(JSON.stringify(res))

    return res
}