WebServiceImpl.kt 4.63 KB
Newer Older
刘鹏 committed
1 2 3 4 5 6 7 8 9
package com.ydl.js

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.gson.Gson
import com.tencent.smtt.sdk.WebView
万齐军 committed
10
import com.ydl.audioim.api.IAudioImService
刘鹏 committed
11
import com.ydl.webview.*
万齐军 committed
12
import com.ydl.ydlcommon.modular.findRouteService
刘鹏 committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
import com.ydl.ydlcommon.utils.Utils
import com.yidianling.common.tools.ToastUtil
import com.yidianling.ydl_pay.pay.payDialog.CallBack
import com.yidianling.ydl_pay.pay.payDialog.ConfidePayParams
import com.yidianling.ydl_pay.pay.payDialog.PayDialog

/**
 * Created by haorui on 2019-10-10.
 * Des:
 */
@Route(path = "/web/webservice")
class WebServiceImpl : IWebService {

    override fun getJavascripHandler(activity: Activity, webView:WebView?, tellData: TellData): IJavascriptHandler {
        return NewH5_JavascriptHandler(webView, object : NewH5_WVClickAbstractListener(activity) {

            override fun setTitle(jsData: H5JsBean.H5JsCmd.Params?) {
                //设置webview标题
                if (activity is NewH5Activity) {
                    activity.setWebViewTitle(jsData?.title)
                }
            }

            //倾诉链接java接口
            override fun confideConnect(jsData: H5JsBean.H5JsCmd.Params?) {
                if (Utils.isFastClick()) {
                    //防止连击
                    return
                }
万齐军 committed
42
                if (!findRouteService(IAudioImService::class.java).getIsOnlineRtm()) {
刘鹏 committed
43
                    //异常退出或者账号被顶掉,重新登录并拨打
万齐军 committed
44
                    findRouteService(IAudioImService::class.java).loginRtm(JsModularService.getIUserService().getUserInfo()?.uid) { isSuccess: Boolean, _ ->
刘鹏 committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                        if (isSuccess) {
                            connectionJava(jsData?.id ?: 0, jsData?.confideType ?: 1, activity, tellData, jsData?.callType)
                        } else {
                            ToastUtil.toastShort("请重新拨打")
                        }
                    }
                } else {
                    connectionJava(jsData?.id ?: 0, jsData?.confideType ?: 1, activity, tellData, jsData?.callType)
                }
            }

            //php线路已废除
            override fun listenTel(jsData: H5JsBean.H5JsCmd.Params?) {
            }

            override fun listenAgora(jsData: H5JsBean.H5JsCmd.Params?) {
                if (Utils.isFastClick()) {
                    //防止连击
                    return
                }
                //声网路线
                connectionJava(jsData?.id ?: 0, 3, activity, tellData, jsData?.callType)
            }

            override fun confidePay(jsData: H5JsBean.H5JsCmd.Params?) {
                //倾诉支付
                val confidePay = ConfidePayParams(
                    jsData?.payTitle ?: "倾诉服务", jsData?.orderPrice, jsData?.coupnPrice ?: 0.00,
                    jsData?.avliableMoney ?: 0.00, jsData?.payId ?: "", jsData?.confideUrl ?: "", jsData?.merchantType
                )
                confidePayDialog(jsData?.id, jsData?.confideType, activity, confidePay, jsData?.callType)
            }

            override fun back() {
                if (activity is NewH5Activity) {
                    activity.goBack()
                }
            }
        })
    }

    //倾诉支付弹窗
    private fun confidePayDialog(id: Int?, type : Int?, activity: Activity, confidePay : ConfidePayParams, callType:String?){
        PayDialog(activity)
            .setCallback(object : CallBack {
                override fun onSuccess() {
                    //支付成功,直接拨打
                    if (TextUtils.isEmpty(confidePay.confideUrl)) {
                        connectionJava(id ?: 0, type ?: 1, activity, null, callType)
                    } else {
                        //倾诉订单列表页面过来,会有confideUrl值,则直接跳转此url
                        NewH5Activity.start(activity, H5Params(confidePay.confideUrl!!, ""))
                    }
                }
                override fun onError() {
                }

            })
            .show(confidePay)
    }

    //java版axb和声网接口
    @SuppressLint("CheckResult")
    private fun connectionJava(id: Int, type: Int, activity: Activity, tellData: TellData?, callType: String?) {
        try {
            JsModularService.getIConfideService().connectionJava(
                id, type, activity, Gson().toJson(tellData), callType
            )
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun init(context: Context) {

    }
}