I'm so sorry to hear that your cat is very sick and has leg spasms that cause great pain.
It's possible that he has a cardiac condition called feline cardiomyopathy, which can cause a blood clot to lodge in the main artery carrying blood to the hind legs. This is very painful and can also cause paralysis. Here is more information:
It's also possible that these spasms are related to a nutritional deficiency or muscle or nerve problem, so it would be best to have him evaluated in person asap, at an ER vet center, where he can be diagnosed and treated for the pain. Once you know the cause of the problem, you will be referred to a veterinary specialist who will be able to help, further.
I'd advise getting him seen today, at an ER vet center, if your regular vet doesn't have weekend hours.
Unfortunately, there is not much to do at home for these symptoms; they must first be diagnosed and the underlying cause, determined.
I hope all will be well with your furry boy!
Please take a moment to Rate my answer, so the site knows I have been of assistance. Thank you very much!