(1) Ding Jie T100 Android APP (PDA) webservice interface debug and development - to achieve login

Ding Jie, the information developed there to the T100 Interface: https: //download.csdn.net/download/qq_31776219/11275333

Here Insert Picture Description

Requirements are as follows: user name and password in the android terminal T100 requests to the interface background.

In the first T100, create interfaces, webservice name is the name of our interface
program code is the code file
Here Insert Picture Description

Then download the program file down to write interface code:
Here Insert Picture Description

Specific code as follows:

{<section id="cwssp010.description" >}
#應用 a00 樣板自動產生(Version:2)
#+ Version..: T100-ERP-1.01.00(SD版次:1,PR版次:1) Build-000000
#+ 
#+ Filename...: cwssp010
#+ Description: 
#+ Creator....: A1480(2019-07-04 15:29:28)
#+ Modifier...: 00000() -SD/PR-

{</section>}

{<section id="cwssp010.global" >}
#應用 m00 樣板自動產生(Version:4)

 
IMPORT os
IMPORT xml
#add-point:增加匯入項目
IMPORT util
#end add-point
 
SCHEMA ds
 
GLOBALS "../../cfg/top_global.inc"
GLOBALS "../../cfg/top_ws.inc"     #TIPTOP Service Gateway 使用的全域變數檔
#add-point:自定義模組變數(Module Variable)

#end add-point
 
#add-point:自定義客戶專用模組變數(Module Variable)

#end add-point

{</section>}

{<section id="cwssp010.main" >}
#+ 作業開始
MAIN
   DEFINE l_request_str  STRING
   DEFINE l_output_str   STRING
   #add-point:main段define

   #end add-point
   #add-point:main段define

   #end add-point
 
   #定義在其他link的程式則無效
   WHENEVER ERROR CALL cl_err_msg_log
 
   #add-point:初始化前定義

   #end add-point
   #依模組進行系統初始化設定(系統設定)
   CALL cl_ap_init("cwss","")
  
   #呼叫服務前置處理程序
   CALL awsp900_01_preprocess()    
 
   #呼叫服務函式,中介程式主要處理段
   IF g_status.code = "0" THEN
      CALL cwssp010_process()
   END IF
        
   #呼叫服務後置處理程序
   CALL awsp900_01_postprocess()    
 
   #離開作業
   CALL cl_ap_exitprogram("0")  
 
END MAIN

{</section>}

{<section id="cwssp010.process" >}
#+ 實際處理服務程式邏輯的FUNCTION內容
PRIVATE FUNCTION cwssp010_process()
   #add-point: 服務邏輯主要處理段的ADP
    DEFINE l_username LIKE gzxd_t.gzxd001 #存储用户名
    DEFINE l_password LIKE gzxd_t.gzxd002 #存储密码
    DEFINE l_dept LIKE ooag_t.ooag003     #存储部门
    DEFINE l_n            LIKE type_t.num5#存储是否有该用户名
    DEFINE l_str LIKE gzxd_t.gzxd001   #存储截取后的工号a1480->A1480
    DEFINE l_password_decode       LIKE gzxd_t.gzxd002#存储解密后的密码
    DEFINE l_return RECORD                 #返回部门、登录成功与否的标志
       l_gzxaowndp LIKE gzxa_t.gzxaowndp,
       l_flag  String,
       l_ooag011 LIKE ooag_t.ooag011  #存储真实姓名
    END RECORD
       
   DEFINE l_node_m         xml.DomNode
   DEFINE l_node           xml.DomNode
   DEFINE l_json    util.JSONObject
   DEFINE r_str   STRING

   INITIALIZE l_username TO NULL
   INITIALIZE l_password TO NULL
   #获取Android端传入的参数
   LET l_username = awsp900_01_getParameter("username")
   LET l_password = awsp900_01_getParameter("password")
   

   
   LET l_node_m = awsp900_01_addMasterRecord(NULL, "M1")
   LET l_node = awsp900_01_addDetail("gzxd_t")
   
   INITIALIZE l_return.* TO NULL
   
   SELECT count(*) INTO l_n FROM gzxd_t WHERE gzxd001= l_username  AND gzxdent=g_enterprise;
   IF l_n=1 THEN #说明存在该用户
       SELECT gzxd002 INTO l_password_decode FROM gzxd_t WHERE gzxd001=l_username AND gzxdent=g_enterprise #查出该用户的密码
       LET l_password_decode=cl_hashkey_user_decode(l_password_decode)#对数据库密文密码进行解码
       IF l_password_decode=l_password THEN #如果解码后的密码与Android端传入的密码相等,校验成功flag=1,失败flag=0
            LET l_return.l_flag=1
   
          LET l_str = cl_replace_str(l_username,'a','A')
          SELECT ooag011 INTO l_return.l_ooag011 FROM ooag_t WHERE ooagent=g_enterprise AND ooag001 = l_str
            #登录成功后,返回该用户所属的部门(由于Android端已经有用户名和密码,就只需传回部门和标志即可)
            SELECT gzxaowndp into l_return.l_gzxaowndp FROM gzxa_t WHERE gzxastus='Y' AND gzxaent=g_enterprise AND  gzxa001=l_username
       ELSE 
            LET l_return.l_flag=0
       END IF
    ELSE#不存在该用户
        LET l_return.l_flag=0
   END IF
   
  CALL awsp900_01_buildDetailRecord(l_node,util.JSONObject.fromFGL(l_return))
   #end add-point
