首页 > php教程 > php手册 > 正文

网上各种短网址算法应用的初步详细汇总

WBOY
发布: 2016-06-06 19:44:38
原创
1303 人浏览过

看过新浪的短连接服务,发现后面主要有6个字符串组成,于是第一个想到的就是原来公司写的一个游戏激活码规则,也就是下面的算法2,26个大写字母 26小写字母,10个数字,随机生成6个然后插入数据库对应一个id,短连接跳转的时候,根据字符串查询到对应id,即

看过新浪的短连接服务,发现后面主要有6个字符串组成,于是第一个想到的就是原来公司写的一个游戏激活码规则,也就是下面的算法2,26个大写字母 26小写字母,10个数字,随机生成6个然后插入数据库对应一个id,短连接跳转的时候,根据字符串查询到对应id,即可实现相应的跳转!不过2的62次方,不知道有没有重复的,小概率可以,但是对应不是很大的网站应该足够了


自从twitter推出短网址(shorturl),继之国内各大微博跟风,google公开goo.gl使用API,短网址之风愈演愈烈.不得不说这是一个新兴又一大热门web2.0服务.现整理一下,包括完整短网址网站,短网址算法原理,算法举例,以及优劣比较,同时还介绍几个phper个人实现的.

yourls,完整的ShortUrl网站.由国外著名 WordPress 插件大师级人物 Ozh Richard 和 Lester Chan 一起写的.官方网站是yourls.org.此为开源版本,可以从这里下载.最新版本1.5,昨天试用了一下,默认第一个是1,感觉不是很好,还是喜欢twitter风格的.

turl,phper的个人实现,可下载源码,点击此处

算法原理
算法一
1)将长网址md5生成32位签名串,分为4段, 每段8个字节;
2)对这四段循环处理, 取8个字节, 将他看成16进制串与0x3fffffff(30位1)与操作, 即超过30位的忽略处理;
3)这30位分成6段, 每5位的数字作为字母表的索引取得特定字符, 依次进行获得6位字符串;
4)总的md5串可以获得4个6位串; 取里面的任意一个就可作为这个长url的短url地址;

这种算法,虽然会生成4个,但是仍然存在重复几率,下面的算法一和三,就是这种的实现.

算法二
a-zA-Z0-9 这64位取6位组合,可产生500多亿个组合数量.把数字和字符组合做一定的映射,就可以产生唯一的字符串,如第62个组合就是aaaaa9,第63个组合就是aaaaba,再利用洗牌算法,把原字符串打乱后保存,那么对应位置的组合字符串就会是无序的组合。
把长网址存入数据库,取返回的id,找出对应的字符串,例如返回ID为1,那么对应上面的字符串组合就是bbb,同理 ID为2时,字符串组合为bba,依次类推,直至到达64种组合后才会出现重复的可能,所以如果用上面的62个字符,任意取6个字符组合成字符串的话,你的数据存量达到500多亿后才会出现重复的可能。
具体参看这里彻底完善新浪微博接口和超短URL算法,算法四可以算作是此算法的一种实现,此算法一般不会重复,但是如果是统计的话,就有很大问题,特别是对域名相关的统计,就抓瞎了.

短网址算法枚举

一个来自http://www.snippetit.com/2009/04/php-short-url-algorithm-implementation/ ,
代码如下:
<span><span><?php <br> </span><span>function </span><span>shorturl</span><span>(</span><span>$input</span><span>) { <br>   </span><span>$base32 </span><span>= array ( <br>     </span><span>'a'</span><span>, </span><span>'b'</span><span>, </span><span>'c'</span><span>, </span><span>'d'</span><span>, </span><span>'e'</span><span>, </span><span>'f'</span><span>, </span><span>'g'</span><span>, </span><span>'h'</span><span>, <br>     </span><span>'i'</span><span>, </span><span>'j'</span><span>, </span><span>'k'</span><span>, </span><span>'l'</span><span>, </span><span>'m'</span><span>, </span><span>'n'</span><span>, </span><span>'o'</span><span>, </span><span>'p'</span><span>, <br>     </span><span>'q'</span><span>, </span><span>'r'</span><span>, </span><span>'s'</span><span>, </span><span>'t'</span><span>, </span><span>'u'</span><span>, </span><span>'v'</span><span>, </span><span>'w'</span><span>, </span><span>'x'</span><span>, <br>     </span><span>'y'</span><span>, </span><span>'z'</span><span>, </span><span>'0'</span><span>, </span><span>'1'</span><span>, </span><span>'2'</span><span>, </span><span>'3'</span><span>, </span><span>'4'</span><span>, </span><span>'5' <br>     </span><span>); <br>   <br>   </span><span>$hex </span><span>= </span><span>md5</span><span>(</span><span>$input</span><span>); <br>   </span><span>$hexLen </span><span>= </span><span>strlen</span><span>(</span><span>$hex</span><span>); <br>   </span><span>$subHexLen </span><span>= </span><span>$hexLen </span><span>/ </span><span>8</span><span>; <br>   </span><span>$output </span><span>= array(); <br>   <br>   for (</span><span>$i </span><span>= </span><span>0</span><span>; </span><span>$i </span><span><span>$subHexLen</span><span>; </span><span>$i</span><span>++) { <br>     </span><span>$subHex </span><span>= </span><span>substr </span><span>(</span><span>$hex</span><span>, </span><span>$i </span><span>* </span><span>8</span><span>, </span><span>8</span><span>); <br>     </span><span>$int </span><span>= </span><span>0x3FFFFFFF </span><span>& (</span><span>1 </span><span>* (</span><span>'0x'</span><span>.</span><span>$subHex</span><span>)); <br>     </span><span>$out </span><span>= </span><span>''</span><span>; <br>   <br>     for (</span><span>$j </span><span>= </span><span>0</span><span>; </span><span>$j </span><span><span>6</span><span>; </span><span>$j</span><span>++) { <br>       </span><span>$val </span><span>= </span><span>0x0000001F </span><span>& </span><span>$int</span><span>; <br>       </span><span>$out </span><span>.= </span><span>$base32</span><span>[</span><span>$val</span><span>]; <br>       </span><span>$int </span><span>= </span><span>$int </span><span>>> </span><span>5</span><span>; <br>     } <br>   <br>     </span><span>$output</span><span>[] = </span><span>$out</span><span>; <br>   } <br>   <br>   return </span><span>$output</span><span>; <br> } <br> </span><span>?></span> </span></span></span>

另一个是纯随机数算法
<span><span><?php <br> </span><span>function </span><span>random</span><span>(</span><span>$length</span><span>, </span><span>$pool </span><span>= </span><span>''</span><span>) <br>     { <br>         </span><span>$random </span><span>= </span><span>''</span><span>; <br>   <br>         if (empty(</span><span>$pool</span><span>)) { <br>             </span><span>$pool    </span><span>= </span><span>'abcdefghkmnpqrstuvwxyz'</span><span>; <br>             </span><span>$pool   </span><span>.= </span><span>'23456789'</span><span>; <br>         } <br>   <br>         </span><span>srand </span><span>((double)</span><span>microtime</span><span>()*</span><span>1000000</span><span>); <br>   <br>         for(</span><span>$i </span><span>= </span><span>0</span><span>; </span><span>$i </span><span><span>$length</span><span>; </span><span>$i</span><span>++)  <br>         { <br>             </span><span>$random </span><span>.= </span><span>substr</span><span>(</span><span>$pool</span><span>,(</span><span>rand</span><span>()%(</span><span>strlen </span><span>(</span><span>$pool</span><span>))), </span><span>1</span><span>); <br>         } <br>   <br>         return </span><span>$random</span><span>; <br>     } <br> </span><span>?></span> </span></span>

