More to the point (and less reading to find it):
direct object pronouns: http://italian.about.com/library/fare/blfare116a.htm
indirect object pronouns: http://italian.about.com/library/fare/blfare117a.htm
Well, not exactly. "In modern Italian, dative gli (to him) is used commonly even as plural (to them) instead of classical loro. So: "Conosci Luca: gli ho sempre detto di stare lontano dalle cattive compagnie" (You know Luca: I have always told him to stay away from bad companies"). And: "Conosci Luca e Gino: gli ho sempre detto..." (...I have always told them...) instead of "... ho sempre detto loro di stare..."."
The key to figuring out this sentence is flipping around the parts like you would in English.
Word for word, this sentence is translated as "For him, we buy a bottle of wine", or to put it in a more common English style, "We buy a bottle of wine for him".
gli is either going to be "To him" or "For him". Not just plain "him", because that would be "lo", not "gli". Meanwhile, in plural, "gli" or "loro" both mean "to them" or "For them", not just plain "them"-- which is the direct pronoun, "li" (or "le" for feminine plural).
Bringing it back to English, you wouldn't ever say, "We buy a bottle of wine him", or "Him we buy a bottle of wine". You'd add the word "For" in front of him, of course. And the nice charts around, showing the indirect pronouns, tell us that , when used indirectly, "gli" means "to/ for him" or "to/for them".
So gli compriamo= "We buy (for) him" OR "We buy (for) them", and li compriamo = "we buy them".
So while "gli" can be any of "To him", "For him" "To them", "For them", you need some outside context for the sentence to decide if you are buying for a single male person or if you are buying for a group.
"lo vedo" = "I see him", (not "to him I see") and "li vedo" = "I see them" (not "to them I see").
There are certain verbs, like "buy", "give" and "talk" that imply that a preposition is wanted ("to"/ "for"), so watch the verbs for clues, too.
And, of course, watch out for the dreaded "piacere" (to like/ to be pleased by) as well as "mancare" (to miss/ to be missed by) since both of those verbs work with indirect objects as the first component in a sentence (and there are others, too).
See how easy it is??
(I got this sentence correct, at my skill level 24, but clitics are something that I practice almost every day. They can still mess me up and this is one of the most essential units that you'll need to know going forward, I'm afraid!)
I tried to explain in a previous post, above. Basically, you'd use "gli" with the verb "to buy" if you you buying for a single male person or for a group, and "li" with the verb "to buy" only if you were buying the actual objects ("them").
In English, "we buy him a flower" or "we buy them some flowers", OR "we buy them" (them being the actual flowers, not for a person or group), which is where you use "li" instead of "gli".
As for hearing the difference, it is nearly impossible until your ear is trained to hear it, or unless the speaker speaks slowly or if you know the entire background of the conversation and it is apparent what the speaker is refering to.
A sentence translated out of context is usually going to confuse.
As "LatecomerLaurie" rightfully says, "Gli" has a "y" sound in it, so it sort-of sounds sloppier than "Li".
L-yee versus Lee : it's very subtle.