<?php

namespace app\common\api;

/**
 * Description of JucaiApi
 *
 * @author sgq
 */
class JucaiApi {

    protected static $key = "rsKVyec52fqEKpk4RRD2TU8fKvPxt6ombKg0qSq1velPQtBHVi";

    public static function login($username, $password, $userType = 1) {
        $params["username"] = $username;
        $params["userType"] = $userType;
        $params["timestr"] = sprintf("%s", time());
        $md5 = self::checkSign($params);
        $params["password"] = $password;
        $params["sign"] = $md5;
        $res = curlPost("https://www.jucai.gov.cn/api/checkuser", $params);
        return $res;
    }

    private static function checkSign($params) {
        ksort($params);
        $signStr = "";
        foreach ($params as $key => $val) {
            if ($val) {
                $signStr .= trim($key) . "=" . trim($val) . "&";
            }
        }
        $signStr .= "key=" . self::$key;
        return strtoupper(md5($signStr));
    }

}