END FUNCTION

{</section>}

{<section id="cwssp010.other_function" >}
#add-point:自定義元件(Function)

#end add-point

{</section>}

This is a request xml file request interface of T100
Here Insert Picture Description

But if you want to request interface, the above xml format but also to change it

Here Insert Picture Description
After such a replacement is the following code:

&lt;request type="sync" key="c45061457e12f4dcdb10defa1f13bc99"&gt;
&lt;host prod="T100MOBILE" ver="2" ip="192.168.66.156" lang="zh_CN" timezone="+8" timestamp="201907290aa90954792" acct="a1480"/&gt;
&lt;service prod="T100" name="appUserLogin" srvver="1.0111" id="topaatst"/&gt;
&lt;payload&gt;
    &lt;param key="data" type="XML"&gt;
      &lt;![CDATA[&lt;Request&gt;
&lt;RequestContent&gt;
&lt;Parameter&gt;
&lt;Record&gt;
&lt;Field name="username" value="a1480"/&gt;
&lt;Field name="password" value="aaaaa"/&gt;
&lt;/Record&gt;
&lt;/Parameter&gt;
&lt;Document/&gt;
&lt;/RequestContent&gt;
&lt;/Request&gt;
]]&gt;
&lt;/param&gt;
  &lt;/payload&gt;
&lt;/request&gt;

First test our interface with SOAP UI to measure

This is the test area of the interface:
HTTP:? // your ip / wtoptst / ws / r / awsp900 wsdl

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description
The above xml into the converted hello there can be friends

Here Insert Picture Description

Small problem:
emergence obtain the latest version of the app fails, there is my acct did not write the job number, there may be other problems.
Here Insert Picture Description

Here is the end of the development of PDA:

log in page:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.LoginActivity"

    >
    <!--登录activity-->
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/login_bg"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <!--    <ImageView
                android:id="@+id/imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/login_logo" />-->

       <!-- <EditText
            android:id="@+id/et_name"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginTop="30dp"
            android:hint="用户名"
            android:paddingLeft="10dp"
            android:singleLine="true" />-->
        <com.gaomeng.km.view.ClearEditText
            android:id="@+id/et_name"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginTop="30dp"
            android:hint="用户名"
            android:paddingLeft="10dp"
            android:singleLine="true"
            android:drawableRight="@drawable/delete_selector"
            />

        <com.gaomeng.km.view.ClearEditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:hint="密码"
            android:paddingLeft="10dp"
            android:password="true"
            android:singleLine="true" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:orientation="vertical">

            <CheckBox
                android:id="@+id/keep_password"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:checked="true"
                android:text="记住密码"
                android:textColor="@color/black" />

        </LinearLayout>

        <Button
            android:id="@+id/btnLogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_bg2"
            android:text="登录"
            android:textColor="@android:color/white" />


        <TextView
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"

            android:textColor="@color/black" />

        <TextView
            android:layout_width="wrap_content"

            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Powered By 资讯室"
            android:textColor="@color/black" />


    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

loginactiviry.java

package com.gaomeng.km.activity;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;

import androidx.appcompat.widget.Toolbar;

import com.gaomeng.km.R;
import com.gaomeng.km.activity.base.BaseActivity;
import com.gaomeng.km.util.ShareUtils;
import com.gaomeng.km.view.CustomDialog;
import com.jaeger.library.StatusBarUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import static com.gaomeng.km.util.StaticClass.WSDL_URI;


/**
 * @ProjectName: km
 * @Package: com.gaomeng.km
 * @ClassName: LoginActivity
 * @Description: 主界面登录Activity
 * @Author: yeweizheng
 * @CreateDate: 2019/7/26 16:30
 * @UpdateUser: yeweizheng
 * @UpdateDate: 2019/7/26 16:30
 * @UpdateRemark: tstasada lsc/2019
 * @Version: 1.0
 */


