接入微信支付,微信提现

This commit is contained in:
fengjignqi
2026-08-12 08:32:42 +08:00
parent f3006f4255
commit 499673782c
22 changed files with 110 additions and 2310 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -155,6 +155,7 @@ object ActionCode {
"找回支付密码" -> url = "/app/setting/payPassword/reset" "找回支付密码" -> url = "/app/setting/payPassword/reset"
"查询支付密码状态" -> url = "/app/setting/payPassword/status" "查询支付密码状态" -> url = "/app/setting/payPassword/status"
"订单支付" -> url = "/app/order/pay" "订单支付" -> url = "/app/order/pay"
"取消待支付订单" -> url = "/app/order/cancelPending"
"修改个人信息" -> url = "/app/profile/update" "修改个人信息" -> url = "/app/profile/update"
@@ -178,6 +179,7 @@ object ActionCode {
"绑定微信" -> url = "/app/profile/wx/bind" "绑定微信" -> url = "/app/profile/wx/bind"
} }
TTLog.e(url) TTLog.e(url)
return url; return url;

View File

@@ -4,4 +4,10 @@ class WithDrawModel {
var amount :String? = "" var amount :String? = ""
var payMethod :String? = "" var payMethod :String? = ""
var authPackageInfo :String? = null
var thirdOrderNo :String? = null
var outBillNo :String? = null
var mchId :String? = null
var appId :String? = null
var needConfirm :Boolean = false
} }

View File

@@ -108,7 +108,7 @@ class RechargeActivity : CKBaseActivity() {
GlobalScope.launch(Dispatchers.IO){ GlobalScope.launch(Dispatchers.IO){
// [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。 // [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。
if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX) // EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX)
} }
val alipay = PayTask(this@RechargeActivity) val alipay = PayTask(this@RechargeActivity)
val result = alipay.payV2(model?.orderStr, true) val result = alipay.payV2(model?.orderStr, true)

View File

