使用w.url.cn 短网址

起码 微信和QQ不会封的,申请一个微信测试号 拿到一个appid就可以了,我一直用这个

微信公众号的测试号

https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

用法:

/index.php?url=

把下面的代码随便新建一个.php的文件就行

<?php

$url = $_REQUEST['url']; //长网址
$appID = ''; // appID
$appsecret = ''; // appsecret

$url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appID.'&secret='.$appsecret;

$access_token = icurl($url_access_token)['access_token'];
$url_shorturl = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token='.$access_token;

$data = json_encode(
        array(
                'action' => 'long2short',
                'long_url' => $url
        )
);

$short_url = icurl($url_shorturl, $data)['short_url'];
echo "$short_url";


function icurl($url, $data = NULL)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    if($data)
    {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    $res = curl_exec($ch);
    curl_close($ch);
    return json_decode($res,1);
}

© 版权声明
THE END
喜欢就支持以下吧
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容