<?php

namespace WebPlugin\Pay;

/**
 * 接口签名
 */
class Signature
{
    /**
     * 排序参数
     * @param array $package
     * @return array
     */
    static function packageSort(array $package)
    {
        ksort($package);
        reset($package);
        return $package;
    }

    /**
     * 组合签名
     * @param array $package
     * @return string
     */
    static function makeSign(array $package)
    {
        $packageList = array();
        foreach ($package as $key => $val) {
            $packageList[] = trim($key . '=' . $val);
        }
        return strtolower(md5(implode('&', $packageList)));
    }

    /**
     * 校验签名
     * @param $submitSign
     * @param $makeSign
     * @return bool
     */
    static function verifySign($submitSign, $makeSign)
    {
        return strtolower($submitSign) == strtolower($makeSign);
    }
}