<?php
namespace lib;

class PayUtils {

	/**
	 * Ԫأա=ֵģʽá&ַƴӳַ
	 * @param $para Ҫƴӵ
	 * return ƴԺַ
	 */
	static public function createLinkstring($para) {
		$arg  = "";
		foreach ($para as $key=>$val) {
			$arg.=$key."=".$val."&";
		}
		//ȥһ&ַ
		$arg = substr($arg,0,-1);

		return $arg;
	}
	/**
	 * Ԫأա=ֵģʽá&ַƴӳַַurlencode
	 * @param $para Ҫƴӵ
	 * return ƴԺַ
	 */
	static public function createLinkstringUrlencode($para) {
		$arg  = "";
		foreach ($para as $key=>$val) {
			$arg.=$key."=".urlencode($val)."&";
		}
		//ȥһ&ַ
		$arg = substr($arg,0,-1);

		return $arg;
	}
	/**
	 * ȥеĿֵǩ
	 * @param $para ǩ
	 * return ȥֵǩǩ
	 */
	static public function paraFilter($para) {
		$para_filter = array();
		foreach ($para as $key=>$val) {
			if($key == "sign" || $key == "sign_type" || $val == "")continue;
			else $para_filter[$key] = $para[$key];
		}
		return $para_filter;
	}
	/**
	 * 
	 * @param $para ǰ
	 * return 
	 */
	static public function argSort($para) {
		ksort($para);
		reset($para);
		return $para;
	}
	/**
	 * ǩַ
	 * @param $prestr Ҫǩַ
	 * @param $key ˽Կ
	 * return ǩ
	 */
	static public function md5Sign($prestr, $key) {
		$prestr = $prestr . $key;
		return md5($prestr);
	}

	/**
	 * ֤ǩ
	 * @param $prestr Ҫǩַ
	 * @param $sign ǩ
	 * @param $key ˽Կ
	 * return ǩ
	 */
	static public function md5Verify($prestr, $sign, $key) {
		$prestr = $prestr . $key;
		$mysgin = md5($prestr);

		if($mysgin == $sign) {
			return true;
		}
		else {
			return false;
		}
	}
}
