------
## 最终结论
```python
def numMagicSquaresInside(grid):
    def isMagic(grid, r, c):
        s = set()
        for i in range(3):
            for j in range(3):
                s.add(grid[r + i][c + j])
        if s != set(range(1, 10)):
            return False
        return (grid[r][c] + grid[r][c+1] + grid[r][c+2] == 15 and
                grid[r+1][c] + grid[r+1][c+1] + grid[r+1][c+2] == 15 and
                grid[r+2][c] + grid[r+2][c+1] + grid[r+2][c+2] == 15 and
                grid[r][c] + grid[r+1][c] + grid[r+2][c] == 15 and
                grid[r][c+1] + grid[r+1][c+1] + grid[r+2][c+1] == 15 and
                grid[r][c+2] + grid[r+1][c+2] + grid[r+2][c+2] == 15 and
                grid[r][c] + grid[r+1][c+1] + grid[r+2][c+2] == 15 and
                grid[r][c+2] + grid[r+1][c+1] + grid[r+2][c] == 15)

    rows, cols = len(grid), len(grid[0])
    count = 0

    for r in range(rows - 2):
        for c in range(cols - 2):
            if isMagic(grid, r, c):
                count += 1

    return count
```