public class LoginActivity extends BaseActivity {

    public  static boolean LOGIN_FLAG = true;
    EditText etName;
    EditText etPassword;
    CheckBox keepPassword;
    Button btnLogin;
    Switch activity_login_sw;

    private String result;
    private CustomDialog dialog;
    private int mStatusBarColor;
    private Thread.UncaughtExceptionHandler mDefaultExceptionHandler;
    final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case 1:
                    Toast.makeText(getApplicationContext(), "网络请求失败,请检查wifi是否连接成功", Toast.LENGTH_SHORT).show();
                    break;
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        initView();

    }


    private void initView() {


        etName = findViewById(R.id.et_name);
        etPassword = findViewById(R.id.et_password);
        keepPassword = findViewById(R.id.keep_password);
        btnLogin = findViewById(R.id.btnLogin);

        mStatusBarColor = getResources().getColor(R.color.colorPrimary);
        StatusBarUtil.setColor(LoginActivity.this, mStatusBarColor);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //自动登录
        String loginName = ShareUtils.getString(getApplicationContext(), "name", null);
        String loginPassword = ShareUtils.getString(getApplicationContext(), "password", null);
        if (loginName != null && loginPassword != null) {
            Intent intent = new Intent(LoginActivity.this,
                    MainActivity.class);
            startActivity(intent);
            finish();
        }
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                //1、获取输入框的值
                String name = etName.getText().toString().trim();
                String password = etPassword.getText().toString().trim();
                //2.判断是否为空
                if (!TextUtils.isEmpty(name) & !TextUtils.isEmpty(password)) {
                    dialog.show();
                    QueryTestTask queryTestTask = new QueryTestTask();
                    queryTestTask.execute(name, password);
                }
            }
        });
        //ShareUtils.getBoolean(this, "keeppass", true);
        boolean isKeep = true;
        keepPassword.setChecked(isKeep);

        dialog = new CustomDialog(this, 100, 100, R.layout.dialog_loding, R.style.Theme_dialog, Gravity.CENTER, R.style.pop_anim_style);
        dialog.setCancelable(false);

        if (isKeep) {
            String name = ShareUtils.getString(this, "name", "");
            String password = ShareUtils.getString(this, "password", "");
            etName.setText(name);
            etPassword.setText(password);
        }
    }


    /**
     * 登录校验
     * param:username password 用户名 密码
     * return:l_gzxaowndp l_flag 部门 登录成功、失败标志
     */
    public String getLoginInfo(String username, String password) throws IOException {

        StringBuilder xml = new StringBuilder();
        xml.append("<soapenv:Envelope\n" +
                "\txmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                "\txmlns:tip=\"http://www.digiwin.com.cn/tiptop/TIPTOPServiceGateWay\">\n" +
                "\t<soapenv:Header />\n" +
                "\t<soapenv:Body>\n" +
                "\t\t<tip:invokeSrv>\n" +
                "\t\t\t<request>&lt;request type=\"sync\" key=\"c45061457e12f4dcdb10defa1f13bc99\"&gt;\n" +
                "&lt;host prod=\"T100MOBILE\" ver=\"2\" ip=\"192.168.66.156\" lang=\"zh_CN\" timezone=\"+8\" timestamp=\"201907290aa90954792\" acct=\"a0724\"/&gt;\n" +
                "&lt;service prod=\"T100\" name=\"appUserLogin\" srvver=\"1.0111\" id=\"topaatst\"/&gt;\n" +
                "&lt;payload&gt;\n" +
                "    &lt;param key=\"data\" type=\"XML\"&gt;\n" +
                "      &lt;![CDATA[&lt;Request&gt;&lt;RequestContent&gt;&lt;Parameter&gt;&lt;Record&gt;&lt;Field name=\"username\" value=\"");
        xml.append(username);
        xml.append("\"/&gt;&lt;Field name=\"password\" value=\"");
        xml.append(password);
        xml.append("\"/&gt;&lt;/Record&gt;&lt;/Parameter&gt;&lt;Document/&gt;&lt;/RequestContent&gt;&lt;/Request&gt;]]&gt;&lt;/param&gt;\n" +
                "  &lt;/payload&gt;\n" +
                "&lt;/request&gt;</request>\n" +
                "\t\t</tip:invokeSrv>\n" +
                "\t</soapenv:Body>\n" +
                "</soapenv:Envelope>");

        byte[] xmlbyte = xml.toString().getBytes("UTF-8");

        URL url = new URL(WSDL_URI);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setDoOutput(true);// 允许输出
        conn.setDoInput(true);
        conn.setUseCaches(false);// 不使用缓存
        conn.setDefaultUseCaches(false);
        conn.setRequestMethod("POST");
/*        conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
        conn.setRequestProperty("Charset", "UTF-8");*/
        conn.setRequestProperty("SOAPAction", "");
  /*      conn.setRequestProperty("Content-Length",
                String.valueOf(xmlbyte.length));*/
        conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
        // conn.setRequestProperty("X-ClientType", "2");//发送自定义的头信息

        conn.getOutputStream().write(xmlbyte);
        conn.getOutputStream().flush();
        conn.getOutputStream().close();

        String l_flag = "0";
        if (conn.getResponseCode() == 200) {

            InputStream is = conn.getInputStream();// 获取返回数据

            // 使用输出流来输出字符(可选)
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int len;
            while ((len = is.read(buf)) != -1) {
                out.write(buf, 0, len);
            }
            String string = out.toString("UTF-8");
            if (!TextUtils.isEmpty(string)) {
                Log.i("yeweizheng", string);
                //部门
                String l_gzxaowndp = string.substring(string.indexOf("l_gzxaowndp", 1), string.length());
                l_gzxaowndp = l_gzxaowndp.substring(l_gzxaowndp.indexOf("=", 1) + 2, l_gzxaowndp.indexOf("/", 1) - 1);
                System.out.println(l_gzxaowndp);
                //标志
                l_flag = string.substring(string.indexOf("l_flag", 1), string.length());
                l_flag = l_flag.substring(l_flag.indexOf("=", 1) + 2, l_flag.indexOf("/", 1) - 1);
                System.out.println(l_flag);

                //System.out.println(string);
                Log.i("yeweizheng", string);
                //String endString = l_gzxaowndp + "\n" + bcme004 + "\n" + bcme010 + "\n" + bcme017 + "\n" + bcmeud002 + "\n" + bcmeud001 + "\n";

                String  l_ooag011 = string.substring(string.indexOf("l_ooag011", 1), string.length());
                l_ooag011 = l_ooag011.substring(l_ooag011.indexOf("=", 1) + 2, l_ooag011.indexOf("/", 1) - 1);
                System.out.println(l_ooag011);
                ShareUtils.putString(getApplicationContext(), "l_ooag011", l_ooag011);
                out.close();
            }

        } else {
            Message msg = mHandler.obtainMessage();
            msg.what = 1;
            mHandler.sendMessage(msg);
        }
        return l_flag;
    }

    /**
     * 异步任务处理网络请求、更新UI主线程
     */
    class QueryTestTask extends AsyncTask<String, Integer, String> {

        @Override
        protected String doInBackground(String... params) {
            try {
                result = getLoginInfo(params[0], params[1]);

            } catch (Exception e) {
                e.printStackTrace();
            }
            //将结果返回给onPostExecute方法
            return result;
        }

        //此方法用于在主线程改变UI
        @Override
        protected void onPostExecute(String result) {
            if (TextUtils.isEmpty(result)) {
                dialog.dismiss();
                Message msg = mHandler.obtainMessage();
                msg.what = 1;
                mHandler.sendMessage(msg);
            } else {
                if (result.equals("1")) {
                    dialog.dismiss();
                    Toast.makeText(getApplicationContext(), "登录成功!", Toast.LENGTH_SHORT).show();
                    ShareUtils.putString(getApplicationContext(), "name", etName.getText().toString().trim());
                    ShareUtils.putString(getApplicationContext(), "password", etPassword.getText().toString().trim());
                    Intent intent = new Intent();
                    intent.setClass(LoginActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();

                } else {
                    dialog.dismiss();
                    Toast.makeText(getApplicationContext(), "用户名或密码错误!", Toast.LENGTH_LONG).show();
                }

            }

        }
    }
}

baseactivity.java

package com.gaomeng.km.activity.base;

import androidx.appcompat.app.AppCompatActivity;

/**
 * @ProjectName: km
 * @Package: com.gaomeng.km.activity
 * @ClassName: BaseActivity
 * @Description:所有Activity的基类,用于处理一些公共事件,如数据统计,获取上下文
 * @Author: yeweizheng
 * @CreateDate: 2019/7/30 8:42
 * @UpdateUser: yeweizheng
 * @UpdateDate: 2019/7/30 8:42
 * @UpdateRemark:
 * @Version: 1.0
 */
public class BaseActivity  extends AppCompatActivity {

}

Guess you like

Origin www.cnblogs.com/bkhacker/p/11987542.html