Commit c9f665d9 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :小象省钱
[实现方案] :调整H5支付和UI
parent f9d047c2
......@@ -81,7 +81,6 @@ public class MainActivity extends BaseActivity implements NavigationBottomView.N
navigationView = findViewById(R.id.id_activity_main_fragment_navigation);
initListener();
AdDataSupport.INSTANCE.init(this);
initFragment();
mRestartLoginObservable = RxBus.get().register(Constant.REFRESH_LOGIN_STATS, String.class);
mRestartLoginObservable.observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {
@Override
......@@ -94,7 +93,7 @@ public class MainActivity extends BaseActivity implements NavigationBottomView.N
}
});
initFragment();
mSwitchMainObservable = RxBus.get().register(Constant.SWITCH_PAGE, Integer.class);
mSwitchMainObservable.observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Integer>() {
@Override
......
package com.zxhl.cms.pay
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.net.http.SslError
import android.util.Log
import android.view.View
import android.webkit.*
import com.zxhl.cms.common.NetConfig
import com.zxhl.cms.utils.EventUtils
import kotlinx.android.synthetic.main.activity_member.*
/**
* @author (wangXuewei)
* @datetime 2022-06-02 10:53 GMT+8
* @detail :
*/
class H5PayUtil {
interface H5PayCallBack {
fun jumpZfbAppSuc();
fun jumpZfbAppException(e: Exception);
fun loadH5Error1(errorStr: String);
fun loadH5Error2(errorStr: String);
}
fun loadH5PayWeb(
mActivity: Activity,
h5WebVIew: WebView,
order: String,
callBack: H5PayCallBack
) {
val webSettings = h5WebVIew.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;
h5WebVIew?.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
var intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
mActivity.startActivity(intent);
}
h5WebVIew?.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
if (url == null) return false
try {
if (url.startsWith("alipays://") //支付宝
) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
mActivity.startActivity(intent)
callBack.jumpZfbAppSuc()
return true
}
} catch (e: Exception) {
//防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
callBack.jumpZfbAppException(e)
return true //没有安装该app时,返回true,表示拦截自定义链接,但不跳转,避免弹出上面的错误页面
}
view?.loadUrl(url)
return false;
}
override fun onPageFinished(view: WebView?, url: String?) {
EventUtils.onEvent("url_update", "url: ${url}")
super.onPageFinished(view, url)
if (url?.contains(NetConfig.H5.WEB_URL_H5_PAY) == true) {
h5WebVIew?.loadUrl("javascript:loadPayHtml('$order')");
}
}
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
// 接受所有网站的证书,忽略SSL错误,执行访问网页
handler?.proceed();
}
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) {
callBack.loadH5Error1("code: ${error?.errorCode} desc: ${error?.description}")
} else {
callBack.loadH5Error1(error.toString())
}
}
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 {
callBack.loadH5Error2("code:" + errorResponse?.statusCode.toString() + " url:${request?.url}")
}
} else {
callBack.loadH5Error2(errorResponse.toString())
}
super.onReceivedHttpError(view, request, errorResponse)
}
}
h5WebVIew.loadUrl(NetConfig.H5.WEB_URL_H5_PAY)
}
}
\ No newline at end of file
......@@ -43,6 +43,7 @@ object PayDialog : PayContract.View {
private var mPresenter: PayContract.Presenter? = null
private var pay_type: Int? = 0
private var id_rl_h5_pay_view: RelativeLayout? = null;
private var id_pay_web_view: WebView? = null;
private var id_rl_zfb_pay: RelativeLayout? = null;
private var id_img_ali: ImageView? = null;
......@@ -61,6 +62,19 @@ object PayDialog : PayContract.View {
mLoading?.setResult(false, "取消支付", 1000)
}
}
1 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view?.visibility = View.VISIBLE
EventUtils.onEvent("h5_pay_end")
}
2 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view?.visibility = View.VISIBLE
}
}
false
}
......@@ -102,6 +116,8 @@ object PayDialog : PayContract.View {
val tv_goods_pay_btn_price = mDialogView.findViewById<TextView>(R.id.id_activity_member_btn)
val id_rcl_payment_list = mDialogView.findViewById<RecyclerView>(R.id.id_rcl_payment_list)
id_rl_h5_pay_view = mDialogView.findViewById<RelativeLayout>(R.id.id_rl_h5_pay_view)
id_pay_web_view = mDialogView.findViewById<WebView>(R.id.id_pay_web_view)
id_rl_zfb_pay = mDialogView.findViewById<RelativeLayout>(R.id.id_rl_zfb_pay)
id_img_ali = mDialogView.findViewById<ImageView>(R.id.id_img_ali)
......@@ -109,7 +125,9 @@ object PayDialog : PayContract.View {
id_tv_zfb_1 = mDialogView.findViewById<TextView>(R.id.id_tv_zfb_1)
id_rl_min_pay = mDialogView.findViewById<RelativeLayout>(R.id.id_rl_min_pay)
id_tv_zfb_2 = mDialogView.findViewById<TextView>(R.id.id_tv_zfb_2)
mDialogView.findViewById<ImageView>(R.id.id_img_close_pay_web).setOnClickListener {
id_rl_h5_pay_view?.visibility = View.GONE
}
if (!context.isFinishing) {
Glide.with(context).load(goodsImg).into(tv_goodsMainImg)
......@@ -236,7 +254,38 @@ object PayDialog : PayContract.View {
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(form)
if (mActivity == null) {
return
}
if (mActivity?.isDestroyed == true) {
return
}
mHandler.sendEmptyMessageDelayed(1, 8000)
H5PayUtil().loadH5PayWeb(
mActivity!!,
id_pay_web_view!!,
form,
object : H5PayUtil.H5PayCallBack {
override fun jumpZfbAppSuc() {
id_rl_h5_pay_view?.visibility = View.GONE
EventUtils.onEvent("h5_open_zfb_suc")
mHandler.removeMessages(1)
}
override fun jumpZfbAppException(e: Exception) {
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler.removeMessages(1)
mHandler.sendEmptyMessage(2)
}
override fun loadH5Error1(errorStr: String) {
EventUtils.onEvent("h5_pay_error1", errorStr)
}
override fun loadH5Error2(errorStr: String) {
EventUtils.onEvent("h5_pay_error2", errorStr)
}
})
}
}
......@@ -288,110 +337,4 @@ object PayDialog : PayContract.View {
}
}
private fun loadH5Pay(form: String) {
// id_pay_web_view?.visibility = View.VISIBLE
Log.d("wxw", "startTime" + System.currentTimeMillis())
val webSettings = id_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_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))
mActivity?.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_pay_web_view?.loadUrl("javascript:loadPayHtml('$form')");
}
}
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
// 接受所有网站的证书,忽略SSL错误,执行访问网页
handler?.proceed();
}
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 {
// Log.d("wxw", "1errorResponse?.statusCode${request?.url}")
// Log.d("wxw", "2errorResponse?.statusCode${errorResponse?.statusCode}")
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_pay_web_view?.loadUrl(NetConfig.H5.WEB_URL_H5_PAY)
}
}
\ No newline at end of file
......@@ -256,9 +256,25 @@
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
<RelativeLayout
android:id="@+id/id_rl_h5_pay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<WebView
android:id="@+id/id_pay_web_view"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<ImageView
android:id="@+id/id_img_close_pay_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/id_pay_web_view"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
......@@ -21,6 +21,7 @@ import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.qy.RightsDetailEntity
import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.PayResultEntity
import com.zxhl.cms.pay.H5PayUtil
import com.zxhl.cms.pay.PayActivity
import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.EventUtils
......@@ -33,6 +34,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_layout_card_detail.*
import kotlinx.android.synthetic.main.activity_layout_card_detail.id_img_back
import kotlinx.android.synthetic.main.activity_layout_card_detail.id_img_close_pay_web
import kotlinx.android.synthetic.main.activity_layout_card_detail.id_rights_pay_web_view
import kotlinx.android.synthetic.main.activity_layout_card_detail.id_rl_h5_pay_view
class CardDetailActivity : BaseActivity(), CardDetailContract.View {
private var mPayPresenter: CardDetailPresenter? = null
......@@ -41,8 +45,8 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
private var payResultObservable: Observable<PayResultEntity>? = null
var goodsID: String? = ""
var type: String? = "0"
var skill:Boolean?=false
var outTradeNo:String?=""
var skill: Boolean? = false
var outTradeNo: String? = ""
override fun onClick(v: View?) {
}
......@@ -59,25 +63,28 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
override fun init() {
val cardbean: RightsDetailEntity =
intent.getSerializableExtra("cardbean") as RightsDetailEntity
type= intent.getStringExtra("type")
outTradeNo= intent.getStringExtra("outTradeNo")
skill= intent.getBooleanExtra("skill",false)
Log.e("MXL","skill"+skill)
type = intent.getStringExtra("type")
outTradeNo = intent.getStringExtra("outTradeNo")
skill = intent.getBooleanExtra("skill", false)
Log.e("MXL", "skill" + skill)
initPay()
goodsID = cardbean.id
id_img_back?.setOnClickListener {
if(TextUtils.equals(type,"1")){
if (TextUtils.equals(type, "1")) {
// 在这里,拦截或者监听Android系统的返回键事件。
DialogUtils.showExitSkillBuy(this, View.OnClickListener {
finish()
})
}else{
} else {
finish()
}
}
id_ll_pay?.setOnClickListener {
toPay()
}
id_img_close_pay_web.setOnClickListener {
id_rl_h5_pay_view.visibility = View.GONE
}
setView(cardbean)
}
......@@ -147,6 +154,19 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
mLoading?.setResult(false, "取消支付", 1000)
}
}
1 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
EventUtils.onEvent("h5_pay_end")
}
2 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
}
}
false
}
......@@ -155,7 +175,14 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
isClickPayBtn = true
mLoading?.setLoading("请稍后...")
mLoading?.show()
mPayPresenter?.requestRightsAliPay(goodsID.toString(), pay_type.toString(), "","51",skill,outTradeNo)
mPayPresenter?.requestRightsAliPay(
goodsID.toString(),
pay_type.toString(),
"",
"51",
skill,
outTradeNo
)
}
override fun requestOrderSuc(result: AliPayEntity) {
......@@ -168,7 +195,32 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(result.outTradeNo!!)
mHandler.sendEmptyMessageDelayed(1, 8000)
H5PayUtil().loadH5PayWeb(
this,
id_rights_pay_web_view,
result.outTradeNo ?: "",
object : H5PayUtil.H5PayCallBack {
override fun jumpZfbAppSuc() {
id_rl_h5_pay_view.visibility = View.GONE
EventUtils.onEvent("h5_open_zfb_suc")
mHandler.removeMessages(1)
}
override fun jumpZfbAppException(e: Exception) {
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler.removeMessages(1)
mHandler.sendEmptyMessage(2)
}
override fun loadH5Error1(errorStr: String) {
EventUtils.onEvent("h5_pay_error1", errorStr)
}
override fun loadH5Error2(errorStr: String) {
EventUtils.onEvent("h5_pay_error2", errorStr)
}
})
}
} else if (pay_type == RightsDetailActivity.ALI_PAY) {
AlipayServer.payV2(this, result.wakeup!!)
......@@ -206,11 +258,12 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
super.onPause()
isPause = true
}
private var isPause = false
private var isClickPayBtn = false
override fun onResume() {
super.onResume()
if (isPause&&isClickPayBtn) {
if (isPause && isClickPayBtn) {
if (pay_type == PayActivity.MIN_PAY_PROGRAM || pay_type == PayActivity.H5_PAY) {
//如果是敏支付或者H5支付
mPayPresenter?.verifyPay(SettingPreference.getOutTradeNo(), pay_type!!)
......@@ -226,109 +279,15 @@ class CardDetailActivity : BaseActivity(), CardDetailContract.View {
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)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if(TextUtils.equals(type,"1")){
if (TextUtils.equals(type, "1")) {
// 在这里,拦截或者监听Android系统的返回键事件。
DialogUtils.showExitSkillBuy(this, View.OnClickListener {
finish()
})
}else{
} else {
finish()
}
......
......@@ -20,9 +20,7 @@ import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.AppInEntity
import com.zxhl.cms.net.model.uc.PayResultEntity
import com.zxhl.cms.net.model.video.MemberEntity
import com.zxhl.cms.pay.PayContract
import com.zxhl.cms.pay.PayPresenter
import com.zxhl.cms.pay.PaymentFunAdapter
import com.zxhl.cms.pay.*
import com.zxhl.cms.utils.*
import com.zxhl.cms.widget.LoadingDialog
import io.reactivex.Observable
......@@ -118,6 +116,9 @@ class OpenMemberOrderActivity : BaseActivity(), PayContract.View {
id_img_back?.setOnClickListener {
finish()
}
id_img_close_pay_web?.setOnClickListener {
id_rl_h5_pay_view?.visibility = View.GONE
}
}
override fun data() {
......@@ -186,23 +187,46 @@ class OpenMemberOrderActivity : BaseActivity(), PayContract.View {
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(form)
mHandler.sendEmptyMessageDelayed(1, 8000)
H5PayUtil().loadH5PayWeb(
this,
id_member_pay_web_view,
form,
object : H5PayUtil.H5PayCallBack {
override fun jumpZfbAppSuc() {
id_rl_h5_pay_view?.visibility = View.GONE
EventUtils.onEvent("h5_open_zfb_suc")
mHandler.removeMessages(1)
}
override fun jumpZfbAppException(e: Exception) {
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler.removeMessages(1)
mHandler.sendEmptyMessage(2)
}
override fun loadH5Error1(errorStr: String) {
EventUtils.onEvent("h5_pay_error1", errorStr)
}
override fun loadH5Error2(errorStr: String) {
EventUtils.onEvent("h5_pay_error2", errorStr)
}
})
}
}
override fun verifyOrderSuc(orsder: String) {
EventUtils.onEvent("pay_suc")
UserDataUtils.updateUserInfo(object : AdCallback<String> {
override fun onResult(code: Int, result: String?) {
UserDataUtils.updateUserInfo { code, result ->
Constant.Switch.isOpenVip = true
val userInfoData = SettingPreference.getUserInfoData()
if (userInfoData != null) {
Constant.Switch.isOpenVip = userInfoData.member
Constant.Switch.isOpenVip = userInfoData.member ?: false
}
showResultLoading(true)
finish()
}
})
}
......@@ -244,6 +268,19 @@ class OpenMemberOrderActivity : BaseActivity(), PayContract.View {
mLoading?.setResult(false, "取消支付", 1000)
}
}
1 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
EventUtils.onEvent("h5_pay_end")
}
2 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
}
}
false
}
......@@ -272,105 +309,6 @@ class OpenMemberOrderActivity : BaseActivity(), PayContract.View {
timer = null
}
private fun loadH5Pay(form: String) {
mHandler?.sendEmptyMessageDelayed(0, 8000)
val webSettings = id_member_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_member_pay_web_view?.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
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")
mHandler?.removeMessages(0)
return true
}
} catch (e: Exception) { //防止crash (如果手机上没有安装处理某个scheme开头的url的APP, 会导致crash)
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler?.removeMessages(0)
showResultLoading(false)
return true //没有安装该app时,返回true,表示拦截自定义链接,但不跳转,避免弹出上面的错误页面
}
//处理http和https开头的url
// view?.loadUrl(url)?
return false
}
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
if (url?.contains(NetConfig.H5.WEB_URL_H5_PAY) == true) {
id_member_pay_web_view?.loadUrl("javascript:loadPayHtml('$form')");
}
}
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
// 接受所有网站的证书,忽略SSL错误,执行访问网页
handler?.proceed();
}
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())
}
}
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}"
)
}
} else {
EventUtils.onEvent("h5_pay_error2", errorResponse.toString())
}
super.onReceivedHttpError(view, request, errorResponse)
}
}
id_member_pay_web_view.loadUrl(NetConfig.H5.WEB_URL_H5_PAY)
}
var timer: Timer? = null
private fun vipTime() {
var timeCount = 15 * 60
......
......@@ -25,7 +25,9 @@ import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.qy.RightsDetailEntity
import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.PayResultEntity
import com.zxhl.cms.pay.H5PayUtil
import com.zxhl.cms.pay.PayActivity
import com.zxhl.cms.pay.PayDialog
import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.*
import com.zxhl.cms.widget.LoadingDialog
......@@ -50,7 +52,7 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
private var brandName: String = "";
private var mRightsData: RightsDetailEntity? = null
private var mLoading: LoadingDialog? = null
var skill:Boolean?=false
var skill: Boolean? = false
override fun layoutID(): Int {
return R.layout.activity_layout_rights_detail
}
......@@ -71,6 +73,7 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
id_img_back2.setOnClickListener(this)
id_tv_buy_right.setOnClickListener(this)
id_tv_btn_order.setOnClickListener(this)
id_img_close_pay_web.setOnClickListener(this)
//权益名称
brandName = intent?.data?.getQueryParameter("brandName") ?: ""
......@@ -112,6 +115,9 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
JumpUtils.MyOrderJump("")
finish()
}
id_img_close_pay_web -> {
id_rl_h5_pay_view?.visibility = View.GONE
}
}
}
......@@ -226,6 +232,19 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
mLoading?.setResult(false, "取消支付", 1000)
}
}
1 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
EventUtils.onEvent("h5_pay_end")
}
2 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
}
}
false
}
......@@ -240,7 +259,32 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(result.outTradeNo!!)
mHandler.sendEmptyMessageDelayed(1, 8000)
H5PayUtil().loadH5PayWeb(
this,
id_rights_pay_web_view,
result.outTradeNo ?: "",
object : H5PayUtil.H5PayCallBack {
override fun jumpZfbAppSuc() {
id_rl_h5_pay_view.visibility = View.GONE
EventUtils.onEvent("h5_open_zfb_suc")
mHandler.removeMessages(1)
}
override fun jumpZfbAppException(e: Exception) {
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler.removeMessages(1)
mHandler.sendEmptyMessage(2)
}
override fun loadH5Error1(errorStr: String) {
EventUtils.onEvent("h5_pay_error1", errorStr)
}
override fun loadH5Error2(errorStr: String) {
EventUtils.onEvent("h5_pay_error2", errorStr)
}
})
}
} else if (pay_type == ALI_PAY) {
AlipayServer.payV2(this, result.wakeup!!)
......@@ -279,18 +323,19 @@ class RightsDetailActivity : BaseActivity(), RightsDetailContract.View, RightsPa
super.onPause()
isPause = true
}
private var isPause = false
private var isClickPayBtn = false
override fun onResume() {
super.onResume()
Log.d("wxw","OnResume")
if (isPause&&isClickPayBtn) {
Log.d("wxw","1OnResume"+pay_type)
Log.d("wxw", "OnResume")
if (isPause && isClickPayBtn) {
Log.d("wxw", "1OnResume" + pay_type)
if (pay_type == PayActivity.MIN_PAY_PROGRAM || pay_type == PayActivity.H5_PAY) {
//如果是敏支付或者H5支付
mPayPresenter?.verifyPay(SettingPreference.getOutTradeNo(), pay_type!!)
} else {
Log.d("wxw","2OnResume"+pay_type)
Log.d("wxw", "2OnResume" + pay_type)
mHandler?.sendEmptyMessageDelayed(0, 2000)
}
}
......
......@@ -21,6 +21,7 @@ import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.qy.SkillGoodsEntity
import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.PayResultEntity
import com.zxhl.cms.pay.H5PayUtil
import com.zxhl.cms.pay.PayActivity
import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.EventUtils
......@@ -34,7 +35,10 @@ import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_layout_card_detail.*
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.*
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.id_img_back
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.id_img_close_pay_web
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.id_rights_pay_web_view
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.id_rl_h5_pay_view
import kotlinx.android.synthetic.main.activity_layout_to_pay_skill_goods.view.*
class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
private var mPayPresenter: CardDetailPresenter? = null
......@@ -43,8 +47,8 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
private var payResultObservable: Observable<PayResultEntity>? = null
var goodsID: String? = ""
var type: String? = "0"
var skill:Boolean?=false
var outTradeNo:String?=""
var skill: Boolean? = false
var outTradeNo: String? = ""
override fun onClick(v: View?) {
}
......@@ -63,7 +67,7 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
intent.getSerializableExtra("skillgoods") as SkillGoodsEntity
type = intent.getStringExtra("type")
outTradeNo = intent.getStringExtra("outTradeNo")
skill= intent.getBooleanExtra("skill",false)
skill = intent.getBooleanExtra("skill", false)
initPay()
goodsID = skillGoodsEntity.goodsId
setDataView(skillGoodsEntity)
......@@ -80,6 +84,9 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
finish()
}
}
id_img_close_pay_web?.setOnClickListener {
id_rl_h5_pay_view.visibility = View.GONE
}
}
fun setDataView(entity: SkillGoodsEntity) {
......@@ -151,6 +158,19 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
mLoading?.setResult(false, "取消支付", 1000)
}
}
1 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
EventUtils.onEvent("h5_pay_end")
}
2 -> {
if (mLoading != null) {
mLoading?.setResult(false, "支付异常", 0)
}
id_rl_h5_pay_view.visibility = View.VISIBLE
}
}
false
}
......@@ -159,7 +179,14 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
isClickPayBtn = true
mLoading?.setLoading("请稍后...")
mLoading?.show()
mPayPresenter?.requestRightsAliPay(goodsID.toString(), pay_type.toString(), "","50",skill,outTradeNo)
mPayPresenter?.requestRightsAliPay(
goodsID.toString(),
pay_type.toString(),
"",
"50",
skill,
outTradeNo
)
}
override fun requestOrderSuc(result: AliPayEntity) {
......@@ -172,7 +199,32 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
EventUtils.onEvent("h5_pay_error")
showResultLoading(false)
} else {
loadH5Pay(result.outTradeNo!!)
mHandler.sendEmptyMessageDelayed(1, 8000)
H5PayUtil().loadH5PayWeb(
this,
id_rights_pay_web_view,
result.outTradeNo ?: "",
object : H5PayUtil.H5PayCallBack {
override fun jumpZfbAppSuc() {
id_rl_h5_pay_view.visibility = View.GONE
EventUtils.onEvent("h5_open_zfb_suc")
mHandler.removeMessages(1)
}
override fun jumpZfbAppException(e: Exception) {
EventUtils.onEvent("h5_open_zfb_error", e.toString())
mHandler.removeMessages(1)
mHandler.sendEmptyMessage(2)
}
override fun loadH5Error1(errorStr: String) {
EventUtils.onEvent("h5_pay_error1", errorStr)
}
override fun loadH5Error2(errorStr: String) {
EventUtils.onEvent("h5_pay_error2", errorStr)
}
})
}
} else if (pay_type == RightsDetailActivity.ALI_PAY) {
AlipayServer.payV2(this, result.wakeup!!)
......@@ -209,11 +261,12 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
super.onPause()
isPause = true
}
private var isPause = false
private var isClickPayBtn = false
override fun onResume() {
super.onResume()
if (isPause&&isClickPayBtn) {
if (isPause && isClickPayBtn) {
if (pay_type == PayActivity.MIN_PAY_PROGRAM || pay_type == PayActivity.H5_PAY) {
//如果是敏支付或者H5支付
mPayPresenter?.verifyPay(SettingPreference.getOutTradeNo(), pay_type!!)
......@@ -228,100 +281,7 @@ class ToPaySkillGoodsActivity : BaseActivity(), CardDetailContract.View {
if (payResultObservable != null)
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)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (TextUtils.equals(type, "1")) {
......
......@@ -279,7 +279,7 @@ class NewBoxGoodsDetailActivity : BaseActivity(), GoodsDetailContract.View,
id_tv_youhui_coin_desc.visibility = View.GONE
} else {
id_tv_youhui_coin_desc.visibility = View.VISIBLE
id_tv_youhui_coin_desc.text = "优惠${reslut.activitiesDiscount}幸运币"
id_tv_youhui_coin_desc.text = "优惠${reslut.activitiesDiscount}"
}
if (reslut.originalPrice.isNullOrEmpty()) {
id_tv_one_original_price.visibility = View.GONE
......
......@@ -392,9 +392,27 @@
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="@+id/id_rl_h5_pay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:layout_below="@+id/id_rl_title">
<WebView
android:id="@+id/id_rights_pay_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/id_img_close_pay_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
android:layout_alignRight="@+id/id_member_pay_web_view"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
</RelativeLayout>
</RelativeLayout>
......@@ -325,10 +325,27 @@
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="@+id/id_rl_h5_pay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/id_img_back"
android:layout_marginTop="20dp"
android:visibility="gone">
<WebView
android:id="@+id/id_member_pay_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/id_img_close_pay_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
android:layout_alignRight="@+id/id_member_pay_web_view"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
</RelativeLayout>
</RelativeLayout>
......@@ -306,12 +306,27 @@
</LinearLayout>
<RelativeLayout
android:id="@+id/id_rl_h5_pay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:visibility="gone">
<WebView
android:id="@+id/id_rights_pay_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/id_img_close_pay_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
android:layout_alignRight="@+id/id_member_pay_web_view"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/id_rl_suc_view"
android:layout_width="match_parent"
......
......@@ -328,9 +328,25 @@
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="@+id/id_rl_h5_pay_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/id_rl_title"
android:visibility="gone">
<WebView
android:id="@+id/id_rights_pay_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/id_img_close_pay_web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
android:layout_alignRight="@+id/id_member_pay_web_view"
android:padding="10dp"
android:src="@drawable/icon_guanbi" />
</RelativeLayout>
</RelativeLayout>
......@@ -106,7 +106,7 @@
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_below="@+id/id_rl_search_view"
android:layout_marginTop="17dp"
android:layout_marginTop="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tl:tl_indicator_color="@color/color_333333"
......
......@@ -70,7 +70,7 @@
android:layout_height="match_parent"
android:background="@drawable/shape_4b5055_r4_stroke"
android:gravity="center_vertical"
android:paddingLeft="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="已减0元"
android:textColor="@color/color_333333"
......
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