From 718f31c92e2029d05260810435a2c70cef6e6ce5 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期四, 24 四月 2025 10:45:55 +0800
Subject: [PATCH] save

---
 app/src/main/java/com/sinata/xqmuse/ui/mine/RechargeActivity.kt |   62 +++++++++++++++++++------------
 1 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/app/src/main/java/com/sinata/xqmuse/ui/mine/RechargeActivity.kt b/app/src/main/java/com/sinata/xqmuse/ui/mine/RechargeActivity.kt
index b6c6cd8..074deff 100644
--- a/app/src/main/java/com/sinata/xqmuse/ui/mine/RechargeActivity.kt
+++ b/app/src/main/java/com/sinata/xqmuse/ui/mine/RechargeActivity.kt
@@ -4,39 +4,32 @@
 import android.content.Intent
 import android.text.Editable
 import android.text.TextWatcher
-import androidx.recyclerview.widget.GridLayoutManager
-import cn.sinata.xldutils.utils.LengthFilter
-import cn.sinata.xldutils.utils.SpanBuilder
 import cn.sinata.xldutils.utils.myToast
 import com.sinata.xqmuse.R
 import com.sinata.xqmuse.dialog.PayDialog
 import com.sinata.xqmuse.network.HttpManager
-import com.sinata.xqmuse.network.entity.RechargeItem
 import com.sinata.xqmuse.network.request
-import com.sinata.xqmuse.ui.H5Activity
 import com.sinata.xqmuse.ui.TransparentStatusBarActivity
-import com.sinata.xqmuse.ui.home.PayResultActivity
-import com.sinata.xqmuse.ui.mine.adapter.RechargeAdapter
 import com.sinata.xqmuse.utils.Const
 import com.sinata.xqmuse.utils.NumberInputFilter
 import com.sinata.xqmuse.utils.event.EmptyEvent
-import com.sinata.xqmuse.utils.extention.clickDelay
 import com.sinata.xqmuse.utils.interfaces.StringCallback
 import com.sinata.xqmuse.utils.pay.PayListener
 import com.sinata.xqmuse.utils.pay.PayUtil
 import kotlinx.android.synthetic.main.activity_recharge.*
 import org.greenrobot.eventbus.EventBus
+import org.jetbrains.anko.browse
 import org.jetbrains.anko.sdk27.coroutines.onClick
 import org.jetbrains.anko.startActivity
-import org.jetbrains.anko.startActivityForResult
 import org.jetbrains.anko.toast
 import java.lang.Exception
 
 class RechargeActivity : TransparentStatusBarActivity(),PayListener {
     override fun setContentView() = R.layout.activity_recharge
 
-    private var way = 1
+    private var way = 2
     private var money = 0.0
+    private var orderId = ""
 
     override fun initClick() {
         tv_way.setOnClickListener {
@@ -86,19 +79,36 @@
 
     private fun pay(payType:Int,money:Double){
         toast("%s充值%.2f".format(if (payType == 1) "微信" else "支付宝",money))
-        onPaySuccess()
-//        HttpManager.payCourse(null,payType,3,null,money).request(this){ _, data->
-//            HttpManager.pay(data?.id?:"",payType,3).request(this,false,success = {_,data->
-//                if (payType == 2){
-//                    PayUtil.aliPay(this,data?.orderInfo?:"")
-//                }else{
-//                    PayUtil.initWeChatPay(this,Const.WX_APP_ID)
-//                    PayUtil.weChatPay(data!!)
-//                }
-//            }){_,msg->
-//                startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_RECHARGE_FAILED,"msg" to msg)
-//            }
-//        }
+        HttpManager.placeOrder(4,payType,2,money,null,null,null )
+            .request(this){_,data->
+                orderId = data?.orderId?:""
+                if (payType == 1)
+                    data?.jumpToWx(this)
+                else
+                    browse(data?.qrcodeUrl?:"")
+            }
+    }
+
+    private fun checkPayStatus(){
+        if (!orderId.isNullOrEmpty()){
+            if (!orderId.isNullOrEmpty()){
+                HttpManager.queryPayment(orderId).request(this){_,data->
+                    when(data){
+                        "pending"->{
+                            toast("未查询到支付结果,如已付款请忽略")
+                        }
+                        "succeeded"->{
+                            toast("支付成功")
+                            onPaySuccess()
+                        }
+                        "failed"->{
+                            toast("支付失败")
+                        }
+                    }
+                }
+                orderId = ""
+            }
+        }
     }
 
     override fun onPaySuccess() {
@@ -112,7 +122,11 @@
     }
 
     override fun onPayError(msg: String) {
-        startActivityForResult<PayResultActivity>(1,"type" to PayResultActivity.TYPE_RECHARGE_FAILED)
+    }
+
+    override fun onResume() {
+        super.onResume()
+        checkPayStatus()
     }
 
     override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

--
Gitblit v1.7.1