| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | <?php/*  * Desc : Action Transform class *  * Author: huchunmei */class Transform{			public function __construct(){}		/*			游戏币转美元,美元转当地金额		$game_currency,游戏币		$game_rate,游戏币与美元之间的汇率		$local_money,当地的货币代码	*/	public static function transform($game_currency,$game_rate,$local_money){		$money = $game_currency*$game_rate;//把游戏币转换成美元		$rate = Transform::fromUSD('USD',$local_money);//获得该货币对应的美元汇率		$transform_money = $money*$rate;		return $transform_money;					}				//实时汇率函数	public static function fromUSD($from='USD',$to='CHY'){		if($from&&$to){				$url="http://download.finance.yahoo.com/d/quotes.html?s=$from$to=X&f=sl1d1t1ba&e=.html";				$contents=Transform::_link($url);				$contents=str_replace("\"","",str_replace("/","-",$contents));				$list=explode(",",$contents);				return $list[1];//$list[1]就是当前汇率		}		exit;	}	public static function _link($url){		$ch = curl_init();		$timeout = 5;		curl_setopt ($ch, CURLOPT_URL, "$url");		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);		curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);		$contents = curl_exec($ch);		curl_close($ch);		if($contents=="Forbidden" || empty($contents)){			$contents = @file_get_contents("$url");		}		return $contents;	}}
 |