Sp sms development-provision interface implementation-code of the forward order instance

Source: Internet
Author: User

Example code: myprovision. jsp, which is implemented in JSP mode.

<? XML version = "1.0" encoding = "UTF-8"?>
<% @ Page contenttype = "text/XML; charset = UTF-8" %>
<% @ Page import = "com. AAAA. Appn. *" %>
<% @ Page import = "Java. Io. *" %>
<% @ Page import = "org. JDOM. XPath. *" %> // Of course, you can use the XML data analysis library.
<% @ Page import = "org. JDOM. *" %>
<% @ Page import = "Java. util. *" %>
<%
// The user sends a custom or cancel command to the corresponding SP Special Service number through the mobile phone. After receiving the mo message, the gateway initiates a mo authentication request to Misc,
// After receiving the mo authentication price approval request, MISC orders and cancels matching of the VOD instruction;
// If the command is customized or canceled, MISC will send the subscription relationship synchronization request packet syncorderrelationreq to the SP.

Boolean resultstr = true;
String xmldata = NULL;
Stringbuffer tempstringbuffer = new stringbuffer ();
String tempstring = NULL;
Bufferedreader reader = request. getreader (); // receives the MISC subscription relationship synchronization request package syncorderrelationreq

While (tempstring = reader. Readline ())! = NULL ){
Tempstringbuffer. append (tempstring); // read the syncorderrelationreq content of the subscription synchronization request package.
}
Xmldata = tempstringbuffer. tostring (); // convert the syncorderrelationreq content of the subscription relationship synchronization request package to string and store it in xmldata

If (xmldata = NULL & xmldata. Length () <10 ){
Resultstr = false;
}
Tempstringbuffer. setlength (0); // clear tempstringbuffer
Tempstring = NULL;

// Out. println ("XML: =" + (xmldata. Equals ("")));

Org. JDOM. Input. saxbuilder sb = new org. JDOM. Input. saxbuilder ();
Org. JDOM. Document Doc = NULL;
// Xmldata is a non-empty character
If (xmldata. Equals ("")){
// Doc = sb. Build ("/home/web/provision. xml ");
Return;
} Else {
// Call the following functions to write the provision. xml and provision. log files.
Write ("/home/web/provision. xml", xmldata); // the local provision. XML is a temporary file;
Append ("/home/web/provision. log", xmldata); // provision. log is a record file for synchronizing information;
Doc = sb. Build ("/home/web/provision. xml"); // read the provision. xml file. The usage of Sb and Doc is not clear;
 
}
// The following describes how to read the information of provision. XML, interpret the definition of each part of the XML file, and read the value into the variable.
Org. JDOM. Element root = Doc. getrootelement ();
Element syncorderrelationreq = NULL;
Element send_address = NULL;
Element dest_address = NULL;
Element feeuser_id = NULL;
Element destuser_id = NULL;

String transactionid = NULL;
String msgtype = NULL;
String HRET = NULL;
String version = NULL;
//--------------------
String linkid = NULL;
String actionid = NULL;
String actionreasonid = NULL;
String spid = NULL;
String spserviceid = NULL;
String accessmode = NULL;
String featurestr = NULL;
//----------------------
String send_address_devicetype = NULL;
String send_address_deviceid = NULL;
String dest_address_devicetype = NULL;
String dest_address_deviceid = NULL;
String feeuser_id_useridtype = NULL;
String feeuser_id_msisdn = NULL;
String feeuser_id_pseudo docode = NULL;
String destuser_id_useridtype = NULL;
String destuser_id_msisdn = NULL;
String destuser_id_pseudo docode = NULL;
// Read the header information;
Element header = (element) XPath. selectsinglenode (root, "/SOAP-ENV: envelope/SOAP-ENV: Header ");
List NS = header. getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("transactionid ")){
Transactionid = E. gettextnormalize ();
}
}
}
// Read the body information;
Element body = (element) XPath. selectsinglenode (root, "/SOAP-ENV: envelope/SOAP-ENV: Body ");
NS = body. getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("syncorderrelationreq ")){
Syncorderrelationreq = E;
}
}
}

