Commit 18372f31 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :加入上报事件戳
[实现方案] :
parent e3d59db6
......@@ -48,7 +48,7 @@ class Appli : Application() {
val afDevKey = "bbVuECGrv5oci77w97NMVg"
val appsflyer: AppsFlyerLib = AppsFlyerLib.getInstance()
// For debug - remove in production
appsflyer.setDebugLog(true)
appsflyer.setDebugLog(false)
//optional
appsflyer.setMinTimeBetweenSessions(0)
appsflyer.init(afDevKey, null, this)
......
PACKAGE_NAME=com.zhangxin.magicbox
VERSION_CODE=13
VERSION_NAME=1.0.3.5
\ No newline at end of file
VERSION_CODE=14
VERSION_NAME=1.0.3.6
\ No newline at end of file
......@@ -40,6 +40,10 @@ class GooglePayHelper {
// To be implemented in a later section.
Log.d(TAG, "购买监听 code ${billingResult.responseCode}")
Log.d(TAG, "购买监听 size ${purchases?.size}")
EventUtils.onEvent(
"GooglePayGotoPayE",
"Google支付结束回调结果 code${billingResult.responseCode}"
)
if (billingResult.responseCode == BillingResponseCode.OK) {
//支付成功 同步后台
if (!purchases.isNullOrEmpty()) {
......@@ -61,6 +65,8 @@ class GooglePayHelper {
//购买成功 消耗掉
consume(googlePayResult, purchase)
}
}else{
mPayCallBack?.onError("支付异常: google支付成功,未获取到商品结果信息")
}
} else if (billingResult.responseCode == BillingResponseCode.ITEM_ALREADY_OWNED) {
//未消耗掉
......@@ -138,13 +144,15 @@ class GooglePayHelper {
}
})
}
}
/**
* 购买商品
*/
private fun purchase(mSku: String, orderId: String) {
EventUtils.onEvent("GooglePayPurchaseS", "预备购买Google商品")
productId = mSku
obfuscatedAccountid = orderId
if (billingClient.isReady) {
......@@ -152,6 +160,9 @@ class GooglePayHelper {
skuList.add(mSku)
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skuList).setType(SkuType.INAPP)
EventUtils.onEvent("GooglePayQuerySkuS", "开始查询Google商品")
billingClient.querySkuDetailsAsync(
params.build()
) { billingResult, skuDetailsList ->
......@@ -166,6 +177,11 @@ class GooglePayHelper {
// .setObfuscatedProfileId()
.setObfuscatedAccountId(orderId)
.build()
EventUtils.onEvent(
"GooglePayGotoPayS",
"查询成功,开始吊起Google支付"
)
//吊起支付
val responseCode =
billingClient.launchBillingFlow(
......@@ -173,42 +189,77 @@ class GooglePayHelper {
flowParams
).responseCode
Log.d(TAG, "purchase 去支付 code $responseCode")
EventUtils.onEvent(
"GooglePayQuerySkuE",
"查询商品结束 吊起支付Code:${responseCode}"
)
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买结束"
)
break
} else {
if (i == skuDetailsList.size - 1) {
mPayCallBack?.onError("GooglePay 未匹配到对应的商品")
EventUtils.onEvent(
"GooglePayQuerySkuE",
"查询商品结束 未匹配到对应的商品:${mSku}"
)
mPayCallBack?.onError("GooglePay 未匹配到对应的商品${mSku}")
}
}
}
} else {
Log.d(TAG, "purchase 未查询到商品")
mPayCallBack?.onError("GooglePay 商品未查询到")
EventUtils.onEvent(
"GooglePayQuerySkuE",
"未查询到Google商品列表"
)
mPayCallBack?.onError("GooglePay 未查询到Google商品列表")
}
} else {
Log.d(TAG, "purchase 查询连接失败 cede" + billingResult.responseCode)
EventUtils.onEvent(
"GooglePayQuerySkuE",
"商品查询连接失败 cede${billingResult.responseCode}"
)
mPayCallBack?.onError("GooglePay error code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
} else {
Log.d(TAG, "purchase 购买 未连接")
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买未连接到Google"
)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。
purchase(mSku, orderId)
} else {
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买重连失败 code:${billingResult.responseCode}"
)
mPayCallBack?.onError("purchase 购买 连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买重连失败 Disconnected"
)
mPayCallBack?.onError("purchase 购买连接失败 onBillingServiceDisconnected")
}
})
// mPayCallBack?.onError("GooglePay purchase 购买 未连接")
}
}
......@@ -218,6 +269,10 @@ class GooglePayHelper {
* @param purchaseToken 商品token
*/
private fun consume(googlePayResult: GooglePayResult, purchase: Purchase) {
EventUtils.onEvent(
"GooglePayConsumeS",
"支付成功,开始消耗商品"
)
if (billingClient.isReady) {
val consumeParams =
ConsumeParams.newBuilder()
......@@ -229,16 +284,33 @@ class GooglePayHelper {
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
// Log.d(TAG, "consume 1消耗成功${googlePayResult.purchaseToken}")
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品成功"
)
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
EventUtils.onEvent(
"GooglePayConsumeE",
"商品消耗失败 code${billingResult.responseCode}}"
)
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode)
mPayCallBack?.onError("consume 消耗失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)//支付成功
}
}
} else {
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品 未连接Google"
)
EventUtils.onEvent(
"GooglePayConsumeS",
"支付成功,开始重连消耗商品"
)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
......@@ -253,17 +325,34 @@ class GooglePayHelper {
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${googlePayResult.purchaseToken}")
EventUtils.onEvent(
"GooglePayConsumeE",
"重连成功 消耗商品成功"
)
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode)
mPayCallBack?.onError("consume 消耗失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
EventUtils.onEvent(
"GooglePayConsumeE",
"重连成功 消耗商品失败code:${billingResult.responseCode}}"
)
mPayCallBack?.onError("重连成功 消耗商品失败code:${billingResult.responseCode}")
}
}
} else {
// Log.d(TAG, "consume init 连接失败 code:" + billingResult.responseCode)
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品 重连失败code:${billingResult.responseCode}"
)
mPayCallBack?.onError("consume 消耗连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
......@@ -271,6 +360,11 @@ class GooglePayHelper {
override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品重连失败 Disconnected"
)
mPayCallBack?.onError("consume onBillingServiceDisconnected")
}
})
......@@ -475,6 +569,9 @@ class GooglePayHelper {
* google支付
*/
fun googlePay(goodsId: String, payMode: String, payCallBack: GooglePayCallBack) {
EventUtils.onEvent("GooglePayGetOrderIdS", "获取订单号")
mPayCallBack = payCallBack
//向服务端获取订单ID
ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", payMode)
......@@ -482,16 +579,30 @@ class GooglePayHelper {
.subscribe(object : BaseObserver<GooglePayEntity>() {
override fun onSuccess(result: GooglePayEntity?) {
if (result != null) {
EventUtils.onEvent("GooglePayGetOrderIdE", "获取订单号_成功")
var sku = goodsId.replace("-", "_")
// Log.d(TAG, "请求支付${sku}")
purchase("xymh_$sku", result.outTradeNo ?: "")
} else {
EventUtils.onEvent(
"GooglePayGetOrderIdE",
"未获取到订单数据"
)
mPayCallBack?.onError("GooglePay 未获取到订单数据")
}
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// EventUtils.onEvent("GooglePay Fail:$errorMsg")
EventUtils.onEvent(
"GooglePayGetOrderIdE",
"获取订单号接口异常:$errorMsg"
)
mPayCallBack?.onError("订单接口 Error:$errorMsg")
}
})
......@@ -501,17 +612,33 @@ class GooglePayHelper {
* google支付 成功后 同步给服务器
*/
private fun updateToService(googlePayResult: GooglePayResult, purchase: Purchase) {
EventUtils.onEvent(
"GooglePayToServiceS",
"google支付成功,开始同步后端校验"
)
//支付成功 向后端同步 网络问题再次重试
ApiClient.shopApi.googlePaySuccess(googlePayResult)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<Any>() {
override fun onSuccess(result: Any?) {
// EventUtils.onEvent("googlepaysuccess_onsuccess")
EventUtils.onEvent(
"GooglePayToServiceE",
"google支付成功,后端校验成功"
)
mPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//支付成功
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}")
EventUtils.onEvent(
"GooglePayToServiceE",
"google支付成功,后端校验失败 code:$code msg:$errorMsg"
)
mPayCallBack?.onError("服务器同步失败 code:$code msg:$errorMsg")
}
})
......
......@@ -282,7 +282,6 @@ class PayActivity : BaseActivity(), PayContract.View,
EventUtils.onEvent("pay_fail")
mLoading?.setResult(false, "Pay for failure", 1000)
}
}
fun setBootmPrice() {
......@@ -516,15 +515,18 @@ class PayActivity : BaseActivity(), PayContract.View,
var googlePay: GooglePayHelper? = null
private fun googlePay(goodsId: String) {
if (goodsId == "") {
EventUtils.onEvent("GooglePayGoodsIdNull")
return
}
mLoading?.setLoading(getString(R.string.wait_ing2))
mLoading?.show()
EventUtils.onEvent("GooglePayStart", "开始支付")
googlePay?.googlePay(goodsId, "6", object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
mPresenter?.verifyPay(googleJson, GOOGLE_PAY)
//mLoading?.setResult(true, "Pay for success", 1000)
EventUtils.onEvent("GooglePaySuccess")
EventUtils.onEvent("GooglePayEnd", "支付结束_成功")
}
override fun onCancel() {
......@@ -532,6 +534,7 @@ class PayActivity : BaseActivity(), PayContract.View,
mLoading?.setResult(false, "pay cancel", 1000)
}
EventUtils.onEvent("GooglePayCancel")
EventUtils.onEvent("GooglePayEnd", "支付结束_取消")
}
override fun onError(error: String) {
......@@ -540,6 +543,8 @@ class PayActivity : BaseActivity(), PayContract.View,
mLoading?.setResult(false, "pay error", 1000)
}
EventUtils.onEvent("GooglePayError", error)
EventUtils.onEvent("GooglePayEnd", "支付结束_异常 msg:${error}")
}
})
}
......
......@@ -39,20 +39,21 @@ object EventUtils {
fun onEvent(action: String) {
val jsonObj = getJSON(action)
jsonObj.put("time", "${System.currentTimeMillis()}")
apiClient(jsonObj)
appFlayerEvent(action,"")
appFlayerEvent(action,jsonObj)
// MobclickAgent.onEvent(AppContext.get(), action)
}
fun onEvent(action: String, value: String) {
val jsonObj = getJSON(action)
jsonObj.put("value", value)
jsonObj.put("time", "${System.currentTimeMillis()}")
apiClient(jsonObj)
appFlayerEvent(action,value)
appFlayerEvent(action,jsonObj)
// MobclickAgent.onEvent(AppContext.get(), action, value)
}
// /**
// * 统计新用户首次登陆 男女生
// */
......@@ -73,9 +74,9 @@ object EventUtils {
private fun apiClient(data: JSONObject) {
val str = data.toString()
Log.d("EventUtils", str)
// Log.d("EventUtils", str)
val key = AESUtils.encrypt(str)
Log.d("EventUtils", key)
// Log.d("EventUtils", key)
EventApiClient.cfgApi.requestEvent("behavior", key).subscribeOn(Schedulers.io())
.subscribe(object : Observer<Any> {
override fun onComplete() {
......@@ -117,9 +118,9 @@ object EventUtils {
}
fun appFlayerEvent(action: String, value: String) {
fun appFlayerEvent(action: String,data: JSONObject) {
var eventValues = HashMap<String, Any>()
eventValues[action] = value
eventValues[action] = data.toString()
AppsFlyerLib.getInstance().logEvent(AppContext.get(), action, eventValues,object :AppsFlyerRequestListener{
override fun onSuccess() {
Log.e("appsflyer","onSuccess")
......
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