init
diff --git a/app/src/main/java/com/supwisdom/bean/BaseResp.kt b/app/src/main/java/com/supwisdom/bean/BaseResp.kt
new file mode 100644
index 0000000..bb60f03
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/bean/BaseResp.kt
@@ -0,0 +1,8 @@
+package com.supwisdom.bean
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+open class BaseResp constructor(retcode: Int, retmsg: String) {
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/BeanPropEnum.kt b/app/src/main/java/com/supwisdom/db/BeanPropEnum.kt
new file mode 100644
index 0000000..2280950
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/BeanPropEnum.kt
@@ -0,0 +1,72 @@
+package com.supwisdom.db
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+object BeanPropEnum {
+    enum class Syspara {
+        id,
+        limitSwitch,
+        returnFlag,
+        heatBeat,
+        offlineFlag,
+        maxOfflineDays,
+        maxPaycnt,
+        creditLowLimit,
+        minCardbal,
+        maxCardbal,
+        daySumLimitamt,
+        onceLimitamt,
+        password,
+        fixpayConsumeGap,
+        controlFlag,
+        consumeShowtime,
+        consumeFailShowtime,
+        qrOfflineEnable,
+        qrcodeUrl,
+        socketSwitch,
+        commTime
+    }
+
+    enum class ConfigPara {
+        id,
+        mode,
+        deviceid,
+        merchaccno,
+        shopname,
+        devphyid,
+        psamno,
+        epayIP,
+        epayPort,
+        epayUri,
+        managePwd,
+        initOK
+    }
+
+    enum class DynamicPara {
+        id,
+        paraverno,
+        paragroupid,
+        feeverno,
+        feegroupid,
+        cardverno,
+        codeverno,
+        schoolno,
+        deductlimitamt,
+        sessionKey,
+        mf1key,
+        mf1factor,
+        rootkey,
+        iv,
+        devkey,
+        appId,
+        appSecret
+    }
+
+    enum class ControlPara {
+        paraname,
+        paraval
+    }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/ConfigParaDao.kt b/app/src/main/java/com/supwisdom/db/ConfigParaDao.kt
new file mode 100644
index 0000000..8402934
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/ConfigParaDao.kt
@@ -0,0 +1,124 @@
+package com.supwisdom.db
+
+import android.content.ContentValues
+import android.content.Context
+import android.database.Cursor
+import com.supwisdom.entity.ConfigParaRecord
+import java.util.concurrent.locks.Lock
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class ConfigParaDao constructor(context: Context) {
+    private val INDEX = "1"
+    private val TABLE = DBTransdtlHelper.TABLE_NAME_CONFIGPARA
+    private val dbHelper = DBTransdtlHelper.getInstance(context)
+
+    fun getLock(): Lock {
+        return dbHelper.getLock()
+    }
+
+    fun replace(record: ConfigParaRecord): Boolean {
+        val db = dbHelper.readableDatabase
+        val values = getContentValues(record)
+        try {
+            db.beginTransaction()
+            if (db.replace(TABLE, null, values) > 0) {
+                db.setTransactionSuccessful()
+                return true
+            }
+        } finally {
+            db.endTransaction()
+        }
+        return false
+    }
+
+    fun update(record: ConfigParaRecord): Boolean {
+        val db = dbHelper.writableDatabase
+        val values = getContentValues(record)
+        try {
+            db.beginTransaction()
+            if (db.update(
+                    TABLE,
+                    values,
+                    BeanPropEnum.ConfigPara.id.toString() + "=?",
+                    arrayOf(INDEX)
+                ) > 0
+            ) {
+                db.setTransactionSuccessful()
+                return true
+            }
+        } finally {
+            db.endTransaction()
+        }
+        return false
+    }
+
+    fun get(): ConfigParaRecord? {
+        val db = dbHelper.readableDatabase
+        var cursor: Cursor? = null
+        try {
+            cursor = db.query(
+                TABLE, null, BeanPropEnum.ConfigPara.id.toString() + "=?",
+                arrayOf(INDEX), null, null, null
+            )
+            if (cursor != null && cursor.moveToNext()) {
+                return getRecord(cursor)
+            }
+        } finally {
+            cursor?.close()
+        }
+        return null
+    }
+
+    private fun getRecord(cursor: Cursor): ConfigParaRecord {
+        val record = ConfigParaRecord()
+        record.mode = cursor.getInt(cursor.getColumnIndex(BeanPropEnum.ConfigPara.mode.toString()))
+        record.deviceid = cursor.getInt(cursor.getColumnIndex(BeanPropEnum.ConfigPara.deviceid.toString()))
+        record.merchaccno = cursor.getInt(cursor.getColumnIndex(BeanPropEnum.ConfigPara.merchaccno.toString()))
+        record.shopname = cursor.getString(cursor.getColumnIndex(BeanPropEnum.ConfigPara.shopname.toString()))
+        record.devphyid = cursor.getString(cursor.getColumnIndex(BeanPropEnum.ConfigPara.devphyid.toString()))
+        record.epayIP = cursor.getString(cursor.getColumnIndex(BeanPropEnum.ConfigPara.epayIP.toString()))
+        record.epayPort = cursor.getInt(cursor.getColumnIndex(BeanPropEnum.ConfigPara.epayPort.toString()))
+        record.epayUri = cursor.getString(cursor.getColumnIndex(BeanPropEnum.ConfigPara.epayUri.toString()))
+        record.shopPwd = cursor.getString(cursor.getColumnIndex(BeanPropEnum.ConfigPara.managePwd.toString()))
+        val value = cursor.getInt(cursor.getColumnIndex(BeanPropEnum.ConfigPara.initOK.toString()))
+        record.initOK = value == 1
+        return record
+    }
+
+    fun clear(): Boolean {
+        val db = dbHelper.writableDatabase
+        try {
+            db.beginTransaction()
+            if (db.delete(TABLE, null, null) < 0) {
+                return false
+            }
+            db.setTransactionSuccessful()
+            return true
+        } finally {
+            db.endTransaction()
+        }
+    }
+
+    private fun getContentValues(record: ConfigParaRecord): ContentValues {
+        val values = ContentValues()
+        values.put(BeanPropEnum.ConfigPara.id.toString(), INDEX)
+        values.put(BeanPropEnum.ConfigPara.mode.toString(), record.mode)
+        values.put(BeanPropEnum.ConfigPara.deviceid.toString(), record.deviceid)
+        values.put(BeanPropEnum.ConfigPara.merchaccno.toString(), record.merchaccno)
+        values.put(BeanPropEnum.ConfigPara.shopname.toString(), record.shopname)
+        values.put(BeanPropEnum.ConfigPara.devphyid.toString(), record.devphyid)
+        values.put(BeanPropEnum.ConfigPara.epayIP.toString(), record.epayIP)
+        values.put(BeanPropEnum.ConfigPara.epayPort.toString(), record.epayPort)
+        values.put(BeanPropEnum.ConfigPara.epayUri.toString(), record.epayUri)
+        values.put(BeanPropEnum.ConfigPara.managePwd.toString(), record.shopPwd)
+        if (record.initOK) {
+            values.put(BeanPropEnum.ConfigPara.initOK.toString(), 1)
+        } else {
+            values.put(BeanPropEnum.ConfigPara.initOK.toString(), 0)
+        }
+        return values
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/DBParaHelper.kt b/app/src/main/java/com/supwisdom/db/DBParaHelper.kt
new file mode 100644
index 0000000..8dcc3dc
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/DBParaHelper.kt
@@ -0,0 +1,106 @@
+package com.supwisdom.db
+
+import android.content.Context
+import android.database.sqlite.SQLiteDatabase
+import android.database.sqlite.SQLiteOpenHelper
+import java.util.concurrent.locks.Lock
+import java.util.concurrent.locks.ReentrantLock
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class DBParaHelper private constructor(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, VERSION) {
+    companion object {
+        private val DB_NAME = "db_para"
+        private val VERSION = 1
+
+        val TABLE_NAME_SYSPARA = "tb_syspara"
+        val TABLE_NAME_DYNAMICPARA = "tb_dynamicpara"
+        val TABLE_NAME_CONTROLPARA = "tb_controlpara"
+    }
+
+
+    /**
+     * SQL for create table
+     */
+
+    private val CREATE_TABLE_NAME_CONTROLPARA = ("create table IF NOT EXISTS "
+            + TABLE_NAME_CONTROLPARA + " ( "
+            + BeanPropEnum.ControlPara.paraname + " varchar(64) primary key,"
+            + BeanPropEnum.ControlPara.paraval + " varchar(64) )")
+    private val CREATE_TABLE_NAME_DYNAMICPARA = ("create table IF NOT EXISTS "
+            + TABLE_NAME_DYNAMICPARA + " ( "
+            + BeanPropEnum.DynamicPara.id + " long primary key, "
+            + BeanPropEnum.DynamicPara.paraverno + " integer, "
+            + BeanPropEnum.DynamicPara.paragroupid + " integer, "
+            + BeanPropEnum.DynamicPara.feeverno + " integer, "
+            + BeanPropEnum.DynamicPara.feegroupid + " integer, "
+            + BeanPropEnum.DynamicPara.cardverno + " char(12),"
+            + BeanPropEnum.DynamicPara.codeverno + " char(14),"
+            + BeanPropEnum.DynamicPara.schoolno + " varchar(16),"
+            + BeanPropEnum.DynamicPara.deductlimitamt + " integer,"
+            + BeanPropEnum.DynamicPara.sessionKey + " char(32),"
+            + BeanPropEnum.DynamicPara.mf1key + " char(16),"
+            + BeanPropEnum.DynamicPara.mf1factor + " char(16),"
+            + BeanPropEnum.DynamicPara.rootkey + " varchar(65),"
+            + BeanPropEnum.DynamicPara.iv + " char(32),"
+            + BeanPropEnum.DynamicPara.devkey + " char(16),"
+            + BeanPropEnum.DynamicPara.appId + " char(8),"
+            + BeanPropEnum.DynamicPara.appSecret + " char(32) )")
+    private val DROP_TABLE_NAME_DYNAMICPARA = "DROP TABLE IF EXISTS $TABLE_NAME_DYNAMICPARA"
+    private val CREATE_TABLE_NAME_SYSPARA = ("create table IF NOT EXISTS "
+            + TABLE_NAME_SYSPARA + " ( "
+            + BeanPropEnum.Syspara.id + " long primary key, "
+            + BeanPropEnum.Syspara.limitSwitch + " integer, "
+            + BeanPropEnum.Syspara.returnFlag + " integer, "
+            + BeanPropEnum.Syspara.heatBeat + " integer, "
+            + BeanPropEnum.Syspara.offlineFlag + " integer, "
+            + BeanPropEnum.Syspara.maxOfflineDays + " integer, "
+            + BeanPropEnum.Syspara.maxPaycnt + " integer, "
+            + BeanPropEnum.Syspara.creditLowLimit + " integer, "
+            + BeanPropEnum.Syspara.minCardbal + " integer, "
+            + BeanPropEnum.Syspara.maxCardbal + " integer, "
+            + BeanPropEnum.Syspara.daySumLimitamt + " integer, "
+            + BeanPropEnum.Syspara.onceLimitamt + " integer, "
+            + BeanPropEnum.Syspara.password + " char(6), "
+            + BeanPropEnum.Syspara.fixpayConsumeGap + " integer, "
+            + BeanPropEnum.Syspara.controlFlag + " integer, "
+            + BeanPropEnum.Syspara.consumeShowtime + " integer, "
+            + BeanPropEnum.Syspara.consumeFailShowtime + " integer, "
+            + BeanPropEnum.Syspara.qrOfflineEnable + " integer, "
+            + BeanPropEnum.Syspara.socketSwitch + " integer, "
+            + BeanPropEnum.Syspara.commTime + " integer, "
+            + BeanPropEnum.Syspara.qrcodeUrl + " varchar(128) )")
+    private val DROP_TABLE_NAME_SYSPARA = "DROP TABLE IF EXISTS $TABLE_NAME_SYSPARA"
+
+    @Volatile
+    private var instance: DBParaHelper? = null
+    private val lock = ReentrantLock()
+
+    fun getInstance(context: Context): DBParaHelper {
+        if (null == instance) {
+            synchronized(DBParaHelper::class.java) {
+                if (null == instance) {
+                    instance = DBParaHelper(context)
+                }
+            }
+        }
+        return instance!!
+    }
+
+    fun getLock(): Lock {
+        return lock
+    }
+
+    override fun onCreate(db: SQLiteDatabase) {
+        db.execSQL(CREATE_TABLE_NAME_SYSPARA)
+        db.execSQL(CREATE_TABLE_NAME_DYNAMICPARA)
+        db.execSQL(CREATE_TABLE_NAME_CONTROLPARA)
+    }
+
+    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
+        if (oldVersion < newVersion) {
+        }
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/DBTransdtlHelper.kt b/app/src/main/java/com/supwisdom/db/DBTransdtlHelper.kt
new file mode 100644
index 0000000..da9587b
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/DBTransdtlHelper.kt
@@ -0,0 +1,66 @@
+package com.supwisdom.db
+
+import android.content.Context
+import android.database.sqlite.SQLiteDatabase
+import android.database.sqlite.SQLiteOpenHelper
+import java.util.concurrent.locks.Lock
+import java.util.concurrent.locks.ReentrantLock
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class DBTransdtlHelper private constructor(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, VERSION) {
+    companion object {
+        private val DB_NAME = "db_transdtl"
+        private val VERSION = 1
+        @Volatile
+        private var instance: DBTransdtlHelper? = null
+
+        val TABLE_NAME_CONFIGPARA = "tb_configpara"
+
+        fun getInstance(context: Context): DBTransdtlHelper {
+            if (null == instance) {
+                synchronized(DBTransdtlHelper::class.java) {
+                    if (null == instance) {
+                        instance = DBTransdtlHelper(context)
+                    }
+                }
+            }
+            return instance!!
+        }
+    }
+
+    /**
+     * SQL for create table
+     */
+    private val CREATE_TABLE_NAME_CONFIGPARA = ("create table IF NOT EXISTS "
+            + TABLE_NAME_CONFIGPARA + " ( "
+            + BeanPropEnum.ConfigPara.id + " long primary key, "
+            + BeanPropEnum.ConfigPara.mode + " integer, "
+            + BeanPropEnum.ConfigPara.deviceid + " integer, "
+            + BeanPropEnum.ConfigPara.merchaccno + " integer, "
+            + BeanPropEnum.ConfigPara.shopname + " varchar(64), "
+            + BeanPropEnum.ConfigPara.devphyid + " char(8), "
+            + BeanPropEnum.ConfigPara.psamno + " char(12), "
+            + BeanPropEnum.ConfigPara.epayIP + " varchar(128), "
+            + BeanPropEnum.ConfigPara.epayPort + " integer, "
+            + BeanPropEnum.ConfigPara.epayUri + " varchar(128), "
+            + BeanPropEnum.ConfigPara.managePwd + " char(6),"
+            + BeanPropEnum.ConfigPara.initOK + " integer ) ")
+    private val DROP_TABLE_NAME_CONFIGPARA = "DROP TABLE IF EXISTS $TABLE_NAME_CONFIGPARA"
+
+    private val lock = ReentrantLock()
+    fun getLock(): Lock {
+        return lock
+    }
+
+    override fun onCreate(db: SQLiteDatabase) {
+        db.execSQL(CREATE_TABLE_NAME_CONFIGPARA)
+    }
+
+    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
+        if (oldVersion < newVersion) {
+        }
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/Pos.kt b/app/src/main/java/com/supwisdom/db/Pos.kt
new file mode 100644
index 0000000..0bbd00e
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/Pos.kt
@@ -0,0 +1,47 @@
+package com.supwisdom.db
+
+import android.content.Context
+import com.supwisdom.entity.ConfigParaRecord
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class Pos constructor(context: Context) {
+    private val context = context
+    private val sdContext = SDContext(context)
+    private var configParaDao = ConfigParaDao(context)
+    private var configParaRecord: ConfigParaRecord? = null
+
+    init {
+    }
+
+    /**
+     * 设备参数
+     */
+
+    fun replaceConfigPara(record: ConfigParaRecord): Boolean {
+        try {
+            configParaDao.getLock().lock()
+            if (configParaDao.replace(record)) {
+                configParaRecord = record
+                return true
+            }
+        } finally {
+            configParaDao.getLock().unlock()
+        }
+        return false
+    }
+
+    fun getConfigPara(): ConfigParaRecord? {
+        if (configParaRecord == null) {
+            try {
+                configParaDao.getLock().lock()
+                configParaRecord = configParaDao.get()
+            } finally {
+                configParaDao.getLock().unlock()
+            }
+        }
+        return configParaRecord
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/db/SDContext.kt b/app/src/main/java/com/supwisdom/db/SDContext.kt
new file mode 100644
index 0000000..df8b2b3
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/db/SDContext.kt
@@ -0,0 +1,56 @@
+package com.supwisdom.db
+
+import android.content.Context
+import android.content.ContextWrapper
+import android.database.DatabaseErrorHandler
+import android.database.sqlite.SQLiteDatabase
+import java.io.File
+import java.io.IOException
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class SDContext constructor(context: Context) : ContextWrapper(context) {
+    override fun getDatabasePath(name: String): File? {
+        if (android.os.Environment.MEDIA_MOUNTED == android.os.Environment.getExternalStorageState()) {
+            //获取sd卡路径
+            var dbDir = android.os.Environment.getExternalStorageDirectory().absolutePath
+            dbDir += "/supwisdom"//数据库所在目录
+            val dbPath = "$dbDir/$name"//数据库路径
+            //判断目录是否存在,不存在则创建该目录
+            val dirFile = File(dbDir)
+            if (!dirFile.exists()) {
+                dirFile.mkdirs()
+            }
+            val dbFile = File(dbPath)
+            if (!dbFile.exists()) {
+                try {
+                    if (dbFile.createNewFile()) {
+                        return dbFile
+                    }
+                } catch (e: IOException) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace()
+                }
+            } else {
+                return dbFile
+            }
+        }
+        return null
+    }
+
+    override fun openOrCreateDatabase(
+        name: String, mode: Int,
+        factory: SQLiteDatabase.CursorFactory?
+    ): SQLiteDatabase {
+        return SQLiteDatabase.openOrCreateDatabase(getDatabasePath(name), null)
+    }
+
+    override fun openOrCreateDatabase(
+        name: String, mode: Int,
+        factory: SQLiteDatabase.CursorFactory?, errorHandler: DatabaseErrorHandler?
+    ): SQLiteDatabase {
+        return SQLiteDatabase.openOrCreateDatabase(getDatabasePath(name), null)
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/entity/ConfigParaRecord.kt b/app/src/main/java/com/supwisdom/entity/ConfigParaRecord.kt
new file mode 100644
index 0000000..2a7c948
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/entity/ConfigParaRecord.kt
@@ -0,0 +1,19 @@
+package com.supwisdom.entity
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class ConfigParaRecord {
+    var mode: Int = 0//
+    var deviceid: Int = 0 // 设备ID
+    var merchaccno: Int = 0//商户号
+    var shopname: String? = null//商户名
+    var devphyid: String? = null
+    var epayIP: String? = null
+    var epayPort: Int = 0
+    var epayUri: String? = null
+    var shopPwd: String? = null //商户密码
+
+    var initOK: Boolean = false //是否初始化 true--未初始化,false--已初始化
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/okhttp/ICallBackok.kt b/app/src/main/java/com/supwisdom/okhttp/ICallBackok.kt
new file mode 100644
index 0000000..0620933
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/okhttp/ICallBackok.kt
@@ -0,0 +1,9 @@
+package com.supwisdom.okhttp
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+interface ICallBackok<T> {
+    fun callback(t: T)
+}
diff --git a/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
new file mode 100644
index 0000000..f91b0de
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
@@ -0,0 +1,257 @@
+package com.supwisdom.okhttp
+
+import okhttp3.*
+import java.io.IOException
+import java.io.UnsupportedEncodingException
+import java.security.SecureRandom
+import java.security.cert.CertificateException
+import java.security.cert.X509Certificate
+import java.util.concurrent.TimeUnit
+import javax.net.ssl.*
+import com.supwisdom.okhttp.ICallBackok as ICallBack1
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+@Suppress("DEPRECATION")
+class NetworkHandler private constructor() {
+    private var instance: NetworkHandler? = null
+    private var client: OkHttpClient? = null
+    private var clientLong: OkHttpClient
+    private val JSON = MediaType.parse("application/json; charset=utf-8")
+    private val FORM_ENCODE = MediaType.parse("application/x-www-form-urlencoded;charset=utf-8")
+    private var commTime = 2
+
+    init {
+        client = OkHttpClient()
+            .newBuilder()
+            .retryOnConnectionFailure(false)
+            .readTimeout(commTime.toLong(), TimeUnit.SECONDS)
+            .writeTimeout(1, TimeUnit.SECONDS)
+            .connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
+            .hostnameVerifier(TrustAllHostnameVerifier())
+            .sslSocketFactory(createSSLSocketFactory()!!)
+            .build()
+        clientLong = OkHttpClient()
+            .newBuilder()
+            .retryOnConnectionFailure(false)
+            .readTimeout(35, TimeUnit.SECONDS)
+            .writeTimeout(1, TimeUnit.SECONDS)
+            .connectTimeout(3, TimeUnit.SECONDS)
+            .hostnameVerifier(TrustAllHostnameVerifier())
+            .sslSocketFactory(createSSLSocketFactory())
+            .build()
+
+    }
+
+    fun setCommTime(communicateTime: Int) {
+        if (communicateTime != 0 && commTime != communicateTime) {
+            this.commTime = communicateTime
+            client = OkHttpClient()
+                .newBuilder()
+                .retryOnConnectionFailure(false)
+                .readTimeout(commTime.toLong(), TimeUnit.SECONDS)
+                .writeTimeout(1, TimeUnit.SECONDS)
+                .connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
+                .hostnameVerifier(TrustAllHostnameVerifier())
+                .sslSocketFactory(createSSLSocketFactory())
+                .build()
+        }
+    }
+
+    private class TrustAllCerts : X509TrustManager {
+        @Throws(CertificateException::class)
+        override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
+        }
+
+        @Throws(CertificateException::class)
+        override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
+        }
+
+        override fun getAcceptedIssuers(): Array<X509Certificate> {
+            return arrayOf<X509Certificate>()
+        }
+    }
+
+    private class TrustAllHostnameVerifier : HostnameVerifier {
+        override fun verify(hostname: String, session: SSLSession): Boolean {
+            return true
+        }
+    }
+
+    private fun createSSLSocketFactory(): SSLSocketFactory? {
+        var ssfFactory: SSLSocketFactory? = null
+        try {
+            val sc = SSLContext.getInstance("TLS")
+            sc.init(null, arrayOf<TrustManager>(TrustAllCerts()), SecureRandom())
+            ssfFactory = sc.socketFactory
+        } catch (e: Exception) {
+        }
+
+        return ssfFactory
+    }
+
+    fun getInstance(): NetworkHandler {
+        if (instance == null) {
+            synchronized(NetworkHandler::class.java) {
+                if (instance == null) {
+                    instance = NetworkHandler()
+                }
+            }
+        }
+        return instance!!
+    }
+
+    fun get(url: String, params: WebParams): TransResp? {
+        val request = Request.Builder()
+            .url(geturl(url, params))
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .build()
+        return getTransResp(request)
+    }
+
+    fun get(url: String, params: WebParams, callback: com.supwisdom.okhttp.ICallBackok<Any?>) {
+        val request = Request.Builder()
+            .url(geturl(url, params))
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .build()
+        client!!.newCall(request).enqueue(object : Callback {
+            override fun onFailure(call: Call, e: IOException) {
+                callback.callback(null)
+            }
+
+            override fun onResponse(call: Call, response: Response) {
+                try {
+                    val content = response.body()!!.string()
+                    val resp = TransResp(response.code(), response.message())
+                    if (response.isSuccessful) {
+                        resp.retjson = content
+                    }
+                    callback.callback(resp)
+                } catch (e: Exception) {
+                    e.printStackTrace()
+                    callback.callback(null)
+                }
+
+            }
+        })
+    }
+
+    fun post(url: String, params: WebParams): TransResp? {
+        val builder = FormBody.Builder()
+        for (name in params.allParameterNames()) {
+            builder.add(name, params.getParameterString(name))
+        }
+        val request = Request.Builder()
+            .url(url)
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .post(builder.build())
+            .build()
+        return getTransResp(request)
+    }
+
+    fun longPost(url: String, params: WebParams): TransResp? {
+        val builder = FormBody.Builder()
+        for (name in params.allParameterNames()) {
+            builder.add(name, params.getParameterString(name))
+        }
+        val request = Request.Builder()
+            .url(url)
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .post(builder.build())
+            .build()
+        return getLongTransResp(request)
+    }
+
+    fun post(url: String, json: String): TransResp? {
+        val body = RequestBody.create(JSON, json)
+        val request = Request.Builder()
+            .url(url)
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .post(body)
+            .build()
+        return getTransResp(request)
+    }
+
+    fun post(url: String, json: String, callback: com.supwisdom.okhttp.ICallBackok<Any?>) {
+        val body = RequestBody.create(JSON, json)
+        val request = Request.Builder()
+            .url(url)
+            .addHeader("Accept", "application/json; q=0.5")
+            .addHeader("Connection", "close")
+            .post(body)
+            .build()
+        client!!.newCall(request).enqueue(object : Callback {
+            override fun onFailure(call: Call, e: IOException) {
+                callback.callback(null)
+            }
+
+            override fun onResponse(call: Call, response: Response) {
+                try {
+                    val content = response.body()!!.string()
+                    val resp = TransResp(response.code(), response.message())
+                    if (response.isSuccessful) {
+                        resp.retjson = content
+                    }
+                    callback.callback(resp)
+                } catch (e: Exception) {
+                    callback.callback(null)
+                }
+
+            }
+        })
+    }
+
+    private fun getLongTransResp(request: Request): TransResp? {
+        return try {
+            val response = clientLong.newCall(request).execute()
+            /*响应主体只能被消耗一次*/
+            val content = response.body()!!.string()
+            val resp = TransResp(response.code(), response.message())
+            if (response.isSuccessful) {
+                resp.retjson = content
+            }
+            resp
+        } catch (e: Exception) {
+            e.printStackTrace()
+            null
+        }
+
+    }
+
+    private fun getTransResp(request: Request): TransResp? {
+        return try {
+            val response = client!!.newCall(request).execute()
+            /*响应主体只能被消耗一次*/
+            val content = response.body()!!.string()
+            val resp = TransResp(response.code(), response.message())
+            if (response.isSuccessful) {
+                resp.retjson = content
+            }
+            resp
+        } catch (e: Exception) {
+            e.printStackTrace()
+            //通讯超时
+            null
+        }
+    }
+
+    private fun geturl(url: String, params: WebParams?): String {
+        val sb = StringBuilder()
+        sb.append(url)
+        if (params != null) {
+            try {
+                sb.append(params.encodeURL())
+            } catch (e: UnsupportedEncodingException) {
+                e.printStackTrace()
+            }
+        }
+        return sb.toString()
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/okhttp/TransResp.kt b/app/src/main/java/com/supwisdom/okhttp/TransResp.kt
new file mode 100644
index 0000000..1ff26d9
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/okhttp/TransResp.kt
@@ -0,0 +1,18 @@
+package com.supwisdom.okhttp
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class TransResp constructor(retcode: Int, retmsg: String) {
+    /**
+     * HTTP返回码 retcode 200 success
+     */
+    /**
+     * retmsg 返回消息,如果是200 则为空,非200则为返回错误信息
+     */
+    /**
+     * 返回json信息
+     */
+    var retjson: String? = null
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/okhttp/WebAPISession.kt b/app/src/main/java/com/supwisdom/okhttp/WebAPISession.kt
new file mode 100644
index 0000000..b695ed2
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/okhttp/WebAPISession.kt
@@ -0,0 +1,40 @@
+package com.supwisdom.okhttp
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class WebAPISession : Cloneable {
+    /**
+     * appid,appsecret暂时写死在代码
+     */
+//    private val appId = PublicDef.APP_ID
+//    private val appSecret = PublicDef.APP_SECRET
+    private var termId = ""
+    private var epayurl = ""
+    private var sessionKey: String? = null
+
+    fun getEpayurl(): String {
+        return epayurl
+    }
+
+    fun setEpayurl(epayurl: String) {
+        this.epayurl = epayurl
+    }
+
+    @Throws(CloneNotSupportedException::class)
+    override fun clone(): Any {
+        val another = WebAPISession()
+        another.termId = this.termId
+        another.sessionKey = this.sessionKey
+        return another
+    }
+
+    fun getSessionKey(): String? {
+        return sessionKey
+    }
+
+    fun setSessionKey(sessionKey: String) {
+        this.sessionKey = sessionKey
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/okhttp/WebParams.kt b/app/src/main/java/com/supwisdom/okhttp/WebParams.kt
new file mode 100644
index 0000000..04ac771
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/okhttp/WebParams.kt
@@ -0,0 +1,90 @@
+package com.supwisdom.okhttp
+
+import java.io.*
+import java.net.URLEncoder
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+class WebParams {
+    private val mParameters = hashMapOf<String, Any>()
+
+    fun setParameter(name: String, value: String): WebParams {
+        mParameters[name] = value
+        return this
+    }
+
+    fun setParameter(name: String, value: Int): WebParams {
+        mParameters[name] = value
+        return this
+    }
+
+    fun setParameter(name: String, value: Float): WebParams {
+        mParameters[name] = value
+        return this
+    }
+
+    fun getParameterString(name: String): String {
+        val ret = mParameters[name]
+        if (String::class.java.isInstance(ret)) {
+            return ret as String
+        } else if (Int::class.java.isInstance(ret)) {
+            return ret.toString()
+        } else if (Double::class.java.isInstance(ret)) {
+            return ret.toString()
+        }
+        return ""
+    }
+
+    fun getParameterInt(name: String): Int {
+        val ret = mParameters[name]
+        return if (Int::class.java.isInstance(ret)) {
+            ret as Int
+        } else 0
+    }
+
+    fun getParameterFloat(name: String): Float {
+        val ret = mParameters[name]
+        return if (Float::class.java.isInstance(ret)) {
+            ret as Float
+        } else 0f
+    }
+
+    fun removeParameter(name: String) {
+        if (mParameters.containsKey(name)) {
+            mParameters.remove(name)
+        }
+    }
+
+    @Throws(UnsupportedEncodingException::class)
+    fun encodeURL(): String {
+        val result = StringBuilder()
+        for (name in mParameters.keys) {
+            val value = mParameters[name]
+            result.append(URLEncoder.encode(name, "utf-8"))
+                .append("=")
+                .append(URLEncoder.encode(value.toString(), "utf-8"))
+                .append("&")
+        }
+        return result.toString()
+    }
+
+    @Throws(IOException::class)
+    fun encodeURL(output: OutputStream): Int {
+        val byteStream = DataOutputStream(output)
+        val writer = OutputStreamWriter(byteStream, "utf-8")
+        for (name in mParameters.keys) {
+            val value = mParameters[name]
+            writer.write(URLEncoder.encode(name, "utf-8"))
+            writer.write("=")
+            writer.write(URLEncoder.encode(value.toString(), "utf-8"))
+            writer.write("&")
+        }
+        return byteStream.size()
+    }
+
+    fun allParameterNames(): Set<String> {
+        return mParameters.keys
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/service/WebsocketProcess.kt b/app/src/main/java/com/supwisdom/service/WebsocketProcess.kt
index fcad538..63a23ba 100644
--- a/app/src/main/java/com/supwisdom/service/WebsocketProcess.kt
+++ b/app/src/main/java/com/supwisdom/service/WebsocketProcess.kt
@@ -8,6 +8,10 @@
 import com.koushikdutta.async.http.AsyncHttpClient
 import com.koushikdutta.async.http.WebSocket
 import com.supwisdom.activities.SPApplication
+import com.supwisdom.db.Pos
+import com.supwisdom.utils.CommonUtil
+import com.supwisdom.utils.DateUtil
+import com.supwisdom.utils.LogUtil
 import com.supwisdom.utils.PublicDef
 import java.util.*
 
@@ -18,7 +22,7 @@
 class WebsocketProcess {
     private val TAG = "WebsocketProcess"
     private var handler: Handler? = null
-    private var pos: Pos
+    private var pos: Pos = SPApplication.getInstance().getPos()
     private var websocketService: WebsocketService
     private var isExit: Boolean = false
     private var qrcodeThread: Thread? = null
@@ -27,14 +31,13 @@
     @Volatile
     private var connectDoing: Boolean = false
     private var webSocket: Future<WebSocket>? = null
-    private var reLinkCnt: Int = 0
+    private var reLinkCnt: Long = 0
     private var clientID = ""
     @Volatile
     private var hasRecv: Boolean = false
     private var pingFailCnt: Int = 0
 
-    fun WebsocketProcess(): ??? {
-        pos = SPApplication.getInstance().getPos()
+    init {
         websocketService = WebsocketService()
     }
 
@@ -99,14 +102,14 @@
         }
     }
 
-    private fun getServerUrl(): String {
-        val sb = StringBuilder()
-        val url = YktSession.getInstance().getWebAPISession().getEpayurl()
-        val offset = url.lastIndexOf("/")
-        sb.append(url.substring(0, offset))
-            .append("/websocket/device_service")
-        return sb.toString()
-    }
+//    private fun getServerUrl(): String {
+//        val sb = StringBuilder()
+//        val url = YktSession.getInstance().getWebAPISession().getEpayurl()
+//        val offset = url.lastIndexOf("/")
+//        sb.append(url.substring(0, offset))
+//            .append("/websocket/device_service")
+//        return sb.toString()
+//    }
 
     private fun newWebsocket(url: String): Future<WebSocket> {
         return AsyncHttpClient.getDefaultInstance().websocket(url, null,
@@ -121,76 +124,76 @@
                 reLinkCnt = 0
                 isConnected = true
                 connectDoing = false
-                val loginStr = getLoginString()
-                webSocket.send(loginStr)
+//                val loginStr = getLoginString()
+//                webSocket.send(loginStr)
                 webSocket.stringCallback = WebSocket.StringCallback { s ->
-                    if (!CommonUtil.isEmpty(s)) {
-                        try {
-                            val retBean = GsonUtil.GsonToBean(s, WebsocketRetBean::class.java)
-                            if (retBean.getRetcode() === PublicDef.SUCCESS) {
-                                if ("login" == retBean.getAction()) {
-                                    val retData = WebsocketLoginRetData()
-                                    val data = retBean.getData() as JSONObject
-                                    retData.setHost_time(data["host_time"] as String?)
-                                } else if ("qrpay_in_process" == retBean.getAction()) {
-                                    val retData = WebsockConsumeProcessRetBean()
-                                    val data = retBean.getData() as JSONObject
-                                    retData.setCustname(data["custname"] as String?)
-                                    retData.setStuempno(data["stuempno"] as String?)
-                                    retData.setClientid(data["clientid"] as String?)
-                                    retData.setDevphyid(data["devphyid"] as String?)
-                                    retData.setTransdatetime(data["transdatetime"] as String?)
-
-                                    sendMsg(PublicDef.MSG_CONSUME_PAYING, "扫码付款中...")
-                                    webSocket.send(
-                                        getQRProcessResp(
-                                            retBean.getAction(),
-                                            retBean.getRequestid(),
-                                            retData
-                                        )
-                                    )
-                                } else if ("qrpay_finish" == retBean.getAction()) {
-                                    val retData = WebsockConsumeFinishRetBean()
-                                    val data = retBean.getData() as JSONObject
-                                    retData.setCustname(data["custname"] as String?)
-                                    retData.setStuempno(data["stuempno"] as String?)
-                                    retData.setDevphyid(data["devphyid"] as String?)
-                                    retData.setRefno(data["refno"] as String?)
-                                    retData.setStatus(data["status"] as String?)
-                                    retData.setAmount(data["amount"] as Int?)
-                                    retData.setAvailbal(data["availbal"] as Int?)
-                                    retData.setTransdatetime(data["transdatetime"] as String?)
-
-                                    if ("succ" == retData.getStatus()) {
-                                        val info = UserCardInfo(PublicDef.SUCCESS, "付款成功")
-                                        info.setDatetime(retData.getTransdatetime())
-                                        info.setUsername(retData.getCustname())
-                                        info.setStuempno(retData.getStuempno())
-                                        info.setPayamt(retData.getAmount())
-                                        info.setAmount(retData.getAmount())
-                                        info.setBalance(retData.getAvailbal())
-                                        info.setShowtime(pos.getSysPara().getConsumeShowtime())
-                                        info.setFlag(PublicDef.TRANSFLAG_NORMAL_CONSUME or PublicDef.TRANSFLAG_WRITE_CARD_SUCCESS)
-                                        info.setConsumeType(PublicDef.CONSUME_TYPE_BAR)
-                                        SPApplication.getInstance().setLastInfo(info)
-                                        sendMsg(PublicDef.MSG_CONSUME_QR_SUC, info)
-
-                                        saveTransdtlOnline(info)
-                                    }
-                                    webSocket.send(
-                                        getQRSuccessResp(
-                                            retBean.getAction(),
-                                            retBean.getRequestid(),
-                                            retData
-                                        )
-                                    )
-                                }
-                            }
-                        } catch (e: Exception) {
-                            e.printStackTrace()
-                        }
-
-                    }
+//                    if (!CommonUtil.isEmpty(s)) {
+//                        try {
+//                            val retBean = GsonUtil.GsonToBean(s, WebsocketRetBean::class.java)
+//                            if (retBean.getRetcode() === PublicDef.SUCCESS) {
+//                                if ("login" == retBean.getAction()) {
+//                                    val retData = WebsocketLoginRetData()
+//                                    val data = retBean.getData() as JSONObject
+//                                    retData.setHost_time(data["host_time"] as String?)
+//                                } else if ("qrpay_in_process" == retBean.getAction()) {
+//                                    val retData = WebsockConsumeProcessRetBean()
+//                                    val data = retBean.getData() as JSONObject
+//                                    retData.setCustname(data["custname"] as String?)
+//                                    retData.setStuempno(data["stuempno"] as String?)
+//                                    retData.setClientid(data["clientid"] as String?)
+//                                    retData.setDevphyid(data["devphyid"] as String?)
+//                                    retData.setTransdatetime(data["transdatetime"] as String?)
+//
+//                                    sendMsg(PublicDef.MSG_CONSUME_PAYING, "扫码付款中...")
+//                                    webSocket.send(
+//                                        getQRProcessResp(
+//                                            retBean.getAction(),
+//                                            retBean.getRequestid(),
+//                                            retData
+//                                        )
+//                                    )
+//                                } else if ("qrpay_finish" == retBean.getAction()) {
+//                                    val retData = WebsockConsumeFinishRetBean()
+//                                    val data = retBean.getData() as JSONObject
+//                                    retData.setCustname(data["custname"] as String?)
+//                                    retData.setStuempno(data["stuempno"] as String?)
+//                                    retData.setDevphyid(data["devphyid"] as String?)
+//                                    retData.setRefno(data["refno"] as String?)
+//                                    retData.setStatus(data["status"] as String?)
+//                                    retData.setAmount(data["amount"] as Int?)
+//                                    retData.setAvailbal(data["availbal"] as Int?)
+//                                    retData.setTransdatetime(data["transdatetime"] as String?)
+//
+//                                    if ("succ" == retData.getStatus()) {
+//                                        val info = UserCardInfo(PublicDef.SUCCESS, "付款成功")
+//                                        info.setDatetime(retData.getTransdatetime())
+//                                        info.setUsername(retData.getCustname())
+//                                        info.setStuempno(retData.getStuempno())
+//                                        info.setPayamt(retData.getAmount())
+//                                        info.setAmount(retData.getAmount())
+//                                        info.setBalance(retData.getAvailbal())
+//                                        info.setShowtime(pos.getSysPara().getConsumeShowtime())
+//                                        info.setFlag(PublicDef.TRANSFLAG_NORMAL_CONSUME or PublicDef.TRANSFLAG_WRITE_CARD_SUCCESS)
+//                                        info.setConsumeType(PublicDef.CONSUME_TYPE_BAR)
+//                                        SPApplication.getInstance().setLastInfo(info)
+//                                        sendMsg(PublicDef.MSG_CONSUME_QR_SUC, info)
+//
+//                                        saveTransdtlOnline(info)
+//                                    }
+//                                    webSocket.send(
+//                                        getQRSuccessResp(
+//                                            retBean.getAction(),
+//                                            retBean.getRequestid(),
+//                                            retData
+//                                        )
+//                                    )
+//                                }
+//                            }
+//                        } catch (e: Exception) {
+//                            e.printStackTrace()
+//                        }
+//
+//                    }
                 }
                 webSocket.closedCallback = CompletedCallback {
                     //主动断网,关服务
@@ -215,18 +218,18 @@
         CommonUtil.doSleep(reLinkCnt * 1000)
     }
 
-    private fun buildServerUrl(clientId: String): String {
-        val nowtime = CommonUtil.getNowDateTimeNoFormat()
-        val signdata = StringBuilder()
-        signdata.append(PublicDef.APP_ID).append(clientId).append(nowtime)
-        val sign = Encrypt.HMACSHA1(signdata.toString(), PublicDef.APP_SECRET)
-
-        val uri = StringBuilder()
-        uri.append("?local_time=").append(CommonUtil.getNowDateTimeNoFormat()).append("&appid=")
-            .append(PublicDef.APP_ID)
-            .append("&clientid=").append(clientId).append("&sign=").append(sign)
-        return getServerUrl() + uri.toString()
-    }
+//    private fun buildServerUrl(clientId: String): String {
+//        val nowtime = CommonUtil.getNowDateTimeNoFormat()
+//        val signdata = StringBuilder()
+//        signdata.append(PublicDef.APP_ID).append(clientId).append(nowtime)
+//        val sign = Encrypt.HMACSHA1(signdata.toString(), PublicDef.APP_SECRET)
+//
+//        val uri = StringBuilder()
+//        uri.append("?local_time=").append(DateUtil.getNowDateTimeNoFormat()).append("&appid=")
+//            .append(PublicDef.APP_ID)
+//            .append("&clientid=").append(clientId).append("&sign=").append(sign)
+//        return getServerUrl() + uri.toString()
+//    }
 
     private fun tryCloseWebsocket(sc: Future<WebSocket>?) {
         if (sc != null) {
@@ -244,73 +247,73 @@
     private fun createNewWebsocket() {
         doSleep()
         tryCloseWebsocket(webSocket)
-        webSocket = newWebsocket(buildServerUrl(clientID))
+//        webSocket = newWebsocket(buildServerUrl(clientID))
     }
 
-    private fun getQRProcessResp(action: String, requestid: String, retData: WebsockConsumeProcessRetBean): String {
-        val data = WebsockConsumeProcessRespBean.Content()
-        data.setDevphyid(retData.getDevphyid())
-        val resp = WebsockConsumeProcessRespBean()
-        resp.setRetcode(PublicDef.SUCCESS)
-        resp.setRetmsg("推流成功")
-        resp.setAction(action)
-        resp.setRequestid(requestid)
-        resp.setData(data)
-        return GsonUtil.GsonString(resp)
-    }
-
-    private fun getQRSuccessResp(action: String, requestid: String, retData: WebsockConsumeFinishRetBean): String {
-        val data = WebsockConsumeFinishRespBean.Content()
-        data.setDevphyid(retData.getDevphyid())
-        val resp = WebsockConsumeFinishRespBean()
-        resp.setRetcode(PublicDef.SUCCESS)
-        resp.setRetmsg("推流成功")
-        resp.setAction(action)
-        resp.setRequestid(requestid)
-        resp.setData(data)
-        return GsonUtil.GsonString(resp)
-    }
-
-    fun getLoginString(): String {
-        val data = WebsocketLoginDataReqBean()
-        data.setClientid(clientID)
-        data.setLocal_time(CommonUtil.getNowDateTimeNoFormat())
-
-        val req = WebsocketLoginReqBean()
-        req.setAction("login")
-        req.setNeedresp("true")
-        req.setRequestid(getRandom())
-        req.setData(data)
-        return GsonUtil.GsonString(req)
-    }
-
-    private fun getRandom(): String {
-        val rand = Random()
-        rand.setSeed(System.currentTimeMillis())
-        return String.format("%010d", rand.nextInt(999999999))
-    }
-
-    private fun saveTransdtlOnline(info: UserCardInfo): Boolean {
-        val record = TransdtlOnlineRecord()
-        var seqno = pos.getTransdtlOnlineSeqno()
-        if (seqno == 0) {
-            val ctlRecord = pos.getControlPara(PublicDef.CONTROL_TRANSDTLONL_SEQNO)
-            if (ctlRecord != null) {
-                seqno = Integer.valueOf(ctlRecord!!.getValue())
-            }
-        }
-        record.setDevseqno(seqno + 1)
-        record.setCustname(info.getUsername())
-        record.setStuempno(info.getStuempno())
-        record.setTransdate(info.getDatetime().substring(0, 8))
-        record.setTranstime(info.getDatetime().substring(8))
-        record.setDevphyid(pos.getConfigPara().getDevphyid())
-        record.setPayamt(info.getAmount())
-        record.setConsumetype(PublicDef.CONSUME_TYPE_BAR)
-        record.setFlag(PublicDef.TRANSFLAG_NORMAL_CONSUME or PublicDef.TRANSFLAG_WRITE_CARD_SUCCESS)
-        record.setUpflag(1)
-        return pos.saveTransdtlOnline(record)
-    }
+//    private fun getQRProcessResp(action: String, requestid: String, retData: WebsockConsumeProcessRetBean): String {
+//        val data = WebsockConsumeProcessRespBean.Content()
+//        data.setDevphyid(retData.getDevphyid())
+//        val resp = WebsockConsumeProcessRespBean()
+//        resp.setRetcode(PublicDef.SUCCESS)
+//        resp.setRetmsg("推流成功")
+//        resp.setAction(action)
+//        resp.setRequestid(requestid)
+//        resp.setData(data)
+//        return GsonUtil.GsonString(resp)
+//    }
+//
+//    private fun getQRSuccessResp(action: String, requestid: String, retData: WebsockConsumeFinishRetBean): String {
+//        val data = WebsockConsumeFinishRespBean.Content()
+//        data.setDevphyid(retData.getDevphyid())
+//        val resp = WebsockConsumeFinishRespBean()
+//        resp.setRetcode(PublicDef.SUCCESS)
+//        resp.setRetmsg("推流成功")
+//        resp.setAction(action)
+//        resp.setRequestid(requestid)
+//        resp.setData(data)
+//        return GsonUtil.GsonString(resp)
+//    }
+//
+//    fun getLoginString(): String {
+//        val data = WebsocketLoginDataReqBean()
+//        data.setClientid(clientID)
+//        data.setLocal_time(CommonUtil.getNowDateTimeNoFormat())
+//
+//        val req = WebsocketLoginReqBean()
+//        req.setAction("login")
+//        req.setNeedresp("true")
+//        req.setRequestid(getRandom())
+//        req.setData(data)
+//        return GsonUtil.GsonString(req)
+//    }
+//
+//    private fun getRandom(): String {
+//        val rand = Random()
+//        rand.setSeed(System.currentTimeMillis())
+//        return String.format("%010d", rand.nextInt(999999999))
+//    }
+//
+//    private fun saveTransdtlOnline(info: UserCardInfo): Boolean {
+//        val record = TransdtlOnlineRecord()
+//        var seqno = pos.getTransdtlOnlineSeqno()
+//        if (seqno == 0) {
+//            val ctlRecord = pos.getControlPara(PublicDef.CONTROL_TRANSDTLONL_SEQNO)
+//            if (ctlRecord != null) {
+//                seqno = Integer.valueOf(ctlRecord!!.getValue())
+//            }
+//        }
+//        record.setDevseqno(seqno + 1)
+//        record.setCustname(info.getUsername())
+//        record.setStuempno(info.getStuempno())
+//        record.setTransdate(info.getDatetime().substring(0, 8))
+//        record.setTranstime(info.getDatetime().substring(8))
+//        record.setDevphyid(pos.getConfigPara().getDevphyid())
+//        record.setPayamt(info.getAmount())
+//        record.setConsumetype(PublicDef.CONSUME_TYPE_BAR)
+//        record.setFlag(PublicDef.TRANSFLAG_NORMAL_CONSUME or PublicDef.TRANSFLAG_WRITE_CARD_SUCCESS)
+//        record.setUpflag(1)
+//        return pos.saveTransdtlOnline(record)
+//    }
 
     private fun sendMsg(code: Int, o: Any) {
         if (handler == null) {
diff --git a/app/src/main/java/com/supwisdom/utils/CommonUtil.kt b/app/src/main/java/com/supwisdom/utils/CommonUtil.kt
index e2b15c9..b0e3aeb 100644
--- a/app/src/main/java/com/supwisdom/utils/CommonUtil.kt
+++ b/app/src/main/java/com/supwisdom/utils/CommonUtil.kt
@@ -14,6 +14,8 @@
 import android.provider.Settings
 import java.io.File
 import java.io.FileOutputStream
+import java.io.PrintWriter
+import java.io.StringWriter
 
 /**
  * @author zzq
@@ -75,6 +77,16 @@
         return false
     }
 
+    fun getExceptionStack(e: Exception?): String {
+        if (e == null) {
+            return "null"
+        }
+        val sw = StringWriter()
+        val pw = PrintWriter(sw)
+        e.printStackTrace(pw)
+        return sw.toString()
+    }
+
     /**
      * get App versionName
      *
diff --git a/app/src/main/java/com/supwisdom/utils/LogUtil.kt b/app/src/main/java/com/supwisdom/utils/LogUtil.kt
new file mode 100644
index 0000000..75b8079
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/utils/LogUtil.kt
@@ -0,0 +1,39 @@
+package com.supwisdom.utils
+
+/**
+ ** create by zzq on 2019/7/24
+ ** @desc
+ **/
+object LogUtil {
+    private val DEBUG = 3
+    private val INFO = 2
+    private val ERROR = 1
+    private var curlevel = DEBUG
+
+    fun setLevel(level: Int) {
+        curlevel = level
+    }
+
+    fun d(tag: String, msg: String) {
+        if (curlevel >= DEBUG) {
+            writeLog(tag, msg)
+        }
+    }
+
+    fun i(tag: String, msg: String) {
+        if (curlevel >= INFO) {
+            writeLog(tag, msg)
+        }
+    }
+
+    fun e(tag: String, msg: String) {
+        if (curlevel >= ERROR) {
+            writeLog(tag, msg)
+        }
+    }
+
+    private fun writeLog(tag: String, msg: String) {
+        val time = DateUtil.getNowDate() + "--"
+        FileUtil.writeLogFile("$tag:$time--$msg")
+    }
+}
\ No newline at end of file