Created
November 18, 2015 06:59
-
-
Save tormaroe/188306ca71c941ee0739 to your computer and use it in GitHub Desktop.
A simple Common Lisp package to send text using LINK Mobility SMS gateway.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :cl-user) | |
(defpackage :sms | |
(:documentation | |
"A simple package to send SMS using LINK Mobility") | |
(:use :cl) | |
(:import-from :drakma :http-request) | |
(:import-from :cl-who :with-html-output-to-string :str :esc) | |
(:export :<gateway> | |
:send-sms)) | |
(in-package :sms) | |
(defclass <gateway> () | |
((url :accessor gateway-url :initarg :url | |
:initform "https://xml.pswin.com/") | |
(user :accessor gateway-user :initarg :user) | |
(pw :accessor gateway-password :initarg :password) | |
(sender :accessor gateway-sender :initarg :sender))) | |
(setf cl-who:*downcase-tokens-p* nil) | |
(defun make-XML (gateway rcv text) | |
(with-html-output-to-string (s) | |
(format s "<?xml version=\"1.0\"?>") | |
(:SESSION | |
(:CLIENT (str (gateway-user gateway))) | |
(:PW (str (gateway-password gateway))) | |
(:MSGLST | |
(:MSG | |
(:ID (str 1)) | |
(:SND (str (gateway-sender gateway))) | |
(:RCV (str rcv)) | |
(:TEXT (esc text))))))) | |
(defun send-sms (gateway rcv text) | |
(http-request (gateway-url gateway) | |
:method :post | |
:content (make-XML gateway rcv text) | |
:content-type "text/xml charset=ISO-8859-1")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload :drakma) | |
(ql:quickload :cl-who) | |
(load "sms") | |
(defvar *connection* (make-instance 'sms:<gateway> | |
:user "some user" | |
:password "some password" | |
:sender "SomeSender")) | |
(sms:send-sms *connection* | |
"4700000001" | |
"Some message text, may include <>&æøå etc.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment