lmw
2024-11-26 b8d8f9b855fdd453d06d78d2565f091db208ec8e
app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt
@@ -22,6 +22,7 @@
import kotlinx.android.synthetic.main.activity_vip.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.backgroundResource
import org.jetbrains.anko.browse
import org.jetbrains.anko.toast
class VipActivity : TransparentStatusBarActivity(), PayListener {
@@ -29,6 +30,7 @@
    private val price = arrayListOf<Double>()
    private val adapter = VipPriceAdapter(price)
    private var orderId = ""
    override fun initClick() {
        iv_back.setOnClickListener { finish() }
@@ -55,16 +57,11 @@
                    override fun onResult(rst: String) {
                        HttpManager.placeOrder(3,rst.toInt(),2,price[adapter.checked],null,null,adapter.checked+1 )
                            .request(this@VipActivity){_,data->
                                if (rst == "1"){
                                    PayUtil.initWeChatPay(this@VipActivity,Const.WX_APP_ID)
                                    PayUtil.weChatPay(data!!)
                                }else{
                                    PayUtil.aliPay(this@VipActivity,data?.orderInfo?:"")
                                    tv_action.postDelayed({ //TEST CALLBACK
                                        onPaySuccess()
                                    },3000)
                                }
                                orderId = data?.orderId?:""
                                if (rst == "1")
                                    data?.jumpToWx(this@VipActivity)
                                else
                                    browse(data?.qrcodeUrl?:"")
                            }
                    }
                },enableBalance = false)
@@ -137,6 +134,26 @@
        }
    }
    private fun checkPayStatus(){
        if (!orderId.isNullOrEmpty()){
            HttpManager.queryPayment(orderId).request(this){_,data->
                when(data){
                    "pending"->{
                        toast("未查询到支付结果,如已付款请忽略")
                    }
                    "succeeded"->{
                        toast("支付成功")
                        onPaySuccess()
                    }
                    "failed"->{
                        toast("支付失败")
                    }
                }
            }
            orderId = ""
        }
    }
    override fun onDestroy() {
        super.onDestroy()
        PayUtil.unregisterApp()
@@ -153,4 +170,9 @@
    override fun onPayError(msg: String) {
    }
    override fun onResume() {
        super.onResume()
        checkPayStatus()
    }
}