That part was a legit message from O2, it's the security code to use to access things like your account. If you give this code to the scammers they can access your account and buy phones on your card.
Never give out that code over the phone, O2 won't ask for it.