Commit 5988366e authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :小象省钱
[实现方案] :
parent c6810392
...@@ -325,7 +325,7 @@ object PayDialog : PayContract.View { ...@@ -325,7 +325,7 @@ object PayDialog : PayContract.View {
return true //没有安装该app时,返回true,表示拦截自定义链接,但不跳转,避免弹出上面的错误页面 return true //没有安装该app时,返回true,表示拦截自定义链接,但不跳转,避免弹出上面的错误页面
} }
//处理http和https开头的url //处理http和https开头的url
view?.loadUrl(url) // view?.loadUrl(url)
return false return false
} }
......
package com.zxbw.modulemain.activity package com.zxbw.modulemain.activity
import android.content.Intent
import android.graphics.Paint import android.graphics.Paint
import android.net.Uri
import android.os.Handler import android.os.Handler
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.webkit.*
import com.zxbw.modulemain.R import com.zxbw.modulemain.R
import com.zxbw.modulemain.contract.CardDetailContract import com.zxbw.modulemain.contract.CardDetailContract
import com.zxbw.modulemain.presenter.CardDetailPresenter import com.zxbw.modulemain.presenter.CardDetailPresenter
import com.zxbw.modulemain.presenter.RightsPayPresenter
import com.zxhl.cms.AppContext import com.zxhl.cms.AppContext
import com.zxhl.cms.common.Constant import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.NetConfig
import com.zxhl.cms.common.base.BaseActivity import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.qy.RightsDetailEntity import com.zxhl.cms.net.model.qy.RightsDetailEntity
import com.zxhl.cms.net.model.uc.AliPayEntity import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.PayResultEntity import com.zxhl.cms.net.model.uc.PayResultEntity
import com.zxhl.cms.pay.PayActivity
import com.zxhl.cms.pay.alipay.AlipayServer import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.EventUtils import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.MainLooper import com.zxhl.cms.utils.MainLooper
import com.zxhl.cms.utils.RxBus import com.zxhl.cms.utils.RxBus
import com.zxhl.cms.widget.LoadingDialog import com.zxhl.cms.widget.LoadingDialog
...@@ -23,13 +29,14 @@ import io.reactivex.Observable ...@@ -23,13 +29,14 @@ import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_layout_card_detail.* import kotlinx.android.synthetic.main.activity_layout_card_detail.*
import kotlinx.android.synthetic.main.activity_layout_card_detail.id_img_back
class CardDetailActivity : BaseActivity(), CardDetailContract.View { class CardDetailActivity : BaseActivity(), CardDetailContract.View {
private var mPayPresenter: CardDetailPresenter? = null private var mPayPresenter: CardDetailPresenter? = null
private var mLoading: LoadingDialog? = null private var mLoading: LoadingDialog? = null
private var pay_type: Int? = RightsDetailActivity.ALI_PAY private var pay_type: Int? = RightsDetailActivity.H5_PAY
private var payResultObservable: Observable<PayResultEntity>? = null private var payResultObservable: Observable<PayResultEntity>? = null
var goodsID:String?="" var goodsID: String? = ""
override fun onClick(v: View?) { override fun onClick(v: View?) {
} }
...@@ -47,7 +54,7 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -47,7 +54,7 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
val cardbean: RightsDetailEntity = val cardbean: RightsDetailEntity =
intent.getSerializableExtra("cardbean") as RightsDetailEntity intent.getSerializableExtra("cardbean") as RightsDetailEntity
initPay() initPay()
goodsID=cardbean.id goodsID = cardbean.id
id_img_back?.setOnClickListener { id_img_back?.setOnClickListener {
finish() finish()
} }
...@@ -56,8 +63,9 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -56,8 +63,9 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
} }
setView(cardbean) setView(cardbean)
} }
fun setView(bean: RightsDetailEntity) { fun setView(bean: RightsDetailEntity) {
id_tv_card_name?.text="${bean.brand}${bean.goodsName}${bean.category}" id_tv_card_name?.text = "${bean.brand}${bean.goodsName}${bean.category}"
id_tv_cards_name?.text = "${bean.brand}${bean.goodsName}${bean.category}" id_tv_cards_name?.text = "${bean.brand}${bean.goodsName}${bean.category}"
id_tv_cagte_name?.text = bean.category id_tv_cagte_name?.text = bean.category
id_tv_card_discount?.text = "会员专享${bean.costDiscount}折" id_tv_card_discount?.text = "会员专享${bean.costDiscount}折"
...@@ -67,8 +75,9 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -67,8 +75,9 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
id_tv_pay_price?.text = "${bean.salePrice}" id_tv_pay_price?.text = "${bean.salePrice}"
id_tv_jiesheng_price?.text = "立省${bean.costPrice}元" id_tv_jiesheng_price?.text = "立省${bean.costPrice}元"
} }
fun initPay(){
mPayPresenter= CardDetailPresenter(this) fun initPay() {
mPayPresenter = CardDetailPresenter(this)
mLoading = LoadingDialog.getLoadingDialog( mLoading = LoadingDialog.getLoadingDialog(
this, this,
getString(com.zxhl.cms.R.string.wait_ing), getString(com.zxhl.cms.R.string.wait_ing),
...@@ -100,7 +109,20 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -100,7 +109,20 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
showResultLoading(false) showResultLoading(false)
} }
}, Consumer<Throwable> { }) }, Consumer<Throwable> { })
var result = SettingPreference.getConfig()
if (result != null) {
if (result != null && !result.pay_config_v2.isNullOrEmpty()) {
for (i in result.pay_config_v2!!.indices) {
if (result?.pay_config_v2!![i].open == 1) {
pay_type = result?.pay_config_v2!![i].type
break
}
}
}
}
} }
private var mHandler: Handler = Handler { private var mHandler: Handler = Handler {
when (it.what) { when (it.what) {
0 -> { 0 -> {
...@@ -111,13 +133,32 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -111,13 +133,32 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
} }
false false
} }
fun toPay(){
fun toPay() {
isClickPayBtn = true
mLoading?.setLoading("请稍后...") mLoading?.setLoading("请稍后...")
mLoading?.show() mLoading?.show()
mPayPresenter?.requestRightsAliPay(goodsID.toString(), pay_type.toString(), "") mPayPresenter?.requestRightsAliPay(goodsID.toString(), pay_type.toString(), "")
} }
override fun requestOrderSuc(result: AliPayEntity) { override fun requestOrderSuc(result: AliPayEntity) {
if (pay_type == RightsDetailActivity.MIN_PAY_PROGRAM) {
SettingPreference.setOutTradeNo(result?.outTradeNo)
JumpUtils.h5Jump("https://api.minpayment.com/pay.do?sendMsg=" + result.wakeup)
} else if (pay_type == RightsDetailActivity.H5_PAY) {
SettingPreference.setOutTradeNo(result?.outTradeNo)
if (result.outTradeNo.isNullOrEmpty()) {
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(result.outTradeNo!!)
}
} else if (pay_type == RightsDetailActivity.ALI_PAY) {
AlipayServer.payV2(this, result.wakeup!!) AlipayServer.payV2(this, result.wakeup!!)
} else {
showToast("暂不支持")
EventUtils.onEvent("payment_error", "$pay_type")
}
} }
override fun requestOrderFail(errorMsg: String) { override fun requestOrderFail(errorMsg: String) {
...@@ -125,12 +166,16 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -125,12 +166,16 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
} }
override fun verifyOrderSuc(order: String) { override fun verifyOrderSuc(order: String) {
isClickPayBtn = false
SettingPreference.setOutTradeNo("")
showResultLoading(true) showResultLoading(true)
} }
override fun verifyOrderFail(errorMsg: String) { override fun verifyOrderFail(errorMsg: String) {
isClickPayBtn = false
showResultLoading(false) showResultLoading(false)
} }
private fun showResultLoading(isPaySuc: Boolean) { private fun showResultLoading(isPaySuc: Boolean) {
if (isPaySuc) { if (isPaySuc) {
mLoading?.setResult(true, "支付成功", 1000) mLoading?.setResult(true, "支付成功", 1000)
...@@ -138,12 +183,124 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View { ...@@ -138,12 +183,124 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
mLoading?.setResult(false, "支付失败", 1000) mLoading?.setResult(false, "支付失败", 1000)
} }
} }
override fun onPause() {
super.onPause()
isPause = true
}
private var isPause = false
private var isClickPayBtn = false
override fun onResume() {
super.onResume()
if (isPause&&isClickPayBtn) {
if (pay_type == PayActivity.MIN_PAY_PROGRAM || pay_type == PayActivity.H5_PAY) {
//如果是敏支付或者H5支付
mPayPresenter?.verifyPay(SettingPreference.getOutTradeNo(), pay_type!!)
} else {
mHandler?.sendEmptyMessageDelayed(0, 2000)
}
}
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (payResultObservable != null) if (payResultObservable != null)
RxBus.get().unregister(Constant.PAY_RESULT, payResultObservable!!) RxBus.get().unregister(Constant.PAY_RESULT, payResultObservable!!)
} }
private fun loadH5Pay(form: String) {
// id_rights_pay_web_view.visibility = View.VISIBLE
Log.d("wxw", "startTime" + System.currentTimeMillis())
val webSettings = id_rights_pay_web_view.settings
//如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
webSettings.javaScriptEnabled = true
//设置自适应屏幕,两者合用
webSettings.useWideViewPort = true //将图片调整到适合webview的大小
webSettings.loadWithOverviewMode = true // 缩放至屏幕的大小
//其他细节操作
webSettings.cacheMode = WebSettings.LOAD_NO_CACHE //关闭webview中缓存
webSettings.allowFileAccess = true //设置可以访问文件
webSettings.javaScriptCanOpenWindowsAutomatically = true //支持通过JS打开新窗口
webSettings.loadsImagesAutomatically = true //支持自动加载图片
webSettings.defaultTextEncodingName = "utf-8" //设置编码格式
webSettings.domStorageEnabled = true
webSettings.allowFileAccessFromFileURLs = true;
webSettings.allowUniversalAccessFromFileURLs = true;
id_rights_pay_web_view?.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
Log.e("WXW", "dURL" + url.toString())
if (url == null) return false
try {
if (url.startsWith("alipays://") //支付宝
) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
EventUtils.onEvent("h5_open_zfb_suc")
return true
}
} catch (e: Exception) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
EventUtils.onEvent("h5_open_zfb_error", e.toString())
showResultLoading(false)
return true //没有安装该app时,返回true,表示拦截自定义链接,但不跳转,避免弹出上面的错误页面
}
//处理http和https开头的url
view?.loadUrl(url)
return false
}
override fun onPageFinished(view: WebView?, url: String?) {
Log.e("WXW", "cURL" + url.toString())
Log.d("wxw", "EndTime" + System.currentTimeMillis())
super.onPageFinished(view, url)
if (url?.contains(NetConfig.H5.WEB_URL_H5_PAY) == true) {
id_rights_pay_web_view?.loadUrl("javascript:loadPayHtml('$form')");
}
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// Log.d("wxw", "1error${error?.errorCode}")
// Log.d("wxw", "2error${error?.description}")
EventUtils.onEvent(
"h5_pay_error1",
"code: ${error?.errorCode} desc: ${error?.description}"
)
} else {
EventUtils.onEvent("h5_pay_error1", error.toString())
}
showResultLoading(false)
}
override fun onReceivedHttpError(
view: WebView?,
request: WebResourceRequest?,
errorResponse: WebResourceResponse?
) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (request?.url?.path?.endsWith("/favicon.ico") == true) {
} else {
EventUtils.onEvent(
"h5_pay_error2",
errorResponse?.statusCode.toString() + " url:${request?.url}"
)
showResultLoading(false)
}
} else {
EventUtils.onEvent("h5_pay_error2", errorResponse.toString())
showResultLoading(false)
}
super.onReceivedHttpError(view, request, errorResponse)
}
}
id_rights_pay_web_view.loadUrl(NetConfig.H5.WEB_URL_H5_PAY)
}
} }
\ No newline at end of file
...@@ -247,8 +247,6 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa ...@@ -247,8 +247,6 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
isClickPayBtn = false isClickPayBtn = false
SettingPreference.setOutTradeNo("") SettingPreference.setOutTradeNo("")
showResultLoading(true) showResultLoading(true)
showToast("成功!")
Log.d("wxw","成功")
} }
override fun verifyOrderFail(errorMsg: String) { override fun verifyOrderFail(errorMsg: String) {
...@@ -319,6 +317,7 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa ...@@ -319,6 +317,7 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
) { ) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent) startActivity(intent)
EventUtils.onEvent("h5_open_zfb_suc")
return true return true
} }
} catch (e: Exception) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash) } catch (e: Exception) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
...@@ -346,7 +345,16 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa ...@@ -346,7 +345,16 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
error: WebResourceError? error: WebResourceError?
) { ) {
super.onReceivedError(view, request, error) super.onReceivedError(view, request, error)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
// Log.d("wxw", "1error${error?.errorCode}")
// Log.d("wxw", "2error${error?.description}")
EventUtils.onEvent(
"h5_pay_error1",
"code: ${error?.errorCode} desc: ${error?.description}"
)
} else {
EventUtils.onEvent("h5_pay_error1", error.toString()) EventUtils.onEvent("h5_pay_error1", error.toString())
}
showResultLoading(false) showResultLoading(false)
} }
...@@ -355,10 +363,22 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa ...@@ -355,10 +363,22 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
request: WebResourceRequest?, request: WebResourceRequest?,
errorResponse: WebResourceResponse? errorResponse: WebResourceResponse?
) { ) {
super.onReceivedHttpError(view, request, errorResponse) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (request?.url?.path?.endsWith("/favicon.ico") == true) {
} else {
EventUtils.onEvent(
"h5_pay_error2",
errorResponse?.statusCode.toString() + " url:${request?.url}"
)
showResultLoading(false)
}
} else {
EventUtils.onEvent("h5_pay_error2", errorResponse.toString()) EventUtils.onEvent("h5_pay_error2", errorResponse.toString())
showResultLoading(false) showResultLoading(false)
} }
super.onReceivedHttpError(view, request, errorResponse)
}
} }
id_rights_pay_web_view.loadUrl(NetConfig.H5.WEB_URL_H5_PAY) id_rights_pay_web_view.loadUrl(NetConfig.H5.WEB_URL_H5_PAY)
......
...@@ -392,4 +392,9 @@ ...@@ -392,4 +392,9 @@
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<WebView
android:id="@+id/id_rights_pay_web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</RelativeLayout> </RelativeLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment