SMSServiceの例

LANSA Integrator

SMSServiceの例


      *************************************************

      * SMS:     Example in RPG ILE of using the LANSA Integrator

      *          SMSService.

      *          This example uses the SMTP (email) protocol to send the

      *          SMS details to the SMS gateway.

      *          You need to check:

      *          - The SMS gateway you are using accepts SMS messages

      *            for transmission in an email format.

      *          - The format of the email sent agrees with the format

      *            expected by your SMS gateway.

      *

      * Note:    This is an example program containing only

      *          rudimentary exception handling

      *

      * To create this program you must execute the following commands,

      * supplying the indicated parameter values and any others that are

      * necessary in your installation:

      *

      *   CRTRPGMOD MODULE(<modlib>/SMS)

      *             SRCFILE(<srclib>/<srcfil>)

      *

      *   CRTPGM    PGM(<pgmlib>/SMS)

      *             MODULE(<modlib>/SMS)

      *             BNDSRVPGM(<lansalib>/DCXS882X)

      *             ACTGRP(*CALLER)

      *************************************************

      * To successfully run this example you will need an SMTP (email)

      * server and an SMS gateway.

      * These need to be set up in the SMSService.properties file.

      * For example:

      *    transport=smtp

      *    port=25

      *    server=10.2.0.55

      *    subject=user+password

      *    [email protected]

      *    mail.domain=yourcoy.com.au

      *    mobile.domain=streetdata.com.au

      *************************************************

       * You must replace the value of the following constants

      * before compiling and running this example

       *    phoneno value needs to be replaced with mobile phone number to

      *    which the SMS message will be sent.

     d phoneno         c                   '+61412345678'

       *    message value can be replaced with the text of the

      *    SMS message

     d message         c                   'Hello. Test message'

       *    emailfrom value needs to be replaced with the email addressee

      *    which will be used on the SMTP (email) sent to the SMS gateway.

     d emailfrom       c                   '[email protected]'

       *************************************************

      *

      * Declare variables for the JSM calls

      d jsmsrv          s             50a   inz(*blanks)

     d jsmsts          s             20a   inz(*blanks)

     d jsmmsg          s            255a   inz(*blanks)

     d jsmcmd          s            255a   inz(*blanks)

     d bytelength      s             10i 0 inz(*zero)

       * Completion messages

      d CompMsg01       c                   'JSMOPEN call completed.'

     d CompMsg02       c                   '  SERVICE_LOAD call completed.'

     d CompMsg11       c                   '  SET ENCODING call completed.'

     d CompMsg12       c                   '  SET FROM call completed.'

     d CompMsg20       c                   '  SEND call completed.'

     d CompMsg98       c                   '  SERVICE_UNLOAD call completed.'

     d CompMsg99       c                   'JSMCLOSE call completed.'

       * Procedure prototypes

      d CheckResult     pr

     d  crjsts                             const like(jsmsts)

     d  crjmsg                             const like(jsmmsg)

      d SendMessage     pr

     d  smText                      512a   VALUE

     d  smType                       10a   VALUE

       * Prototypes for the JSM calls

       /COPY QRPGLESRC,JSM_PROC.H

       *************************************************

      * Open a connection to the default JSM server

      * - because the server parameter is blank, details of the default

      *   JSM server are obtained from the data area JSMCLTDTA on IBM i

      *   or from the file jsmcltdta.txt on other supported platforms

      c                   callp     p_jsmopen(jsmsrv:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg01:'*COMP')

       * Load the SMSService

      * This loads and ititializes the service using the values defined in

      *   the SMSService.properties file.

      * This example explicitly turns tracing on.

      c                   eval      jsmcmd = 'SERVICE_LOAD'

     c                             + ' SERVICE(SMSSERVICE) TRACE(*YES)'

     c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg02:'*COMP')

      *

       * Examples of SET command

      * The SET command may be used to override any defaults that are

      *    defined in the SMSService.properties file.

       *    Set the encoding value

     c                   eval      jsmcmd = 'SET'

     c                                      + ' ENCODING(ISO8859_1)'

     c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg11:'*COMP')

       *    Set the SMTP (email) FROM value.

      *      The FROM value will be used when sending the email

      *      to the SMS gateway.

     c                   eval      jsmcmd = 'SET'

     c                                      + ' FROM(' + emailfrom + ')'

     c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg12:'*COMP')

       * SEND the message

      c                   eval      jsmcmd = 'SEND'

     c                                      + ' TO(' + phoneno

     c                                      + ') MSG(' + message + ')'

     c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg20:'*COMP')

       * Unload the SMSService

      c                   eval      jsmcmd = 'SERVICE_UNLOAD'

     c                   callp     p_jsmcmd(jsmcmd:jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg98:'*COMP')

       * Close the connection to the JSM server and finish

      c                   callp     p_jsmclose(jsmsts:jsmmsg)

     c                   callp     CheckResult(jsmsts:jsmmsg)

     c                   callp     SendMessage(CompMsg99:'*COMP')

     c                   eval      *inlr = *on

     c                   return

       *************************************************

      * Procedure to check the result of a Java Service Manager call

      *************************************************

     p CheckResult     b

     d CheckResult     pi

     d  crjsts                             const like(jsmsts)

     d  crjmsg                             const like(jsmmsg)

     d  crText         s            512a

     d  crMsg1         c                   const('JSM Status : ')

     d  crMsg2         c                   const('JSM Message: ')

     d  crMsg3         c                   const('JSM Service error has +

     d                                            occurred')

     c                   if        crjsts <> 'OK'

     c                   eval      crText = crMsg1 + crjsts

     c                   callp     SendMessage(crText:'*DIAG')

     c                   eval      crText = crMsg2 + crjmsg

     c                   callp     SendMessage(crText:'*DIAG')

     c                   callp     SendMessage(crMsg3:'*ESCAPE')

     c                   endif

     p CheckResult     e

       *************************************************

      * Procedure to send a program message

      *************************************************

     p SendMessage     b

      d SendMessage     pi

     d smText                       512a   VALUE

     d smMsgT                        10a   VALUE

      d smMsgI          s              7a   inz('CPF9897')

     d smMsgF          s             20a   inz('QCPFMSG   *LIBL     ')

     d smDtaL          s             10i 0 inz(%size(smText))

     d smStkE          s             10a   inz('*')

     d smStkC          s             10i 0 inz(1)

     d smMsgK          s              4a

     d smErrC          s             10i 0 inz(0)

      c                   if        smMsgT = '*ESCAPE'

     c                   eval      smMsgI = 'CPF9898'

     c                   endif

      c                   call      'QMHSNDPM'

     c                   parm                    smMsgI

     c                   parm                    smMsgF

     c                   parm                    smText

     c                   parm                    smDtaL

     c                   parm                    smMsgT

     c                   parm                    smStkE

     c                   parm                    smStkC

     c                   parm                    smMsgK

     c                   parm                    smErrC

      p                 e