各大微博短网址(ShortUrl)的算法 ,第一种算法的C#实现
<span><span><?php <br> </span><span>// 这是c#代码,受编辑器的限制,只能用php <br> </span><span>public static </span><span>string</span><span>[] </span><span>ShortUrl</span><span>(</span><span>string url</span><span>) <br>         { <br>             </span><span>//可以自定义生成MD5加密字符传前的混合KEY <br>             </span><span>string key </span><span>= </span><span>"Leejor"</span><span>; <br>             </span><span>//要使用生成URL的字符 <br>             </span><span>string</span><span>[] </span><span>chars </span><span>= new </span><span>string</span><span>[]{ <br>                 </span><span>"a"</span><span>,</span><span>"b"</span><span>,</span><span>"c"</span><span>,</span><span>"d"</span><span>,</span><span>"e"</span><span>,</span><span>"f"</span><span>,</span><span>"g"</span><span>,</span><span>"h"</span><span>, <br>                 </span><span>"i"</span><span>,</span><span>"j"</span><span>,</span><span>"k"</span><span>,</span><span>"l"</span><span>,</span><span>"m"</span><span>,</span><span>"n"</span><span>,</span><span>"o"</span><span>,</span><span>"p"</span><span>, <br>                 </span><span>"q"</span><span>,</span><span>"r"</span><span>,</span><span>"s"</span><span>,</span><span>"t"</span><span>,</span><span>"u"</span><span>,</span><span>"v"</span><span>,</span><span>"w"</span><span>,</span><span>"x"</span><span>, <br>                 </span><span>"y"</span><span>,</span><span>"z"</span><span>,</span><span>"0"</span><span>,</span><span>"1"</span><span>,</span><span>"2"</span><span>,</span><span>"3"</span><span>,</span><span>"4"</span><span>,</span><span>"5"</span><span>, <br>                 </span><span>"6"</span><span>,</span><span>"7"</span><span>,</span><span>"8"</span><span>,</span><span>"9"</span><span>,</span><span>"A"</span><span>,</span><span>"B"</span><span>,</span><span>"C"</span><span>,</span><span>"D"</span><span>, <br>                 </span><span>"E"</span><span>,</span><span>"F"</span><span>,</span><span>"G"</span><span>,</span><span>"H"</span><span>,</span><span>"I"</span><span>,</span><span>"J"</span><span>,</span><span>"K"</span><span>,</span><span>"L"</span><span>, <br>                 </span><span>"M"</span><span>,</span><span>"N"</span><span>,</span><span>"O"</span><span>,</span><span>"P"</span><span>,</span><span>"Q"</span><span>,</span><span>"R"</span><span>,</span><span>"S"</span><span>,</span><span>"T"</span><span>, <br>                 </span><span>"U"</span><span>,</span><span>"V"</span><span>,</span><span>"W"</span><span>,</span><span>"X"</span><span>,</span><span>"Y"</span><span>,</span><span>"Z" <br> <br>               </span><span>}; <br>             </span><span>//对传入网址进行MD5加密 <br>             </span><span>string hex </span><span>= </span><span>System</span><span>.</span><span>Web</span><span>.</span><span>Security</span><span>.</span><span>FormsAuthentication</span><span>.</span><span>HashPasswordForStoringInConfigFile</span><span>(</span><span>key </span><span>+ </span><span>url</span><span>, </span><span>"md5"</span><span>);<br> <br>             </span><span>string</span><span>[] </span><span>resUrl </span><span>= new </span><span>string</span><span>[</span><span>4</span><span>]; <br> <br>             for (</span><span>int i </span><span>= </span><span>0</span><span>; </span><span>i </span><span><span>4</span><span>; </span><span>i</span><span>++) <br>             { <br>                 </span><span>//把加密字符按照8位一组16进制与0x3FFFFFFF进行位与运算 <br>                 </span><span>int hexint </span><span>= </span><span>0x3FFFFFFF </span><span>& </span><span>Convert</span><span>.</span><span>ToInt32</span><span>(</span><span>"0x" </span><span>+ </span><span>hex</span><span>.</span><span>Substring</span><span>(</span><span>i </span><span>* </span><span>8</span><span>, </span><span>8</span><span>), </span><span>16</span><span>); <br>                 </span><span>string outChars </span><span>= </span><span>string</span><span>.Empty; <br>                 for (</span><span>int j </span><span>= </span><span>0</span><span>; </span><span>j </span><span><span>6</span><span>; </span><span>j</span><span>++) <br>                 { <br>                     </span><span>//把得到的值与0x0000003D进行位与运算,取得字符数组chars索引 <br>                     </span><span>int index </span><span>= </span><span>0x0000003D </span><span>& </span><span>hexint</span><span>; <br>                     </span><span>//把取得的字符相加 <br>                     </span><span>outChars </span><span>+= </span><span>chars</span><span>[</span><span>index</span><span>]; <br>                     </span><span>//每次循环按位右移5位 <br>                     </span><span>hexint </span><span>= </span><span>hexint </span><span>>> </span><span>5</span><span>; <br>                 } <br>                 </span><span>//把字符串存入对应索引的输出数组 <br>                 </span><span>resUrl</span><span>[</span><span>i</span><span>] = </span><span>outChars</span><span>; <br>             } <br> <br>             return </span><span>resUrl</span><span>; <br>         } <br> </span><span>?></span> </span></span></span>

高进制数字转换,使用六十二进制将十进制数字变“短”。(作者自称很高效,但是来源页www.zoeey.com/cnphpdocs/short.url.radix.convert.html 打不开)
例如数据库中第 56800235583 条信息,对应的短网址后缀可以是 ZZZZZZ 。
下面是存储示例:

<span><span><?php <br> </span><span>//id 自增序列/自增编号 <br> //url 目标链接 <br> //*suffix* 短网址后缀 (并不需要存储在数据库内) <br> </span><span>+------------+-----------------------+---------+ <br> |</span><span>id          </span><span>| </span><span>url                   </span><span>| *</span><span>suffix</span><span>*| <br> +------------+-----------------------+---------+ <br> |</span><span>123456      </span><span>| </span><span>http</span><span>:</span><span>//zoeey.com/     | w7e     | <br> </span><span>+------------+-----------------------+---------+ <br> |</span><span>123457      </span><span>| </span><span>http</span><span>:</span><span>//www.zoeey.com/ | w7f     | <br> </span><span>+------------+-----------------------+---------+ <br> |</span><span>56800235582 </span><span>| </span><span>http</span><span>:</span><span>//zoeey.org/     | ZZZZZY  | <br> </span><span>+------------+-----------------------+---------+ <br> |</span><span>56800235583 </span><span>| </span><span>http</span><span>:</span><span>//www.zoeey.org/ | ZZZZZZ  | <br> </span><span>+------------+-----------------------+---------+ <br> </span><span>?></span> </span>
短网址使用流程:

  • 提交网址存储后获取其编号 如:123456
  • 用dec2Any将编号转换为62进制,并拼接网址 如:http://go.to/w7e
  • 用户访问到 http://go.to/w7e 时,提取短网址后缀 w7e
  • 用any2Dec将短网址后缀转换为10进制,得到链接编号 如:123456
  • 使用编号查询链接,并进行跳转[/list]


