Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package im.actor.server.sms
- import java.net.URLEncoder
- import akka.actor.ActorSystem
- import akka.http.scaladsl.Http
- import akka.http.scaladsl.model._
- import com.typesafe.config.Config
- import akka.stream.Materializer
- import scala.concurrent.Future
- final class MyOwnClient(config: Config)(implicit system: ActorSystem, materializer: Materializer) extends SmsEngine {
- val defaultSmsTemplate: String = "Your MIM Activation code is : "
- private val url = "http://xxx.com/magfaHttpService"
- private val service = config.getString("service")
- private val domain = config.getString("domain")
- private val username = config.getString("username")
- private val password = config.getString("password")
- private val from = config.getString("from")
- override def send(phoneNumber: Long, message: String): Future[Unit] = {
- val http = Http()
- val req = url + "?service=" + service + "&domain=" + domain + "&username=" + username +
- "&password=" + password + "&from=" + from + "&to=" + phoneNumber.toString +
- "&message=" + URLEncoder.encode(defaultSmsTemplate + message, "ISO-8859-1")
- val f = http.singleRequest(HttpRequest(uri = req)) map {
- case HttpResponse(StatusCodes.OK, _, _, _) ⇒ ()
- case resp ⇒
- throw new Exception(s"Wrong response: $resp")
- }
- f onFailure {
- case e ⇒
- system.log.error(e, "Failed to send sms through Magfa")
- }
- f
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement