How to get the canister identifier in the motoko code?

Indeed. See What is special about actor wrapper and this? - Motoko - #4 by ggreif.