UrlHelper.php 1.1 KB
<?php

namespace common\helpers;

use common\exts\wechat\Log as WxLog;

class UrlHelper
{
    /**
     * 获取短地址
     */
    public static function getShortUrl($url)
    {
        WxLog::init();
        WxLog::DEBUG('UrlHelper::getShortUrl->[' . $url . ']');

        $baseurl = 'http://581.so/api.php?format=json&url=' . $url;
        $ch=curl_init();
        curl_setopt($ch, CURLOPT_URL, $baseurl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
        $strRes=curl_exec($ch);
        curl_close($ch);
        $arrResponse=json_decode($strRes,true);
        WxLog::DEBUG('UrlHelper::getShortUrl->' . $strRes);
        if($arrResponse['err'])
        {
            return false;
        }

        return $arrResponse['url'];
    }

    /**
     * 获取微信访问路径
     */
    public static function getWxUrl() {
        if (YII_ENV == "prod") {
            $httpUrl = "https://wx.jiwork.com";
        } else if (YII_ENV == "test") {
            $httpUrl = "https://twx.jiwork.com";
        } else {
            $httpUrl = "http://localhost/jw/src/app-wx/web";
        }
        return $httpUrl;
    }
}