@@ -20,11 +20,17 @@ import com.google.gson.Gson
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import com.tt.kit.model.Data import com.tt.kit.model.Data
import com.tt.kit.model.DataCollection import com.tt.kit.model.DataCollection
import com.tt.kit.utils.LiveDataBus
import com.tencent.mm.opensdk.modelbiz.WXOpenBusinessView
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.ck.ckcollar.app.utils.Const
import java.net.URLEncoder
import java.math.BigDecimal import java.math.BigDecimal
class WithDrawActivity : CKLHBaseActionBarActivity() { class WithDrawActivity : CKLHBaseActionBarActivity() {
lateinit var binding: ActivityWithdrawBinding lateinit var binding: ActivityWithdrawBinding
var model : BalanceModle? = null var model : BalanceModle? = null
private var pendingWithdraw: WithDrawModel? = null
var payType = "0" var payType = "0"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -39,6 +45,14 @@ class WithDrawActivity : CKLHBaseActionBarActivity() {
} }
override fun initView() { override fun initView() {
LiveDataBus.get().with(WX_WITHDRAW_RESULT, Int::class.java).observe(this) { resultCode ->
val withdraw = pendingWithdraw ?: return@observe
if (resultCode == 0) {
showWithdrawSuccess(withdraw)
} else {
toast(if (resultCode == -2) "已取消微信收款确认" else "微信提现确认失败")
}
}
binding.btnAli.setOnClickListener { binding.btnAli.setOnClickListener {
binding.image1.setImageResource(R.mipmap.image_address_check_select) binding.image1.setImageResource(R.mipmap.image_address_check_select)
@@ -91,14 +105,13 @@ class WithDrawActivity : CKLHBaseActionBarActivity() {
add(TTRequestData("payType", payType)) add(TTRequestData("payType", payType))
}, object : ICallback { }, object : ICallback {
override fun onSuccess(data: String) { override fun onSuccess(data: String) {
val withdraw = Gson().fromJson(data, WithDrawModel::class.java)
var model = Gson().fromJson<WithDrawModel>(data, WithDrawModel::class.java) pendingWithdraw = withdraw
toActivity(WithDrawSuccessActivity::class.java, DataCollection().apply { if (withdraw.needConfirm && "0" == payType) {
add(Data("data", Gson().toJson(model))) openWeChatTransferConfirm(withdraw)
} else {
}) showWithdrawSuccess(withdraw)
}
finish()
} }
@@ -110,6 +123,52 @@ class WithDrawActivity : CKLHBaseActionBarActivity() {
} }
private fun openWeChatTransferConfirm(withdraw: WithDrawModel) {
val mchId = withdraw.mchId
val appId = withdraw.appId
val packageInfo = withdraw.authPackageInfo
if (mchId.isNullOrBlank() || appId.isNullOrBlank() || packageInfo.isNullOrBlank()) {
toast("微信收款确认参数不完整")
return
}
if (appId != Const.WX_APP_ID) {
toast("微信支付 AppID 不匹配")
return
}
val api = WXAPIFactory.createWXAPI(this, Const.WX_APP_ID, true)
api.registerApp(Const.WX_APP_ID)
if (!api.isWXAppInstalled) {
toast("请先安装微信")
return
}
if (api.wxAppSupportAPI < 0x28002d33) {
toast("当前微信版本过低,请升级微信")
return
}
val request = WXOpenBusinessView.Req().apply {
businessType = "requestMerchantTransfer"
query = "mchId=${URLEncoder.encode(mchId, "UTF-8")}" +
"&appId=${URLEncoder.encode(appId, "UTF-8")}" +
"&package=${URLEncoder.encode(packageInfo, "UTF-8")}"
}
if (!api.sendReq(request)) {
toast("微信收款确认页拉起失败")
}
}
private fun showWithdrawSuccess(withdraw: WithDrawModel) {
toActivity(WithDrawSuccessActivity::class.java, DataCollection().apply {
add(Data("data", Gson().toJson(withdraw)))
})
finish()
}
companion object {
const val WX_WITHDRAW_RESULT = "wx_withdraw_result"
}
fun getBalanceInfo(){ fun getBalanceInfo(){
TTHttpClient.get(this,"余额", TTRequestParam(),object : ICallback{ TTHttpClient.get(this,"余额", TTRequestParam(),object : ICallback{

View File

@@ -242,7 +242,7 @@ class OpenMemberActivity : CKLHBaseActionBarActivity() {
GlobalScope.launch(Dispatchers.IO){ GlobalScope.launch(Dispatchers.IO){
// [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。 // [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。
if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX) // EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX)
} }
val alipay = PayTask(this@OpenMemberActivity) val alipay = PayTask(this@OpenMemberActivity)
val result = alipay.payV2(orderStr, true) val result = alipay.payV2(orderStr, true)

View File

@@ -411,7 +411,7 @@ class PayOrderActivity : CKBaseActivity() {
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
// [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。 // [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。
if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX) // EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX)
} }
val alipay = PayTask(this@PayOrderActivity) val alipay = PayTask(this@PayOrderActivity)
val result = alipay.payV2(orderStr, true) val result = alipay.payV2(orderStr, true)

View File

@@ -337,6 +337,7 @@ class OrderActivity : CKBaseActivity() {
toActivity(OrderSuccessActivity::class.java, DataCollection()) toActivity(OrderSuccessActivity::class.java, DataCollection())
finish() finish()
} }
@@ -361,7 +362,7 @@ class OrderActivity : CKBaseActivity() {
// [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。 // [支付宝沙箱测试] 仅 Debug 包启用Release 包继续使用正式环境。
if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) { if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX) // EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX)
} }
val alipay = PayTask(this@OrderActivity) val alipay = PayTask(this@OrderActivity)
val result = alipay.payV2(orderStr, true) val result = alipay.payV2(orderStr, true)

View File

@@ -78,7 +78,9 @@ object TTHttpClient {
val string = response.body?.string() val string = response.body?.string()
string?.let { TTLog.e("response", actionCode + "====" + it) } string?.let { TTLog.e("response", actionCode + "====" + it) }
var model = JSONObject(string) var model = JSONObject(string)
if (isSusscee(model)) { // A withdrawal code of 201 means the transfer bill was created
// and the client must continue with WeChat confirmation.
if (isSusscee(model) || (actionCode == "提现" && getCode(model) == "201")) {
activity.runOnUiThread { activity.runOnUiThread {
activity.hiddenProgeassDialog() activity.hiddenProgeassDialog()
iCallback.onSuccess(getData(model)) iCallback.onSuccess(getData(model))
@@ -137,7 +139,10 @@ object TTHttpClient {
val string = response.body?.string() val string = response.body?.string()
string?.let { TTLog.e("response", actionCode + "====" + it) } string?.let { TTLog.e("response", actionCode + "====" + it) }
var model = JSONObject(string) var model = JSONObject(string)
if (isSusscee(model)) { // code 201 means the withdrawal bill was created and the
// client must continue with WeChat confirmation. Keep the
// response data available to the withdrawal screen.
if (isSusscee(model) || (actionCode == "提现" && getCode(model) == "201")) {
activity.runOnUiThread { activity.runOnUiThread {
activity.hiddenProgeassDialog() activity.hiddenProgeassDialog()
iCallback.onSuccess(getData(model)) iCallback.onSuccess(getData(model))

View File

@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.ck.ckcollar.app.CKApp import com.ck.ckcollar.app.CKApp
import com.ck.ckcollar.app.ui.act.balance.WithDrawActivity
import com.ck.ckcollar.app.ui.act.login.LoginActivity import com.ck.ckcollar.app.ui.act.login.LoginActivity
import com.ck.ckcollar.app.ui.act.user.UserInfoActivity import com.ck.ckcollar.app.ui.act.user.UserInfoActivity
import com.ck.ckcollar.app.utils.Const import com.ck.ckcollar.app.utils.Const
@@ -15,6 +16,7 @@ import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.tencent.mm.opensdk.openapi.WXAPIFactory import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.tt.kit.utils.TTLog import com.tt.kit.utils.TTLog
import com.tt.kit.utils.LiveDataBus
class WXEntryActivity : Activity(), IWXAPIEventHandler { class WXEntryActivity : Activity(), IWXAPIEventHandler {
@@ -43,6 +45,13 @@ class WXEntryActivity : Activity(), IWXAPIEventHandler {
} }
override fun onResp(resp: BaseResp?) { override fun onResp(resp: BaseResp?) {
if (resp?.type == ConstantsAPI.COMMAND_OPEN_BUSINESS_VIEW) {
LiveDataBus.get()
.with(WithDrawActivity.WX_WITHDRAW_RESULT)
.value = resp.errCode
finish()
return
}
if (resp!!.getType() === ConstantsAPI.COMMAND_SENDAUTH) { if (resp!!.getType() === ConstantsAPI.COMMAND_SENDAUTH) {
val authResp = resp as SendAuth.Resp val authResp = resp as SendAuth.Resp
val code = authResp.code val code = authResp.code

View File

@@ -8,6 +8,8 @@ import com.ck.ckcollar.app.ui.act.balance.RechargeActivity
import com.ck.ckcollar.app.utils.Const import com.ck.ckcollar.app.utils.Const
import com.tencent.mm.opensdk.modelbase.BaseReq import com.tencent.mm.opensdk.modelbase.BaseReq
import com.tencent.mm.opensdk.modelbase.BaseResp import com.tencent.mm.opensdk.modelbase.BaseResp
import com.tencent.mm.opensdk.constants.ConstantsAPI
import com.ck.ckcollar.app.ui.act.balance.WithDrawActivity
import com.tencent.mm.opensdk.openapi.IWXAPI import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
import com.tencent.mm.opensdk.openapi.WXAPIFactory import com.tencent.mm.opensdk.openapi.WXAPIFactory
@@ -32,6 +34,11 @@ class WXPayEntryActivity : Activity(), IWXAPIEventHandler {
override fun onResp(resp: BaseResp?) { override fun onResp(resp: BaseResp?) {
val resultCode = resp?.errCode ?: -1 val resultCode = resp?.errCode ?: -1
if (resp?.type == ConstantsAPI.COMMAND_OPEN_BUSINESS_VIEW) {
LiveDataBus.get().with(WithDrawActivity.WX_WITHDRAW_RESULT).value = resultCode
finish()
return
}
val message = when (resultCode) { val message = when (resultCode) {
BaseResp.ErrCode.ERR_OK -> "微信支付成功" BaseResp.ErrCode.ERR_OK -> "微信支付成功"
BaseResp.ErrCode.ERR_USER_CANCEL -> "已取消微信支付" BaseResp.ErrCode.ERR_USER_CANCEL -> "已取消微信支付"

View File

@@ -183,7 +183,7 @@
android:layout_marginTop="50dp" android:layout_marginTop="50dp"
android:background="@drawable/bg_login_button" android:background="@drawable/bg_login_button"
android:text="@string/apply_withdraw" android:text="@string/apply_withdraw"
android:textColor="@color/buttonTextColor"></com.ck.ckcollar.app.widget.CKButton> android:textColor="@color/buttonTextColor"/>
</com.ck.ckcollar.app.widget.CKLinearLayout> </com.ck.ckcollar.app.widget.CKLinearLayout>

View File

@@ -9,19 +9,19 @@
android:layout_marginTop="200dp"> android:layout_marginTop="200dp">
<ImageView <ImageView
android:id="@+id/img_noresult" android:id="@+id/img_noresult"
android:layout_width="120dp" android:layout_width="wrap_content"
android:layout_height="120dp" android:layout_height="150dp"
android:src="@mipmap/icon_no_result" android:src="@mipmap/icon_no_result"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/> android:layout_centerHorizontal="true"/>
<TextView <TextView
android:id="@+id/tv_noresult" android:id="@+id/tv_noresult"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/img_noresult"
android:layout_marginTop="50dp"
android:textSize="14sp" android:textSize="14sp"
android:textColor="@color/color_999999" android:textColor="@color/color_999999"
android:text="暂无结果" android:text="暂无结果"
android:layout_below="@+id/img_noresult"
android:layout_centerHorizontal="true"/> android:layout_centerHorizontal="true"/>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB