Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
M
magicbox
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王雪伟
magicbox
Commits
f698e9cf
Commit
f698e9cf
authored
Mar 14, 2022
by
王雪伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[提交人]:王雪伟
[提交简述] :加入googlePay工具类 [实现方案] :生成订单ID 调起Google支付
parent
581ac570
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
220 additions
and
32 deletions
+220
-32
NetConfig.java
cms/src/main/java/com/zxhl/cms/common/NetConfig.java
+6
-0
GooglePayActivity.kt
...src/main/java/com/zxhl/cms/googlepay/GooglePayActivity.kt
+21
-1
GooglePayCallBack.kt
...src/main/java/com/zxhl/cms/googlepay/GooglePayCallBack.kt
+18
-0
GooglePayHelper.kt
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayHelper.kt
+78
-31
GooglePayResult.kt
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayResult.kt
+13
-0
IUserInfoApi.java
cms/src/main/java/com/zxhl/cms/net/api/IUserInfoApi.java
+22
-0
GooglePayEntity.java
.../main/java/com/zxhl/cms/net/model/uc/GooglePayEntity.java
+61
-0
activity_google_pay.xml
cms/src/main/res/layout/activity_google_pay.xml
+1
-0
No files found.
cms/src/main/java/com/zxhl/cms/common/NetConfig.java
View file @
f698e9cf
...
...
@@ -144,6 +144,12 @@ public class NetConfig {
public
static
final
String
USER_PHONE_CODE_LOGIN
=
"app/v3/auth/phoneCodeLogin"
;
//验证码登录
public
static
final
String
URL_VERSION
=
"app/v1/version"
;
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"
;
}
public
static
class
Task
{
...
...
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayActivity.kt
View file @
f698e9cf
...
...
@@ -4,6 +4,7 @@ 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
...
...
@@ -28,16 +29,35 @@ class GooglePayActivity : BaseActivity() {
}
var
googlePay
:
GooglePayHelper
?
=
null
override
fun
layoutID
():
Int
{
return
R
.
layout
.
activity_google_pay
}
override
fun
init
()
{
id_btn_google_pay
.
setOnClickListener
{
googlePay
?.
googlePay
(
"0.1"
,
object
:
GooglePayCallBack
{
override
fun
onPaySuccess
(
purchase
:
GooglePayResult
)
{
showToast
(
"success"
+
purchase
.
orderId
)
}
override
fun
onCancel
()
{
showToast
(
"onCancel"
)
}
override
fun
onError
(
error
:
String
)
{
showToast
(
"onError$error"
)
}
})
}
// startConnection()
GooglePayHelper
(
this
,
""
).
init
()
googlePay
=
GooglePayHelper
(
this
)
googlePay
?.
init
()
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
googlePay
?.
release
()
}
//
//
...
...
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayCallBack.kt
0 → 100644
View file @
f698e9cf
package
com.zxhl.cms.googlepay
import
com.ishin.google.bean.GooglePayResult
/**
* @author (wangXuewei)
* @datetime 2022-03-14 16:49 GMT+8
* @detail :
*/
interface
GooglePayCallBack
{
fun
onPaySuccess
(
purchase
:
GooglePayResult
)
fun
onCancel
()
fun
onError
(
error
:
String
)
}
\ No newline at end of file
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayHelper.kt
View file @
f698e9cf
...
...
@@ -5,11 +5,13 @@ 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.uc.AliPayEntity
import
com.zxhl.cms.net.model.uc.GooglePayEntity
import
com.zxhl.cms.pay.alipay.AlipayServer
import
com.zxhl.cms.utils.EventUtils
...
...
@@ -22,11 +24,14 @@ import com.zxhl.cms.utils.EventUtils
class
GooglePayHelper
{
private
val
TAG
=
"GooglePayHelper"
private
var
mActivity
:
Activity
;
private
var
mSku
:
String
=
"box0001"
private
var
mSku
:
String
=
"box_text_0001_1cent"
private
var
mPayCallBack
:
GooglePayCallBack
?
=
null
;
private
var
mConsume
:
String
=
"2"
private
var
productId
=
""
private
var
obfuscatedAccountid
=
""
constructor
(
mActivity
:
Activity
,
mSku
:
String
)
{
constructor
(
mActivity
:
Activity
)
{
this
.
mActivity
=
mActivity
// this.mSku = mSku
}
/**
...
...
@@ -38,17 +43,34 @@ class GooglePayHelper {
Log
.
d
(
TAG
,
"购买监听 code ${billingResult.responseCode}"
)
Log
.
d
(
TAG
,
"购买监听 size ${purchases?.size}"
)
if
(
billingResult
.
responseCode
==
BillingResponseCode
.
OK
)
{
mConsume
=
"2"
//支付成功 同步后台
if
(!
purchases
.
isNullOrEmpty
())
{
for
(
i
in
0
until
purchases
.
size
)
{
updateToService
()
var
purchase
=
purchases
[
i
];
var
googlePayResult
=
GooglePayResult
()
googlePayResult
.
packageName
=
purchase
.
packageName
googlePayResult
.
orderId
=
purchase
.
orderId
googlePayResult
.
productId
=
productId
googlePayResult
.
obfuscatedAccountid
=
obfuscatedAccountid
googlePayResult
.
developerPayload
=
purchase
.
developerPayload
googlePayResult
.
purchaseTime
=
purchase
.
purchaseTime
.
toString
()
googlePayResult
.
purchaseState
=
purchase
.
purchaseState
.
toString
()
googlePayResult
.
purchaseToken
=
purchase
.
purchaseToken
mPayCallBack
?.
onPaySuccess
(
googlePayResult
)
//支付成功
//同步后台 消耗掉
updateToService
(
purchase
.
purchaseToken
)
}
}
}
else
if
(
billingResult
.
responseCode
==
BillingResponseCode
.
ITEM_ALREADY_OWNED
)
{
//未消耗掉
//
mConsume = "1"
mConsume
=
"1"
queryPurchases
()
mPayCallBack
?.
onError
(
"商品未消耗掉 查询补单"
)
}
else
if
(
billingResult
.
responseCode
==
BillingResponseCode
.
USER_CANCELED
)
{
mPayCallBack
?.
onCancel
()
}
else
{
mPayCallBack
?.
onError
(
"支付异常: code:"
+
billingResult
.
responseCode
+
" msg:"
+
billingResult
.
debugMessage
)
when
(
billingResult
.
responseCode
)
{
BillingResponseCode
.
SERVICE_TIMEOUT
->
{
//服务连接超时
...
...
@@ -89,11 +111,12 @@ class GooglePayHelper {
.
enablePendingPurchases
()
.
build
()
//检查之前的商品是否被消费
fun
init
()
{
//已经连接查询订单
if
(
billingClient
.
isReady
)
{
Log
.
d
(
TAG
,
"init 已连接"
)
getOrderId
()
queryPurchases
()
}
else
{
//开始连接
Log
.
d
(
TAG
,
"init 开始连接"
)
...
...
@@ -102,9 +125,10 @@ class GooglePayHelper {
if
(
billingResult
.
responseCode
==
BillingResponseCode
.
OK
)
{
//BillingClient准备好了。你可以在这里查询购买情况。
Log
.
d
(
TAG
,
"init 连接成功"
)
getOrderId
()
queryPurchases
()
}
else
{
Log
.
d
(
TAG
,
"init 连接失败 code:"
+
billingResult
.
responseCode
)
mPayCallBack
?.
onError
(
"初始化连接失败 code:"
+
billingResult
.
responseCode
+
" msg:"
+
billingResult
.
debugMessage
)
}
}
...
...
@@ -112,6 +136,7 @@ class GooglePayHelper {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
Log
.
d
(
TAG
,
"init onBillingServiceDisconnected"
)
mPayCallBack
?.
onError
(
"初始化连接失败 onBillingServiceDisconnected"
)
}
})
}
...
...
@@ -121,10 +146,11 @@ class GooglePayHelper {
/**
* 购买商品
*/
private
fun
purchase
()
{
private
fun
purchase
(
sku
:
String
,
orderId
:
String
)
{
mSku
=
sku
if
(
billingClient
.
isReady
)
{
val
skuList
:
MutableList
<
String
>
=
ArrayList
()
skuList
.
add
(
mS
ku
)
skuList
.
add
(
s
ku
)
val
params
=
SkuDetailsParams
.
newBuilder
()
params
.
setSkusList
(
skuList
).
setType
(
SkuType
.
INAPP
)
billingClient
.
querySkuDetailsAsync
(
...
...
@@ -140,7 +166,7 @@ class GooglePayHelper {
val
flowParams
=
BillingFlowParams
.
newBuilder
()
.
setSkuDetails
(
skuDetails
)
// .setObfuscatedProfileId()
// .setObfuscatedAccountId(
)
.
setObfuscatedAccountId
(
orderId
)
.
build
()
//吊起支付
val
responseCode
=
...
...
@@ -154,11 +180,15 @@ class GooglePayHelper {
}
else
{
Log
.
d
(
TAG
,
"purchase 未查询到商品"
)
mPayCallBack
?.
onError
(
"GooglePay 商品未查询到"
)
}
}
else
{
Log
.
d
(
TAG
,
"purchase 查询连接失败 cede"
+
billingResult
.
responseCode
)
mPayCallBack
?.
onError
(
"GooglePay error code:"
+
billingResult
.
responseCode
+
" msg:"
+
billingResult
.
debugMessage
)
}
}
}
else
{
Log
.
d
(
TAG
,
"purchase 购买 未连接"
)
}
}
...
...
@@ -230,21 +260,14 @@ class GooglePayHelper {
}
else
{
for
(
i
in
0
until
mutableList
.
size
)
{
Log
.
d
(
TAG
,
"queryPurchases init "
+
mutableList
[
i
].
purchaseState
)
if
(
mutableList
[
i
].
isAcknowledged
)
{
//已
确认/已验证
,消耗即可
if
(
mutableList
[
i
].
purchaseState
==
Purchase
.
PurchaseState
.
PURCHASED
)
{
//已
购买
,消耗即可
consume
(
mutableList
[
i
].
purchaseToken
)
if
(
mutableList
[
i
].
purchaseState
==
Purchase
.
PurchaseState
.
PURCHASED
)
{
}
}
else
{
//后端同步
//支付成功后 google回调没有收到 再次检查 后端同步
}
}
}
}
else
{
Log
.
d
(
TAG
,
"queryPurchases
null"
)
Log
.
d
(
TAG
,
"queryPurchases
error code"
+
billingResult
.
responseCode
)
}
}
}
else
{
...
...
@@ -268,28 +291,50 @@ class GooglePayHelper {
}
fun
getOrderId
()
{
/**
* google支付
*/
fun
googlePay
(
goodsId
:
String
,
payCallBack
:
GooglePayCallBack
)
{
mPayCallBack
=
payCallBack
//向服务端获取订单ID
ApiClient
.
userInfoAPi
.
aliPay
(
"39"
,
"4"
,
""
,
""
,
"6"
)
ApiClient
.
userInfoAPi
.
googlePay
(
goodsId
,
"4"
,
""
,
""
,
"6"
)
.
compose
(
RxSchedulers
.
observableIO2Main
())
.
subscribe
(
object
:
BaseObserver
<
AliPayEntity
>()
{
override
fun
onSuccess
(
result
:
AliPayEntity
?)
{
.
subscribe
(
object
:
BaseObserver
<
GooglePayEntity
>()
{
override
fun
onSuccess
(
result
:
GooglePayEntity
?)
{
if
(
result
!=
null
)
{
Log
.
d
(
TAG
,
"请求支付"
)
purchase
(
"box_text_0001_1cent"
,
result
.
outTradeNo
?:
""
)
}
else
{
Log
.
d
(
TAG
,
"未获取到订单"
)
}
}
override
fun
onFailure
(
e
:
Throwable
?,
code
:
String
?,
errorMsg
:
String
?)
{
EventUtils
.
onEvent
(
"member_page_pay_get_order_fail"
)
// EventUtils.onEvent("GooglePay Fail:$errorMsg")
mPayCallBack
?.
onError
(
"订单接口 Error:$errorMsg"
)
}
})
purchase
()
}
fun
updateToService
()
{
fun
updateToService
(
purchaseToken
:
String
)
{
//支付成功 向后端同步 网络问题再次重试
// ApiClient.userInfoAPi.googlePaySuccess(pkName, orderId, productId, developerPayload, obfuscatedAccountid, purchaseTime, purchaseState, purchaseToken).compose(RxSchedulers.observableIO2Main())
// .subscribe(object : BaseObserver<Any?>() {
// override fun onSuccess(result: Any?) {
// EventUtils.onEvent("memberpresenter_googlepaysuccess_onsuccess")
// AdJustUtils.onEvent("r7m4vr")
// mActivity?.finish()
//
//
// }
//
// override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// EventUtils.onEvent("memberpresenter_googlepaysuccess_onfailure","${errorMsg}")
// AdJustUtils.onEvent("3ebyqo")
// }
// })
//同步成功 消耗掉
consume
(
""
)
consume
(
purchaseToken
)
}
...
...
@@ -297,6 +342,8 @@ class GooglePayHelper {
if
(
billingClient
.
isReady
)
{
billingClient
.
endConnection
();
}
mPayCallBack
=
null
Log
.
d
(
TAG
,
"billingClient release"
)
}
}
\ No newline at end of file
cms/src/main/java/com/zxhl/cms/googlepay/GooglePayResult.kt
0 → 100644
View file @
f698e9cf
package
com.ishin.google.bean
class
GooglePayResult
{
var
packageName
:
String
=
""
var
orderId
:
String
=
""
var
productId
:
String
=
""
var
developerPayload
:
String
=
""
var
obfuscatedAccountid
:
String
=
""
var
purchaseTime
:
String
=
""
var
purchaseState
:
String
=
""
var
purchaseToken
:
String
=
""
}
\ No newline at end of file
cms/src/main/java/com/zxhl/cms/net/api/IUserInfoApi.java
View file @
f698e9cf
...
...
@@ -3,6 +3,7 @@ package com.zxhl.cms.net.api;
import
com.zxhl.cms.ad.upload.model.Response
;
import
com.zxhl.cms.common.NetConfig
;
import
com.zxhl.cms.net.model.uc.AliPayEntity
;
import
com.zxhl.cms.net.model.uc.GooglePayEntity
;
import
com.zxhl.cms.net.model.uc.PayMinEntity
;
import
com.zxhl.cms.net.model.uc.PayVerifyEntity
;
import
com.zxhl.cms.net.model.uc.UserInfo
;
...
...
@@ -80,6 +81,27 @@ public interface IUserInfoApi {
@POST
(
NetConfig
.
User
.
URL_PAY_ORDER
)
Observable
<
Response
<
AliPayEntity
>>
aliPay
(
@Query
(
"goodsId"
)
String
goodsId
,
@Query
(
"payType"
)
String
payType
,
@Query
(
"voucherId"
)
String
voucherId
,
@Query
(
"appId"
)
String
appId
,
@Query
(
"payMode"
)
String
payMode
);
/**
* Google支付
*
* @return
*/
@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
<
AliPayEntity
>>
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
);
/**
* 商城商品支付宝支付
...
...
cms/src/main/java/com/zxhl/cms/net/model/uc/GooglePayEntity.java
0 → 100644
View file @
f698e9cf
package
com
.
zxhl
.
cms
.
net
.
model
.
uc
;
/**
* @author (wangXuewei)
* @datetime 2022-03-14 18:21 GMT+8
* @detail :
*/
public
class
GooglePayEntity
{
/**
* payType : 4
* wakeup : {"orderNo":1503315110133714944}
* payPlatform : null
* outTradeNo : 1503315110133714944
*/
private
int
payType
;
private
WakeupBean
wakeup
;
private
String
outTradeNo
;
public
int
getPayType
()
{
return
payType
;
}
public
void
setPayType
(
int
payType
)
{
this
.
payType
=
payType
;
}
public
WakeupBean
getWakeup
()
{
return
wakeup
;
}
public
void
setWakeup
(
WakeupBean
wakeup
)
{
this
.
wakeup
=
wakeup
;
}
public
String
getOutTradeNo
()
{
return
outTradeNo
;
}
public
void
setOutTradeNo
(
String
outTradeNo
)
{
this
.
outTradeNo
=
outTradeNo
;
}
public
static
class
WakeupBean
{
/**
* orderNo : 1503315110133714944
*/
private
long
orderNo
;
public
long
getOrderNo
()
{
return
orderNo
;
}
public
void
setOrderNo
(
long
orderNo
)
{
this
.
orderNo
=
orderNo
;
}
}
}
cms/src/main/res/layout/activity_google_pay.xml
View file @
f698e9cf
...
...
@@ -9,6 +9,7 @@
<Button
android:id=
"@+id/id_btn_google_pay"
android:text=
"GooglePay"
android:layout_marginTop=
"100dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment