Not sure if this answers your question:
How to get the Product link:
Context::getContext()->link->getProductLink( $id_product );
How to get the Category link:
Context::getContext()->link->getCategoryLink( $id_category );
Oh, actually I think now I understand what you're asking:
you want to change the URL structure, so you've gotta go to
Admin Office -> Preferences -> Seo & URLs -> scroll down to SCHEMA OF URLS
I have mine set to {category:/}{id}/{rewrite} so I get exactly what you want I believe