I have the same problem on a Macbook Pro where imessages worked before. iCloud Preferences told me that my security had been compromised (no other explanation like location of suspicious logins or devices etc.) and that I had to change my iCloud password. That's when the problems started. I've sorted out all the other problems with my devices logging into iCloud services. But not FaceTime and Messages on the MBP.
I've followed the steps in the second link (except for waiting 24 hours). I've also tried logging out of iCloud in System Prefs and back in.
Then I tried generating an app-specific password as per the first link (that page by the way advises that this is for apps and services not provided by Apple) that didn't work either. So I turned off two-factor authentication. It still doesn't work!
Next step I'm investigating uninstalling Messages and reinstalling - unlikely to work if other Apple apps are anything to go by. Will repost here when the problem's solved, but meantime if anyone has anything that's worked when the above steps have failed, I'd appreciate your tips.