I am new in bitcoin. I am developing a PHP website to let users build their wallet on my website. I want to give every user a wallet. I do not want to give users private keys. I keep private keys, so all their bitcoins owns mine. If everyone wants to spend his/her bitcoins, he/she needs to send a withdrawal request and I will handle it. I want to be able to send user's bitcoin at once with one transaction and one fee. So if I give every user a new address, bitcoins will be a changeed (a little amount in every address). So spending them needs lots of fee. What should I do? I am using blockcypher's API. Is there any other API can help? What senario should I do to achieve all above targets? thanks.
You'd have to get creative here.
Step 1) Get unspent outputs. https://bullpay.com/docs#GetUnspentOutputs You can build your unspent outputs from multiple wallets. As long as you have the private keys, it can be done. Step 2) Build your signed transaction. https://medium.com/coinmonks/how-to-create-a-raw-bitcoin-transaction-step-by-step-239b888e87f2 Step 3) Send your signed transaction. https://bullpay.com/docs#SendTransaction or use a node.
The part you'll want to repeat is in step 2. Building out the inputs each using their own private keys. The tricky part here is waiting long enough to have multiple outputs to warrant going through all this.