验证18位身份编码是否合法

@param int $idCard 身份编码
@return boolean 是否合法
964829
public function validateIdCard($idCard)
    {
        if (strlen($idCard) == 18) {
            // 前17位
            $code17 = substr($idCard, 0, 17);
            // 第18位
            $code18 = substr($idCard, 17, 1);
            if (is_numeric($code17)) {
                $iArr = str_split($code17);
                if ($iArr != null) {
                    $iSum17 = $this->getPowerSum($iArr);
                    // 获取校验位
                    $val = $this->getCheckCode18($iSum17);
                    if (strlen($val) > 0 && $val == $code18) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
416909
public function isAncestor(int $id): Bool
    {
        if ( ! is_null($this->getAncestor($id))) {
            return true;
        }

        return false;
    }
994656
public function deleteById($id) : int
    {
        $sql = 'DELETE FROM `' . $this->table . '` WHERE ';

        // Assign ids
        if (is_array($id)) {
            $i = 0;
            foreach ($id as $_id) {
                if ($i === 0) {
                    $sql .= ' id=:id' . $i;
                } else {
                    $sql .= ' OR id=:id' . $i;
                }
                $i++;
            }
            $query = $this->pdo->prepare($sql);
            for ($j = 0; $j < 0; $j++) {
                $query->bindParam(':id' . $j, $id[$j]);
            }
        } else {
            $sql .= 'id=:id';
            $query = $this->pdo->prepare($sql);
            $query->bindParam(':id', $id);
        }

        $query->execute();

        return $query->rowCount();
    }
1107008
public static String getBirth(String idCard) {
		final Integer len = idCard.length();
		if (len < CHINA_ID_MIN_LENGTH) {
			return null;
		} else if (len == CHINA_ID_MIN_LENGTH) {
			idCard = convert15To18(idCard);
		}
		return idCard.substring(6, 14);
	}
1075246
public function setCodeUnavailable($code, $card_id = null)
    {
        if (empty($code)) {
            return false;
        }
        $result = $this->httpRaw(static::WECHAT_SET_CARD_CODE_UNAVAILABLE_URL . 'access_token=' . $this->getAccessToken(), [
            'code' => $code,
            empty($card_id) && 'card_id' => $card_id
        ]);
        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? true : false;
    }
143507
public function deleteDepartment($id)
    {
        $result = $this->httpGet(self::WECHAT_DEPARTMENT_DELETE_PREFIX, [
            'access_token' => $this->getAccessToken(),
            'id' => $id
        ]);
        return isset($result['errcode']) && ($result['errcode'] ? $this->dump([$result,$this->getAccessToken()]) : !$result['errcode']);
    }
207175
public function delCategory($id)
    {
        $where = [];
        if (is_array($id)) {
            $where[] = ['id', 'IN', $id];
        } else {
            $id = (int)$id;
            if (is_numeric($id) && $id > 0) {
                $where[] = ['id', '=', $id];
            } else {
                throw new Exception('删除条件错误');
            }
        }

        if ($this->where($where)->delete() === false) {
            throw new Exception('删除权限分组出错');
        }
        return true;
    }
380107
public static String[] isValidCard10(String idCard) {
		if(StrUtil.isBlank(idCard)) {
			return null;
		}
		String[] info = new String[3];
		String card = idCard.replaceAll("[\\(|\\)]", "");
		if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) {
			return null;
		}
		if (idCard.matches("^[a-zA-Z][0-9]{9}$")) { // 台湾
			info[0] = "台湾";
			String char2 = idCard.substring(1, 2);
			if (char2.equals("1")) {
				info[1] = "M";
			} else if (char2.equals("2")) {
				info[1] = "F";
			} else {
				info[1] = "N";
				info[2] = "false";
				return info;
			}
			info[2] = isValidTWCard(idCard) ? "true" : "false";
		} else if (idCard.matches("^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?$")) { // 澳门
			info[0] = "澳门";
			info[1] = "N";
		} else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$")) { // 香港
			info[0] = "香港";
			info[1] = "N";
			info[2] = isValidHKCard(idCard) ? "true" : "false";
		} else {
			return null;
		}
		return info;
	}
1342468
public static function hasIdCard($string, &$matches = array(), $ifAll = false) {
		return 0 < self::validateByRegExp("/\d{17}[\d|X]|\d{15}/", $string, $matches, $ifAll);
	}
585828
public static function validate($creditCard)
    {
        if (trim($creditCard) === '') {
            return false;
        }

        if (!boolval(preg_match('/.*[1-9].*/', $creditCard))) {
            return false;
        }

        //longueur de la chaine $creditCard
        $length = strlen($creditCard);

        //resultat de l'addition de tous les chiffres
        $tot = 0;
        for ($i = $length - 1; $i >= 0; --$i) {
            $digit = substr($creditCard, $i, 1);

            if ((($length - $i) % 2) == 0) {
                $digit = (int) $digit * 2;
                if ($digit > 9) {
                    $digit = $digit - 9;
                }
            }
            $tot += (int) $digit;
        }

        return ($tot % 10) == 0;
    }
300817
public function codeGet($code, $check_consume = true, $card_id = '')
    {
        if (empty($code) || !is_bool($check_consume)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr = [];
        if (!empty($card_id)) {
            $queryStr['card_id'] = $card_id;
        }
        $queryStr['code']          = $code;
        $queryStr['check_consume'] = $check_consume;

        $this->apitype = 'card';
        $this->module  = 'code';
        $res           = $this->_post('get', $queryStr);

        return $res;
    }
907486
public function getdepositcount($card_id)
    {
        if (!is_string($card_id)) {
            $this->setError('参数错误');

            return false;
        }

        $queryStr            = [];
        $queryStr['card_id'] = $card_id;

        $this->apitype = 'card';
        $this->module  = 'code';
        $res           = $this->_post('getdepositcount', $queryStr);

        return $res;
    }
98140
public function getcardlist($openid, $card_id = '')
    {
        if (empty($openid)) {
            $this->setError('缺少openid');

            return false;
        }

        $queryStr           = [];
        $queryStr['openid'] = $openid;

        if (!empty($card_id)) {
            $queryStr['card_id'] = $card_id;
        }

        $this->apitype = 'card';
        $this->module  = 'user';
        $res           = $this->_post('getcardlist', $queryStr);

        return $res;
    }
650810
public function deleteById($id)
    {
        $this->validateTableAndIdentityColumn();
        // If the soft delete is activated
        if ($this->deleteColumnName) {
            $query = <<<EOQ
UPDATE {$this->getTableName()}
SET {$this->deleteColumnName} = 1
WHERE {$this->escapeCharacter}{$this->identityColumn}{$this->escapeCharacter} = %s
EOQ;
        } else {
            $query = <<<EOQ
DELETE FROM {$this->getTableName()}
WHERE {$this->escapeCharacter}{$this->identityColumn}{$this->escapeCharacter} = %s
EOQ;
        }

        $params = array('identity' => $id);

        return (bool)$this->db->query($query, $params);
    }
192084
public function updateCode($code, $card_id, $new_code)
    {
        if (empty($code) || empty($card_id) || $new_code) {
            return false;
        }

        $result = $this->httpPost(static::WECHAT_CARD_CODE_UPDATE_URL . 'access_token=' . $this->getAccessToken(), [
            'code' => $code,
            'card_id' => $card_id,
            'new_code' => $new_code
        ]);

        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? true : false;
    }
573210
public function cardNumber($value): bool
    {
        if (!is_string($value) || strlen($value) < 12) {
            return false;
        }

        $result = 0;
        $odd = strlen($value) % 2;
        preg_replace('/[^0-9]+/', '', $value);

        for ($i = 0; $i < strlen($value); ++$i) {
            $result += $odd
                ? $value[$i]
                : (($value[$i] * 2 > 9) ? $value[$i] * 2 - 9 : $value[$i] * 2);

            $odd = !$odd;
        }

        // Check validity.
        return ($result % 10 == 0) ? true : false;
    }
423801
public static boolean isValidCard(String idCard) {
		idCard = idCard.trim();
		int length = idCard.length();
		switch (length) {
		case 18:// 18位身份证
			return isvalidCard18(idCard);
		case 15:// 15位身份证
			return isvalidCard15(idCard);
		case 10: {// 10位身份证，港澳台地区
			String[] cardval = isValidCard10(idCard);
			if (null != cardval && cardval[2].equals("true")) {
				return true;
			} else {
				return false;
			}
		}
		default:
			return false;
		}
	}