Commit 4f723dc8 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :测试环境
[实现方案] :完整的Google支付流程
parent 499bc8e1
......@@ -4,8 +4,13 @@ import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
......@@ -40,6 +45,8 @@ import com.zxhl.main.page.view.DiscountDialog;
import com.zxhl.main.page.view.NavigationBottomView;
import com.zxhl.uc.page.fragment.UserCenterFragment;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -121,7 +128,6 @@ public class MainActivity extends BaseActivity implements NavigationBottomView.N
}
});
}
private void initListener() {
......
PACKAGE_NAME=com.zhangxin.magicbox
VERSION_CODE=2
VERSION_NAME=1.0.0
VERSION_CODE=3
VERSION_NAME=1.0.1
......@@ -17,6 +17,9 @@ buildscript {
classpath "com.mob.sdk:MobSDK:2018.0319.1724"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}
}
}
......
......@@ -28,6 +28,7 @@ public class NetConfig {
public static String BASE_FEED_URL = "";
public static final String URL_REPORT_BASE = "http://report.zhangxinhulian.com/";
public static final String HOME_BANNER_BASE_URL = "https://bs.zhangxinhulian.com/";
public static final String URL_PAY_BASE = "http://paytest.zhangxinhulian.com/";
public static void setBase_Url(Environment s) {
sEnvironment = s;
......@@ -146,7 +147,6 @@ public class NetConfig {
public static final String URL_AUTH_GOOGLE_LOGIN = "app/v1/auth/googleLogin";//绑定谷歌登录
public static final String URL_PAY_BASE = "http://pay.linking100.com/";
///unifiedpay/gateway/google/替换包名/notify/order
public static final String URL_GOOGLE_NOTIFY = URL_PAY_BASE +"unifiedpay/gateway/google/com.zhangxin.magicbox/notify/order";
......
package com.zxhl.cms.googlepay
import android.util.Log
import android.view.View
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient.SkuType
import com.ishin.google.bean.GooglePayResult
import com.zxhl.cms.AppContext
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.widget.LoadingDialog
......@@ -34,6 +29,7 @@ class GooglePayActivity : BaseActivity() {
override fun layoutID(): Int {
return R.layout.activity_google_pay
}
private var mLoading: LoadingDialog? = null
override fun init() {
mLoading = LoadingDialog.getLoadingDialog(
......@@ -43,11 +39,12 @@ class GooglePayActivity : BaseActivity() {
false
)
id_btn_google_pay.setOnClickListener {
mLoading?.setLoading(getString(R.string.wait_ing2))
mLoading?.show()
googlePay?.googlePay("0.1", object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult) {
googlePay?.googlePay("box_text_0001_1cent", "6", object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
showToast("success" + purchase.orderId)
mLoading?.setResult(true, "pay success", 1000)
mLoading?.setResult(true, "Pay for success", 1000)
}
override fun onCancel() {
......@@ -62,7 +59,7 @@ class GooglePayActivity : BaseActivity() {
})
}
// startConnection()
googlePay= GooglePayHelper(this)
googlePay = GooglePayHelper(this)
googlePay?.init()
}
......
package com.zxhl.cms.googlepay
import com.ishin.google.bean.GooglePayResult
/**
* @author (wangXuewei)
* @datetime 2022-03-14 16:49 GMT+8
......@@ -9,7 +7,7 @@ import com.ishin.google.bean.GooglePayResult
*/
interface GooglePayCallBack {
fun onPaySuccess(purchase: GooglePayResult)
fun onPaySuccess(purchase: GooglePayResult,googleJson:String)
fun onCancel()
......
......@@ -5,15 +5,12 @@ import android.util.Log
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient.BillingResponseCode
import com.android.billingclient.api.BillingClient.SkuType
import com.ishin.google.bean.GooglePayResult
import com.zxhl.cms.AppContext
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.other.AnyEntity
import com.zxhl.cms.net.model.uc.AliPayEntity
import com.zxhl.cms.net.model.uc.GooglePayEntity
import com.zxhl.cms.pay.alipay.AlipayServer
import com.zxhl.cms.utils.EventUtils
......@@ -48,6 +45,8 @@ class GooglePayHelper {
if (!purchases.isNullOrEmpty()) {
for (i in 0 until purchases.size) {
var purchase = purchases[i];
Log.d(TAG, "detail ${purchase.originalJson}")
Log.d(TAG, "obfuscatedAccountid $obfuscatedAccountid")
var googlePayResult = GooglePayResult()
googlePayResult.packageName = purchase.packageName
googlePayResult.orderId = purchase.orderId
......@@ -57,8 +56,8 @@ class GooglePayHelper {
googlePayResult.purchaseTime = purchase.purchaseTime.toString()
googlePayResult.purchaseState = purchase.purchaseState.toString()
googlePayResult.purchaseToken = purchase.purchaseToken
//同步后台 消耗掉
updateToService(googlePayResult)
//购买成功 消耗掉
consume(googlePayResult, purchase)
}
}
} else if (billingResult.responseCode == BillingResponseCode.ITEM_ALREADY_OWNED) {
......@@ -198,7 +197,7 @@ class GooglePayHelper {
*
* @param purchaseToken 商品token
*/
private fun consume(googlePayResult: GooglePayResult) {
private fun consume(googlePayResult: GooglePayResult, purchase: Purchase) {
if (billingClient.isReady) {
val consumeParams =
ConsumeParams.newBuilder()
......@@ -210,7 +209,8 @@ class GooglePayHelper {
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${googlePayResult.purchaseToken}")
mPayCallBack?.onPaySuccess(googlePayResult)//支付成功
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
......@@ -233,7 +233,10 @@ class GooglePayHelper {
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${googlePayResult.purchaseToken}")
mPayCallBack?.onPaySuccess(googlePayResult)//支付成功
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode)
mPayCallBack?.onError("consume 消耗失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
......@@ -248,7 +251,7 @@ class GooglePayHelper {
override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
mPayCallBack?.onError("consume onBillingServiceDisconnected" )
mPayCallBack?.onError("consume onBillingServiceDisconnected")
}
})
}
......@@ -356,16 +359,17 @@ class GooglePayHelper {
/**
* google支付
*/
fun googlePay(goodsId: String, payCallBack: GooglePayCallBack) {
fun googlePay(goodsId: String,payMode: String, payCallBack: GooglePayCallBack) {
mPayCallBack = payCallBack
//向服务端获取订单ID
ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", "6")
ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", payMode)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<GooglePayEntity>() {
override fun onSuccess(result: GooglePayEntity?) {
if (result != null) {
Log.d(TAG, "请求支付")
purchase("box_text_0001_1cent", result.outTradeNo ?: "")
var sku = goodsId.replace("-", "_")
Log.d(TAG, "请求支付${sku}")
purchase("xymh_$sku", result.outTradeNo ?: "")
} else {
Log.d(TAG, "未获取到订单")
mPayCallBack?.onError("GooglePay 未获取到订单数据")
......@@ -379,29 +383,26 @@ class GooglePayHelper {
})
}
fun updateToService(purchase: GooglePayResult) {
/**
* google支付 成功后 同步给服务器
*/
private fun updateToService(googlePayResult: GooglePayResult, purchase: Purchase) {
//支付成功 向后端同步 网络问题再次重试
ApiClient.userInfoAPi.googlePaySuccess(
purchase.packageName,
purchase.orderId,
purchase.productId,
purchase.developerPayload,
purchase.obfuscatedAccountid,
purchase.purchaseTime,
purchase.purchaseState,
purchase.purchaseToken
).compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<AnyEntity?>() {
override fun onSuccess(result: AnyEntity?) {
ApiClient.shopApi.googlePaySuccess(googlePayResult)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<Any>() {
override fun onSuccess(result: Any?) {
EventUtils.onEvent("googlepaysuccess_onsuccess")
mPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//支付成功
if (result != null) {
}
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}")
mPayCallBack?.onError("服务器同步失败 code:$code msg:$errorMsg")
}
})
//同步成功 消耗掉
consume(purchase)
}
......
package com.ishin.google.bean
package com.zxhl.cms.googlepay
class GooglePayResult {
......
......@@ -2,6 +2,8 @@ package com.zxhl.cms.net.api
import com.zxhl.cms.ad.upload.model.Response
import com.zxhl.cms.common.NetConfig
import com.zxhl.cms.googlepay.GooglePayResult
import com.zxhl.cms.net.model.box.AddressEntity
import com.zxhl.cms.net.model.shop.ShopEntity
import io.reactivex.Observable
import retrofit2.http.*
......@@ -16,5 +18,12 @@ interface IShopApi {
@Query("category") category: String
): Observable<Response<ShopEntity>>
/**
* google支付成功后 通知后台
*/
@POST(NetConfig.User.URL_GOOGLE_NOTIFY)
fun googlePaySuccess(
@Body entity: GooglePayResult?
): Observable<Response<Any>>
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package com.zxhl.cms.net.api;
import com.zxhl.cms.ad.upload.model.Response;
import com.zxhl.cms.common.NetConfig;
import com.zxhl.cms.googlepay.GooglePayResult;
import com.zxhl.cms.net.model.box.AddressEntity;
import com.zxhl.cms.net.model.other.AnyEntity;
import com.zxhl.cms.net.model.uc.AliPayEntity;
import com.zxhl.cms.net.model.uc.GooglePayEntity;
......@@ -14,6 +16,7 @@ import com.zxhl.cms.net.model.uc.WeChatPayEntity;
import com.zxhl.cms.net.model.video.MemberEntity;
import io.reactivex.Observable;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
......@@ -90,19 +93,6 @@ public interface IUserInfoApi {
@POST(NetConfig.User.URL_PAY_ORDER)
Observable<Response<GooglePayEntity>> googlePay(@Query("goodsId") String goodsId, @Query("payType") String payType, @Query("voucherId") String voucherId, @Query("appId") String appId, @Query("payMode") String payMode);
/**
* google支付成功后 通知后台
*/
@POST(NetConfig.User.URL_GOOGLE_NOTIFY)
Observable<Response<AnyEntity>> googlePaySuccess(
@Query("packageName") String packageName,
@Query("orderId") String orderId,
@Query("productId") String productId,
@Query("developerPayload") String developerPayload,
@Query("obfuscatedAccountid") String obfuscatedAccountid,
@Query("purchaseTime") String purchaseTime,
@Query("purchaseState") String purchaseState,
@Query("purchaseToken") String purchaseToken);
/**
* 商城商品支付宝支付
......
package com.zxhl.cms.net.model.box
import com.umeng.commonsdk.debug.I
class AppInEntity {
var pay_ali: String? = ""
var pay_wx: String? = ""
var pay_google: String = "0"
var pay_paypal: String = "0"
var pay_wx_type: Int? = 0
var feedback_open: String? = ""
var depots_text: String? = ""
......
......@@ -81,14 +81,22 @@ class PayPresenter : PayContract.Presenter {
goodIds: String,
orderNotes: String
) {
ApiClient.userInfoAPi.shopwechatPay(goodsId, payType, payMode, addressId, discount,goodIds,orderNotes)
ApiClient.userInfoAPi.shopwechatPay(
goodsId,
payType,
payMode,
addressId,
discount,
goodIds,
orderNotes
)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<WeChatPayEntity>() {
override fun onSuccess(result: WeChatPayEntity?) {
if (result != null) {
EventUtils.onEvent("member_page_pay_get_order_suc")
mView?.setOrderNo(result?.outTradeNo)
WeChatPay.startWeChatPay(result,payType)
WeChatPay.startWeChatPay(result, payType)
mView?.requestOrderSuc()
} else {
EventUtils.onEvent("member_page_pay_get_order_fail")
......@@ -113,7 +121,15 @@ class PayPresenter : PayContract.Presenter {
goodIds: String,
orderNotes: String
) {
ApiClient.userInfoAPi.shopaliPay(goodsId, payType, payMode, addressId, discount,goodIds,orderNotes)
ApiClient.userInfoAPi.shopaliPay(
goodsId,
payType,
payMode,
addressId,
discount,
goodIds,
orderNotes
)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<AliPayEntity>() {
override fun onSuccess(result: AliPayEntity?) {
......@@ -143,7 +159,7 @@ class PayPresenter : PayContract.Presenter {
EventUtils.onEvent("member_page_pay_get_order_suc")
mView?.setOrderNo(result?.outTradeNo)
SettingPreference.setOutTradeNo(result?.outTradeNo)
WeChatPay.startWeChatProgromPay(result,payType)
WeChatPay.startWeChatProgromPay(result, payType)
mView?.requestOrderSuc()
} else {
EventUtils.onEvent("member_page_pay_get_order_fail")
......@@ -167,7 +183,7 @@ class PayPresenter : PayContract.Presenter {
if (result != null) {
EventUtils.onEvent("member_page_pay_get_order_suc")
mView?.setOrderNo(result?.outTradeNo)
WeChatPay.startWeChatPay(result,payType)
WeChatPay.startWeChatPay(result, payType)
mView?.requestOrderSuc()
} else {
EventUtils.onEvent("member_page_pay_get_order_fail")
......@@ -227,10 +243,15 @@ class PayPresenter : PayContract.Presenter {
if (!TextUtils.isEmpty(order)) {
requestVerify(order ?: "", "", payType)
}
}else if(payType==12){
} else if (payType == 12) {
if (!TextUtils.isEmpty(order)) {
requestVerify(order ?: "", "", payType)
}
} else if (payType == 4) {
val googleJson = JSONObject(order)
val tradeOrder = googleJson.optString("orderId") ?: ""
val outTradeOrder = googleJson.optString("obfuscatedAccountId") ?: ""
requestVerify(outTradeOrder, tradeOrder, payType)
}
} catch (e: Exception) {
mView?.verifyOrderFail()
......@@ -250,7 +271,6 @@ class PayPresenter : PayContract.Presenter {
} else {
EventUtils.onEvent("member_page_pay_query_order_fail", result.toString())
mView?.verifyOrderFail()
}
}
......
......@@ -83,7 +83,7 @@
android:background="@drawable/shape_need_price_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible">
android:visibility="gone">
<TextView
android:id="@+id/id_tv_need"
......@@ -130,7 +130,7 @@
android:layout_below="@+id/id_ll_content"
android:background="@drawable/shape_white_r5"
android:orientation="vertical">
<!--微信-->
<RelativeLayout
android:id="@+id/id_rl_wechat_pay"
android:layout_width="match_parent"
......@@ -159,7 +159,7 @@
android:layout_marginRight="15dp"
android:src="@drawable/icon_xuanzhong_default" />
</RelativeLayout>
<!--支付宝-->
<RelativeLayout
android:id="@+id/id_rl_zfb_pay"
android:layout_width="match_parent"
......@@ -187,6 +187,63 @@
android:layout_marginRight="15dp"
android:src="@drawable/icon_xuanzhong_default" />
</RelativeLayout>
<!--Google-->
<RelativeLayout
android:id="@+id/id_rl_google_pay"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:drawableLeft="@drawable/icon_google"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:text="@string/pay_google"
android:textColor="@color/color_333333"
android:textSize="14sp" />
<ImageView
android:id="@+id/id_img_google"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="@drawable/icon_xuanzhong_default" />
</RelativeLayout>
<!--PayPal-->
<RelativeLayout
android:id="@+id/id_rl_paypal_pay"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:drawableLeft="@drawable/zhifub"
android:drawablePadding="5dp"
android:text="@string/pay_paypal"
android:textColor="@color/color_333333"
android:textSize="14sp" />
<ImageView
android:id="@+id/id_img_paypal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="@drawable/icon_xuanzhong_default" />
</RelativeLayout>
</LinearLayout>
<!-- 支付按钮-->
......@@ -244,7 +301,7 @@
android:layout_marginTop="10dp"
android:layout_marginBottom="30dp"
android:gravity="center"
android:visibility="visible">
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
......@@ -302,8 +359,9 @@
<com.paypal.checkout.paymentbutton.PayPalButton
android:id="@+id/id_PayPal_btn"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-100dp"
android:visibility="gone" />
</RelativeLayout>
\ No newline at end of file
......@@ -44,7 +44,7 @@
<string name="recycle_desc2">You can exchange high-value goods</string>
<string name="empty_trip">Empty,go open some boxes</string>
//请选择要发货的商品
<string name="select_deliver">Please select the goods you want to deliver</string>
<string name="select_deliver">please select the goods to be shipped</string>
//请选择要回收的商品
<string name="select_reclaim">Please select the goods you want to reclaim</string>
<string name="recycle_suc">Reclaim successful</string>
......@@ -120,6 +120,8 @@
<string name="pay_button">Top-up</string>
<string name="pay_wechat">微信支付</string>
<string name="pay_zfb">支付宝支付</string>
<string name="pay_google">GooglePay</string>
<string name="pay_paypal">PayPal</string>
<string name="pay_need_desc">Needed:</string>
<!-- 填写地址-->
......
......@@ -99,6 +99,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:text=""
android:textColor="@color/color_333333"
android:textSize="14sp" />
......@@ -109,6 +110,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:text=""
android:textColor="@color/color_666666"
android:textSize="14sp" />
......@@ -119,6 +121,9 @@
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="@string/box_detail_open_box_result_re_pumping_desc"
android:textColor="@color/color_4C84FF"
android:textSize="14sp"
......
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