Commit e83b209b authored by mengcuiguang2's avatar mengcuiguang2

添加微信,支付宝支付功能

parent 53ec835e
...@@ -51,6 +51,18 @@ interface MainApi { ...@@ -51,6 +51,18 @@ interface MainApi {
@POST("api/getPayChannels") @POST("api/getPayChannels")
fun getPayChannels(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<PaymentBean>>> fun getPayChannels(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<PaymentBean>>>
/**
* 获取支付参数
*/
@POST("api/trade/getVipPayParams")
fun getVipPayParams(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<WxPayParamBean>>>
/**
* 支付成功
*/
@POST("api/trade/queryVipOrder")
fun queryVipOrder(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<Any>>>
/** /**
* 获取用户登录信息 * 获取用户登录信息
*/ */
......
...@@ -78,17 +78,13 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList ...@@ -78,17 +78,13 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
//查询用户登录信息 if (userManager.userIsLogin()) {
viewModel.getmyInfo() //查询用户登录信息
setUserLoginStatus() viewModel.getmyInfo()
// } else {
// if (userManager.userIsLogin()) { //重新显示界面信息
// //查询用户登录信息 setUserLoginStatus()
// viewModel.getmyInfo() }
// } else {
// //重新显示界面信息
// setUserLoginStatus()
// }
} }
private fun initListener() { private fun initListener() {
......
...@@ -28,15 +28,19 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -28,15 +28,19 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
private var mAdapter: DelegateAdapter? = null private var mAdapter: DelegateAdapter? = null
private var vipList: MutableList<VipBean.ListBean>? = null private var vipList: MutableList<VipBean.ListBean>? = null
private var currentPayType=""
override fun initVariableId() = BR.viewModel override fun initVariableId() = BR.viewModel
override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_openvip override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_openvip
override fun initData() { override fun initData() {
super.initData() super.initData()
//获取vip福利信息 if(!TextUtils.isEmpty(UserManager.INSTANCE.getUserID())){
viewModel.openvipInfo() //获取vip福利信息
//获取支付方式 viewModel.openvipInfo()
viewModel.getpaymentwey("android") //获取支付方式
viewModel.getpaymentwey("android")
}
initView() initView()
initListener() initListener()
} }
...@@ -86,6 +90,27 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -86,6 +90,27 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
vipList= it.list as MutableList<VipBean.ListBean>? vipList= it.list as MutableList<VipBean.ListBean>?
mAdapter?.addAdapter(GridPaymentAdapter(this, it.list!!)) mAdapter?.addAdapter(GridPaymentAdapter(this, it.list!!))
}) })
viewModel.vippayParams.observe(this, Observer<WxPayParamBean> {
if (TextUtils.equals(currentPayType, "WEIXIN")) {
if (it == null || it.params == null) {
ToastUtils.showShort("微信支付维护中")
return@Observer
}
wxPay(it)
} else {
if (it == null || it.params == null) {
ToastUtils.showShort("支付宝支付维护中")
return@Observer
}
alipay(it)
}
})
viewModel.isPaySuc.observe(this, Observer<Boolean> {
if(it){
ToastUtils.showShort("支付成功")
finish()
}
})
viewModel.Paymentdata.observe(this, Observer<PaymentBean> { viewModel.Paymentdata.observe(this, Observer<PaymentBean> {
if (it.list.isNullOrEmpty()) { if (it.list.isNullOrEmpty()) {
return@Observer return@Observer
...@@ -93,9 +118,13 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -93,9 +118,13 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
for (str in it.list!!) { for (str in it.list!!) {
if (str.equals("WEIXIN")) { if (str.equals("WEIXIN")) {
ly_weixin.visibility = View.VISIBLE ly_weixin.visibility = View.VISIBLE
currentPayType="WEIXIN"
} }
if (str.equals("ALIPAY")) { if (str.equals("ALIPAY")) {
ly_alipay.visibility = View.VISIBLE ly_alipay.visibility = View.VISIBLE
if(TextUtils.isEmpty(currentPayType)){
currentPayType="ALIPAY"
}
} }
} }
} }
...@@ -110,18 +139,20 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -110,18 +139,20 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
R.id.ly_weixin->{//支付宝支付 R.id.ly_weixin->{//支付宝支付
//设置选中样式 //设置选中样式
setOnChecked(1) setOnChecked(1)
currentPayType="WEIXIN"
} }
R.id.ly_alipay->{//支付宝支付 R.id.ly_alipay->{//支付宝支付
//设置选中样式 //设置选中样式
setOnChecked(2) setOnChecked(2)
currentPayType="ALIPAY"
} }
R.id.bt_try -> { R.id.bt_try -> {
if (vipList != null && vipList!!.size > 0) { if (vipList != null && vipList!!.size > 0) {
// if (TextUtils.equals("weixin", payDialog?.payChannel)) { if (TextUtils.equals("WEIXIN",currentPayType)) {
// vipPresenter?.getVipPayParams("WEIXIN", vipList!![vipAdapter?.getPosition()].pid) viewModel.getVipPayParams("WEIXIN", vipList!![0].pid)
// } else { } else {
// vipPresenter?.getVipPayParams("ALIPAY", vipList!![vipAdapter?.getPosition()].pid) viewModel.getVipPayParams("ALIPAY", vipList!![1].pid)
// } }
} }
} }
} }
...@@ -155,7 +186,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -155,7 +186,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
//支付成功 //支付成功
UserManager.INSTANCE.setVipFlag(true) UserManager.INSTANCE.setVipFlag(true)
} }
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), isPay) viewModel.queryVipOrder(wxParanBean.tid.toString())
}) { throwable -> }) { throwable ->
ToastUtils.showShort("支付异常,请联系管理员") ToastUtils.showShort("支付异常,请联系管理员")
} }
...@@ -168,7 +199,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>() ...@@ -168,7 +199,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
//支付成功 //支付成功
UserManager.INSTANCE.setVipFlag(true) UserManager.INSTANCE.setVipFlag(true)
} }
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), isPay) viewModel.queryVipOrder(wxParanBean.tid.toString())
}) { throwable -> }) { throwable ->
ToastUtils.showShort("支付异常,请联系管理员") ToastUtils.showShort("支付异常,请联系管理员")
} }
......
...@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData ...@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import com.mints.street.bean.BaseResponse import com.mints.street.bean.BaseResponse
import com.mints.street.bean.PaymentBean import com.mints.street.bean.PaymentBean
import com.mints.street.bean.VipBean import com.mints.street.bean.VipBean
import com.mints.street.bean.WxPayParamBean
import com.mints.street.model.ApiModel import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl import com.mints.street.netwrok.base.HttpSubscribeImpl
import me.goldze.mvvmhabit.base.BaseViewModel import me.goldze.mvvmhabit.base.BaseViewModel
...@@ -16,6 +17,8 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) { ...@@ -16,6 +17,8 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
val Vipdata: MutableLiveData<VipBean> = MutableLiveData() val Vipdata: MutableLiveData<VipBean> = MutableLiveData()
val Paymentdata: MutableLiveData<PaymentBean> = MutableLiveData() val Paymentdata: MutableLiveData<PaymentBean> = MutableLiveData()
val vippayParams: MutableLiveData<WxPayParamBean> = MutableLiveData()
val isPaySuc: MutableLiveData<Boolean> = MutableLiveData()
/** /**
* 开通Vip * 开通Vip
...@@ -61,4 +64,42 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) { ...@@ -61,4 +64,42 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
) )
} }
/**
* 获取支付参数
*/
fun getVipPayParams(payChannel:String,pid: String) {
val vo = HashMap<String, Any>()
vo["payChannel"] = payChannel
vo["pid"] = pid
ApiModel.getVipPayParams(lifecycleProvider, vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<WxPayParamBean>>(
this@OpenvipViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<WxPayParamBean>) {
vippayParams.value = response.result
}
override fun onError(e: Throwable) {
}
}
)
}
/**
* 支付成功
*/
fun queryVipOrder(tid: String) {
val vo = HashMap<String, Any>()
vo["tid"] = tid
ApiModel.queryVipOrder(lifecycleProvider, vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>(
this@OpenvipViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
isPaySuc.value = true
}
override fun onError(e: Throwable) {
}
}
)
}
} }
...@@ -54,6 +54,22 @@ object ApiModel { ...@@ -54,6 +54,22 @@ object ApiModel {
.execute(lifecycleProvider, MainApi.newInstance().getPayChannels(map)) .execute(lifecycleProvider, MainApi.newInstance().getPayChannels(map))
} }
/**
* 获取支付参数
*/
fun getVipPayParams(lifecycleProvider: LifecycleProvider<Any>?, map: Map<String, Any>): Observable<Response<BaseResponse<WxPayParamBean>>> {
return HttpManager.getInstance()
.execute(lifecycleProvider, MainApi.newInstance().getVipPayParams(map))
}
/**
* 支付成功
*/
fun queryVipOrder(lifecycleProvider: LifecycleProvider<Any>?, map: Map<String, Any>): Observable<Response<BaseResponse<Any>>> {
return HttpManager.getInstance()
.execute(lifecycleProvider, MainApi.newInstance().queryVipOrder(map))
}
/** /**
* 获取用户登录信息 * 获取用户登录信息
*/ */
......
package com.mints.street.widget
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.AttributeSet
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import com.mints.street.R
class BrowserLayout : LinearLayout {
private var mContext: Context? = null
private var mWebView: WebView? = null
private var mWebTitle: TextView? = null
private val mBarHeight = 5
private var mProgressBar: ProgressBar? = null
constructor(context: Context) : super(context) {
init(context)
}
constructor(
context: Context,
attrs: AttributeSet?
) : super(context, attrs) {
init(context)
}
private fun init(context: Context) {
mContext = context
orientation = VERTICAL
mProgressBar = LayoutInflater.from(context)
.inflate(R.layout.progress_horizontal, null) as ProgressBar
mProgressBar!!.max = 100
mProgressBar!!.progress = 0
addView(
mProgressBar,
LayoutParams.MATCH_PARENT,
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_PX,
mBarHeight.toFloat(),
resources.displayMetrics
).toInt()
)
mWebView = WebView(context)
mWebView!!.settings.javaScriptEnabled = true
mWebView!!.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
mWebView!!.settings.defaultTextEncodingName = "UTF-8"
mWebView!!.settings.cacheMode = WebSettings.LOAD_NO_CACHE
mWebView!!.settings.builtInZoomControls = true
mWebView!!.settings.setSupportMultipleWindows(true)
//将图片调整到适合webview的大小
mWebView!!.settings.useWideViewPort = false
mWebView!!.settings.loadWithOverviewMode = true
mWebView!!.settings.setSupportZoom(true)
mWebView!!.settings.pluginState = WebSettings.PluginState.ON
mWebView!!.settings.domStorageEnabled = true
mWebView!!.settings.loadsImagesAutomatically = true
mWebView!!.settings.displayZoomControls = false
// 支持打开新窗口
mWebView!!.settings.javaScriptCanOpenWindowsAutomatically = true
try {
mWebView!!.setLayerType(View.LAYER_TYPE_NONE, null)
} catch (e: Exception) {
e.printStackTrace()
}
//支持自动加载图片
mWebView!!.settings.loadsImagesAutomatically = true
//解决5.0后https地址中图片不显示的问题(图片地址为http)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView!!.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}
//允许webview对文件的操作
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mWebView!!.settings.allowUniversalAccessFromFileURLs = true
mWebView!!.settings.allowFileAccessFromFileURLs = true
}
mWebView!!.settings.allowFileAccess = true
val lps =
LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f)
addView(mWebView, lps)
mWebView!!.setWebChromeClient(object : WebChromeClient() {
override fun onReceivedTitle(view: WebView, title: String) {
super.onReceivedTitle(view, title)
if (mWebTitle != null) {
mWebTitle!!.text = title
}
}
override fun onProgressChanged(view: WebView, newProgress: Int) {
super.onProgressChanged(view, newProgress)
if (newProgress == 100) {
mProgressBar!!.visibility = View.GONE
} else {
mProgressBar!!.visibility = View.VISIBLE
mProgressBar!!.progress = newProgress
}
}
})
mWebView!!.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView,
url: String
): Boolean {
if (url.startsWith("tel:")) {
try {
val intent = Intent(Intent.ACTION_DIAL, Uri.parse(url))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
mContext!!.startActivity(intent)
} catch (e: Exception) {
}
return true
}
return super.shouldOverrideUrlLoading(view, url)
}
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
}
}
}
fun loadUrl(url: String?) {
mWebView!!.loadUrl(url!!)
}
fun canGoBack(): Boolean {
return if (null != mWebView) mWebView!!.canGoBack() else false
}
fun canGoForward(): Boolean {
return if (null != mWebView) mWebView!!.canGoForward() else false
}
fun goBack() {
if (null != mWebView) {
mWebView!!.goBack()
}
}
fun goForward() {
if (null != mWebView) {
mWebView!!.goForward()
}
}
val webView: WebView?
get() = if (mWebView != null) mWebView else null
fun setWebTitle(mWebTitle: TextView?) {
this.mWebTitle = mWebTitle
}
fun clearWebView() {
if (mWebView != null) {
val parent = mWebView!!.parent as ViewGroup
parent?.removeView(mWebView)
mWebView!!.removeAllViews()
mWebView!!.destroy()
mWebView = null
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:drawable="@drawable/progress_bar_bg" />
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#3D5AFE" />
</shape>
</clip>
</item>
</layer-list>
\ No newline at end of file
...@@ -16,11 +16,10 @@ ...@@ -16,11 +16,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:ctb_theme="dark" app:ctb_theme="dark"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<WebView <WebView
android:id="@+id/webview" android:id="@+id/webview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>
</layout> </layout>
\ No newline at end of file
<!--
~ Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
~
~ Licensed under the Apache License, Version 2.0 (the "License”);
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_profile_tracker"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:max="60"
android:indeterminateOnly="false"
android:progressDrawable="@drawable/progress_bar_horizontal" />
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
~
~ Licensed under the Apache License, Version 2.0 (the "License”);
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<drawable name="progress_bar_bg">#00000000</drawable>
<drawable name="sr_primary">#2B3238</drawable>
<drawable name="sr_primary_r">#002444</drawable>
</resources>
\ No newline at end of file
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