下面是进制转换所需要的源码:
<span><span><?php <br> </span><span>/* <br> * MoXie (SysTem128@GMail.Com) 2010-6-30 17:53:57 <br> *  <br> * Copyright © 2008-2010 Zoeey.Org . All rights are reserved. <br> * Code license: Apache License  Version 2.0 <br> * http://www.apache.org/licenses/LICENSE-2.0.txt <br> */ <br> </span><span>error_reporting</span><span>(</span><span>E_ALL</span><span>); <br> <br> </span><span>/** <br> * 返回一字符串,十进制 number 以 radix 进制的表示。 <br> * @param dec       需要转换的数字 <br> * @param toRadix    输出进制。当不在转换范围内时,此参数会被设定为 2,以便及时发现。 <br> * @return    指定输出进制的数字 <br> */ <br> </span><span>function </span><span>dec2Any</span><span>(</span><span>$dec</span><span>, </span><span>$toRadix</span><span>) { <br>     </span><span>$MIN_RADIX </span><span>= </span><span>2</span><span>; <br>     </span><span>$MAX_RADIX </span><span>= </span><span>62</span><span>; <br>     </span><span>$num62 </span><span>= </span><span>'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span><span>; <br>     if (</span><span>$toRadix </span><span><span>$MIN_RADIX </span><span>|| </span><span>$toRadix </span><span>> </span><span>$MAX_RADIX</span><span>) { <br>         </span><span>$toRadix </span><span>= </span><span>2</span><span>; <br>     } <br>     if (</span><span>$toRadix </span><span>== </span><span>10</span><span>) { <br>         return </span><span>$dec</span><span>; <br>     } <br>     </span><span>// -Long.MIN_VALUE 转换为 2 进制时长度为65 <br>     </span><span>$buf </span><span>= array(); <br>     </span><span>$charPos </span><span>= </span><span>64</span><span>; <br>     </span><span>$isNegative </span><span>= </span><span>$dec </span><span><span>0</span><span>; </span><span>//(bccomp($dec, 0)      </span><span>if (!</span><span>$isNegative</span><span>) { <br>         </span><span>$dec </span><span>= -</span><span>$dec</span><span>; </span><span>// bcsub(0, $dec); <br>     </span><span>} <br> <br>     while (</span><span>bccomp</span><span>(</span><span>$dec</span><span>, -</span><span>$toRadix</span><span>) <span>0</span><span>) { <br>         </span><span>$buf</span><span>[</span><span>$charPos</span><span>--] = </span><span>$num62</span><span>[-</span><span>bcmod</span><span>(</span><span>$dec</span><span>, </span><span>$toRadix</span><span>)]; <br>         </span><span>$dec </span><span>= </span><span>bcdiv</span><span>(</span><span>$dec</span><span>, </span><span>$toRadix</span><span>); <br>     } <br>     </span><span>$buf</span><span>[</span><span>$charPos</span><span>] = </span><span>$num62</span><span>[-</span><span>$dec</span><span>]; <br>     if (</span><span>$isNegative</span><span>) { <br>         </span><span>$buf</span><span>[--</span><span>$charPos</span><span>] = </span><span>'-'</span><span>; <br>     } <br>     </span><span>$_any </span><span>= </span><span>''</span><span>; <br>     for (</span><span>$i </span><span>= </span><span>$charPos</span><span>; </span><span>$i </span><span><span>65</span><span>; </span><span>$i</span><span>++) { <br>         </span><span>$_any </span><span>.= </span><span>$buf</span><span>[</span><span>$i</span><span>]; <br>     } <br>     return </span><span>$_any</span><span>; <br> } <br> <br> </span><span>/** <br> * 返回一字符串,包含 number 以 10 进制的表示。<br> <br> * fromBase 只能在 2 和 62 之间(包括 2 和 62)。 <br> * @param number    输入数字 <br> * @param fromRadix    输入进制 <br> * @return  十进制数字 <br> */ <br> </span><span>function </span><span>any2Dec</span><span>(</span><span>$number</span><span>, </span><span>$fromRadix</span><span>) { <br>     </span><span>$num62 </span><span>= </span><span>'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span><span>; <br>     </span><span>$dec </span><span>= </span><span>0</span><span>; <br>     </span><span>$digitValue </span><span>= </span><span>0</span><span>; <br>     </span><span>$len </span><span>= </span><span>strlen</span><span>(</span><span>$number</span><span>) - </span><span>1</span><span>; <br>     for (</span><span>$t </span><span>= </span><span>0</span><span>; </span><span>$t </span><span><span>$len</span><span>; </span><span>$t</span><span>++) { <br>         </span><span>$digitValue </span><span>= </span><span>strpos</span><span>(</span><span>$num62</span><span>, </span><span>$number</span><span>[</span><span>$t</span><span>]); <br>         </span><span>$dec </span><span>= </span><span>bcadd</span><span>(</span><span>bcmul</span><span>(</span><span>$dec</span><span>, </span><span>$fromRadix</span><span>), </span><span>$digitValue</span><span>); <br>     } <br>     return </span><span>$dec</span><span>; <br> } <br> <br> </span><span>$sol </span><span>= </span><span>'<br>' </span><span>. </span><span>PHP_EOL</span><span>; <br> echo </span><span>dec2Any</span><span>(</span><span>'56800235583'</span><span>, </span><span>62</span><span>), </span><span>$sol</span><span>; </span><span>// ZZZZZZ <br> </span><span>echo </span><span>any2Dec</span><span>(</span><span>'ZZZZZZ'</span><span>, </span><span>62</span><span>), </span><span>$sol</span><span>; </span><span>// 56800235583 <br> </span><span>echo </span><span>dec2Any</span><span>(</span><span>'123456'</span><span>, </span><span>62</span><span>), </span><span>$sol</span><span>; </span><span>// w7e <br> </span><span>echo </span><span>any2Dec</span><span>(</span><span>'w7e'</span><span>, </span><span>62</span><span>), </span><span>$sol</span><span>; </span><span>// 123456 <br> </span><span>?></span></span></span></span></span></span></span>

另外,介绍一下goo.gl接口api的应用.
据说此算法是各种短网址服务中 "......(这是)互联网上最稳定、最安全、最快速的短网址服务。"(google声称)

有人做了比较,证明确实如此。



除了速度快,goo.gl还提供详细的点击统计。比如,Yahoo首页的短网址是http://goo.gl/QuXj,那么它的统计数据就在http://goo.gl/info/QuXj。加上后缀".qr",还能得到这个网址的二维条形码,Yahoo的就是http://goo.gl/QuXj.qr。

详细信息可从这查看:http://code.google.com/apis/urlshortener/overview.html

下面是http://www.biaodianfu.com/php-google-urlshortener-api.html弄的一个简单的PHP调用API生成短网址方法,分享给大家。
在使用前,请先到这里申请API Key:http://code.google.com/apis/console/
短网址的生成需要使用POST提交数据,所以使用了curl,短网址的还原可以直接使用file_get_contents()函数。不过为了统一,也使用了curl来处理哈。
<span><span><?php <br> </span><span>// 生成 <br> </span><span>function </span><span>shortenGoogleUrl</span><span>(</span><span>$long_url</span><span>){ <br>  </span><span>$apiKey </span><span>= </span><span>'API-KEY'</span><span>; </span><span>//Get API key from : http://code.google.com/apis/console/ <br>  </span><span>$postData </span><span>= array(</span><span>'longUrl' </span><span>=> </span><span>$long_url</span><span>, </span><span>'key' </span><span>=> </span><span>$apiKey</span><span>); <br>  </span><span>$jsonData </span><span>= </span><span>json_encode</span><span>(</span><span>$postData</span><span>); <br>  </span><span>$curlObj </span><span>= </span><span>curl_init</span><span>(); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_URL</span><span>, </span><span>'https://www.googleapis.com/urlshortener/v1/url'</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_RETURNTRANSFER</span><span>, </span><span>1</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_SSL_VERIFYPEER</span><span>, </span><span>0</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_HEADER</span><span>, </span><span>0</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_HTTPHEADER</span><span>, array(</span><span>'Content-type:application/json'</span><span>)); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_POST</span><span>, </span><span>1</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_POSTFIELDS</span><span>, </span><span>$jsonData</span><span>); <br>  </span><span>$response </span><span>= </span><span>curl_exec</span><span>(</span><span>$curlObj</span><span>); <br>  </span><span>curl_close</span><span>(</span><span>$curlObj</span><span>); <br>  </span><span>$json </span><span>= </span><span>json_decode</span><span>(</span><span>$response</span><span>); <br>  return </span><span>$json</span><span>-></span><span>id</span><span>; <br> } <br> <br> </span><span>//还原 <br> </span><span>function </span><span>expandGoogleUrl</span><span>(</span><span>$short_url</span><span>){ <br>  </span><span>$curlObj </span><span>= </span><span>curl_init</span><span>(); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_URL</span><span>, </span><span>'https://www.googleapis.com/urlshortener/v1/url?shortUrl='</span><span>.</span><span>$short_url</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_HEADER</span><span>, </span><span>0</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_RETURNTRANSFER</span><span>, </span><span>1</span><span>); <br>  </span><span>curl_setopt</span><span>(</span><span>$curlObj</span><span>, </span><span>CURLOPT_SSL_VERIFYPEER</span><span>, </span><span>0</span><span>); <br>  </span><span>$response </span><span>= </span><span>curl_exec</span><span>(</span><span>$curlObj</span><span>); <br>  </span><span>curl_close</span><span>(</span><span>$curlObj</span><span>); <br>  </span><span>$json </span><span>= </span><span>json_decode</span><span>(</span><span>$response</span><span>); <br>  return </span><span>$json</span><span>-></span><span>longUrl</span><span>; <br> } <br> </span><span>?></span> </span>
在此处有个生成器,但是无代码奉献.点击此处

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!