// All children who get data packets.
If (syncorderrelationreq! = NULL ){
NS = syncorderrelationreq. getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
//------------------------------------
If (E. getname (). Equals ("send_address ")){
Send_address = E;
}
If (E. getname (). Equals ("dest_address ")){
Dest_address = E;
}
If (E. getname (). Equals ("feeuser_id ")){
Feeuser_id = E;
}
If (E. getname (). Equals ("destuser_id ")){
Destuser_id = E;
}
//------------------------------------
If (E. getname (). Equals ("version ")){
Version = E. gettextnormalize ();
}
If (E. getname (). Equals ("msgtype ")){
Msgtype = E. gettextnormalize ();
}
If (E. getname (). Equals ("linkid ")){
Linkid = E. gettextnormalize ();
}
If (E. getname (). Equals ("actionid ")){
Actionid = E. gettextnormalize ();
}
If (E. getname (). Equals ("actionreasonid ")){
Actionreasonid = E. gettextnormalize ();
}
If (E. getname (). Equals ("spid ")){
Spid = E. gettextnormalize ();
}
If (E. getname (). Equals ("spserviceid ")){
Spserviceid = E. gettextnormalize ();
}
If (E. getname (). Equals ("accessmode ")){
Accessmode = E. gettextnormalize ();
}
If (E. getname (). Equals ("featurestr ")){
Featurestr = E. gettextnormalize ();
}
}
}
}

// Analyze the data packet

If (send_address! = NULL ){
NS = send_address.getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("devicetype ")){
Send_address_devicetype = E. gettextnormalize ();
}
If (E. getname (). Equals ("DeviceID ")){
Send_address_deviceid = E. gettextnormalize ();
}
}
}
}
If (dest_address! = NULL ){
NS = dest_address.getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("devicetype ")){
Dest_address_devicetype = E. gettextnormalize ();
}
If (E. getname (). Equals ("DeviceID ")){
Dest_address_deviceid = E. gettextnormalize ();
}
}
}
}
If (feeuser_id! = NULL ){
NS = feeuser_id.getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("useridtype ")){
Feeuser_id_useridtype = E. gettextnormalize ();
}
If (E. getname (). Equals ("msisdn ")){
Feeuser_id_msisdn = E. gettextnormalize ();
}
If (E. getname (). Equals ("pseudo code ")){
Feeuser_id_pseudo docode = E. gettextnormalize ();
}
}
}
}
If (destuser_id! = NULL ){
NS = destuser_id.getchildren ();
For (iterator I = NS. iterator (); I. hasnext ();){
Object n = I. Next ();
If (N instanceof element ){
Element E = (element) N;
If (E. getname (). Equals ("useridtype ")){
Destuser_id_useridtype = E. gettextnormalize ();
}
If (E. getname (). Equals ("msisdn ")){
Destuser_id_msisdn = E. gettextnormalize ();
}
If (E. getname (). Equals ("pseudo code ")){
Destuser_id_pseudo docode = E. gettextnormalize ();
}
}
}
}
// The above content is the soap xml field defined by mobile, which mainly interprets and reads data to variables.

// The following is the business logic part. Now it is written into JSP and can be directly transmitted to the business layer for business processing using Servlet and other methods.

// To add synchronous business information, you only need to modify the following code;
If (transactionid! = NULL & actionid! = NULL & destuser_id_msisdn! = NULL & spserviceid! = NULL ){
Sun. Misc. base64decoder B = new sun. Misc. base64decoder ();
Byte [] BB = B. decodebuffer (featurestr); // service order parameter (base64 encrypted). The content is a long number + space + content sent by the user, and is converted into byte using decodebase64decoder () []

String content = new string (BB, "gb2312"); // convert it to string;
String SQL _ = "insert into provision (content, actionid, provisiontime, msisdn, pserviceid) values ('" + content + "'," + actionid + ", now (), '"+ destuser_id_msisdn +"', '"+ spserviceid + "')";
Dbutil.exe (SQL _); // write the subscription information of provision to the data table; database write operation function
Content = content. Trim (). touppercase ();
Actionid = actionid. Trim (). touppercase ();
Spserviceid = spserviceid. Trim (). touppercase ();
 
Int userid = bizlogicutil. getuserid (destuser_id_msisdn );
// Analyze the user's synchronous subscription information and update the corresponding SP registration database table;
If (content. startswith ("AA ")){
Bizlogicutil. registeruser (userid, 3, 1, null );
Nvshservice. Register (userid); // register a dictionary user;
} Else if (content. startswith ("")){
Bizlogicutil. registeruser (userid, 2, 1, null );
// The code of the following three if statements indicates that, no matter whether the custom information sent by the user is "AA" or "A", you only need to synchronize the Business Code of the spserviceid of the order information,
// Actionid, service status management action code. The specific value is as follows:
// 1: Activate the service;
// 2: stop the service;
// 3: Activate the service;
// 4: suspend the service;

} Else if (spserviceid. startswith ("-test1") & actionid. startswith ("1 ")){
Bizlogicutil. registeruser (userid, 1, 1, null); // register a User Function
} Else if (spserviceid. startswith ("-Test2") & actionid. startswith ("2") {// stop the service;
Bizlogicutil. registeruser (userid, 1, 2, null); // deregister a user function.
} Else if (spserviceid. startswith ("-qtyx") & actionid. startswith ("2") {// stop the service;
Bizlogicutil. registeruser (userid, 2, 2, null );
Bizlogicutil. registeruser (userid, 3, 2, null );
}
// Write the Group Sending information table to send the SMS or menu to the ordering user;
SQL _ = "insert into pushsms (content, msisdn, pserviceid, feetype, feecode, sended, actionid, revtime) values ('" + content + "', '"+ destuser_id_msisdn +"', '"+ spserviceid +"', '01', '00', 0, "+ actionid +", now ())";
Dbutil.exe (SQL _);

}

/*
String transactionid = NULL;
String msgtype = NULL;
String HRET = NULL;
String version = NULL;
//--------------------
String linkid = NULL;
String actionid = NULL;
String actionreasonid = NULL;
String spid = NULL;
String spserviceid = NULL;
String accessmode = NULL;
String featurestr = NULL;
//----------------------
String send_address_devicetype = NULL;
String send_address_deviceid = NULL;
String dest_address_devicetype = NULL;
String dest_address_deviceid = NULL;
String feeuser_id_useridtype = NULL;
String feeuser_id_msisdn = NULL;
String feeuser_id_pseudo docode = NULL;
String destuser_id_useridtype = NULL;
String destuser_id_msisdn = NULL;
String destuser_id_pseudo docode = NULL;
*/
HRET = "0 ";
%>
<%!
// Overwrite the content into the file;
//
//
Public static void write (string file, string content)
{
Filewriter writer = NULL;
Try
{
If (file! = NULL & content! = NULL)
{
Writer = new filewriter (File );
Writer. Write (new string (content. getbytes ("GBK ")));
}
}
Catch (ioexception ex)
{
}
Finally
{
If (writer! = NULL)
{
Try
{
Writer. Close ();
}
Catch (ioexception ex1)
{
}
}
}
}

// Add comtent to file

Public static void append (string file, string content ){
Fileoutputstream fo = NULL;
Bufferedwriter fout = NULL;
String contents = "";
Try {

Fo = new fileoutputstream (file, true );
Fout = new bufferedwriter (New outputstreamwriter (FO ));
Contents = content + "/N ";
Fout. Write (contents, 0, contents. Length ());
Fout. Close ();
Fo. Close ();
} Catch (exception e ){

} Finally {
Try {
Fout. Close ();
Fo. Close ();
} Catch (exception E1 ){
}
}

}

%>
// This part of the code basically meets the requirements and can be left unchanged;
// SP after receiving the synchronous request packet, it processes the corresponding order relationship for the order request and returns the Synchronous Response syncorderrelationresp
// After receiving the response packet, MISC generates a formal order relationship or cancels the order relationship in the system based on whether the returned result is correct, the 1862 system sends a message to the user indicating that the order is successful or the cancellation is successful.
// Description of the syncorderrelationresp message field:
// Description of importance types of field names
// Msgtype must be string Message Type
// Transactionid must be a string of the Message ID
// Version must be a string of the version number of the interface message. The versions of all interface messages are "1.5.0"
// HRET must return an integer. The main error is as follows:
// 0: Successful
// 4007: The MISC service is activated synchronously, but the SP end has a subscription relationship and the status is activated.
// 4008: the service is activated synchronously by MISC, And the SP end does not have a subscription relationship, but the service fails to be activated.
// 4010: the service is stopped synchronously by MISC, And the SP end has a subscription relationship, but service cancellation fails.
// 4011: MISC stops the service synchronously, but the SP end does not have a subscription relationship.
// 4012: the service is suspended synchronously by MISC, And the SP end has a subscription relationship, but service suspension fails.
// 4013: the service is suspended synchronously by MISC, but the SP end does not have a subscription relationship.
// 4015: The MISC synchronously activates the service, but the SP end already has a subscription relationship and the status is activated.
// 4016: MISC synchronously activates the service, but the SP end does not have a subscription relationship
// For other errors, see MISC system sms sp access guide-interface transformation sub-book.

<SOAP-ENV: Envelope
Xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope"
Xmlns: SOAP-ENC = "http://schemas.xmlsoap.org/soap/encoding"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: dsmp = "http://www.monternet.com/dsmp/schemas/">
<SOAP-ENV: Header>
<Dsmp: transactionid xmlns: dsmp = "http://www.monternet.com/dsmp/schemas/">
<% = Transactionid %>
</Dsmp: transactionid>
</SOAP-ENV: Header>
SOAP-ENV: Body>
<Dsmp: syncorderrelationresp xmlns: dsmp = "http://www.monternet.com/dsmp/schemas/">
<Msgtype> syncorderrelationresp </msgtype>
<Version> <% = version %> </version>
<HRET> <% = HRET %> </HRET>
</Dsmp: syncorderrelationresp>
SOAP-ENV: Body>
SOAP-ENV: envelope>

 

===== All the code and content in this article cannot be reproduced without the permission of the author, retain ownership ==============================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.