调整三星包
This commit is contained in:
@@ -229,14 +229,23 @@ dependencies {
|
||||
//侧滑删除
|
||||
api 'com.yanzhenjie.recyclerview:x:1.3.2'
|
||||
|
||||
//华为支付插件包
|
||||
//api project(':lib_huawei')
|
||||
|
||||
//google插件包
|
||||
api project(':lib_google')
|
||||
huawei_onlineImplementation project(':lib_huawei')
|
||||
huawei_testImplementation project(':lib_huawei')
|
||||
|
||||
samsung_onlineImplementation project(":lib_google")
|
||||
samsung_testImplementation project(":lib_google")
|
||||
|
||||
google_onlineImplementation project(":lib_google")
|
||||
google_testImplementation project(":lib_google")
|
||||
|
||||
link_onlineImplementation project(":lib_google")
|
||||
link_testImplementation project(":lib_google")
|
||||
|
||||
//samsung插件包
|
||||
//api project(':IAP6Helper')
|
||||
samsung_onlineImplementation project(':IAP6Helper')
|
||||
samsung_testImplementation project(':IAP6Helper')
|
||||
|
||||
|
||||
//時間選擇器
|
||||
api 'com.contrarywind:Android-PickerView:4.1.9'
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
package com.yunbao.common.pay.samsung;
|
||||
|
||||
public interface OnSamsungPaymentListener {
|
||||
void onPaymentSuccess(String purchaseVo);
|
||||
|
||||
void onPaymentFailed(String errorVo);
|
||||
}
|
||||
@@ -2,28 +2,22 @@ package com.yunbao.common.pay.samsung;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.samsung.android.sdk.iap.lib.constants.HelperDefine;
|
||||
import com.samsung.android.sdk.iap.lib.helper.IapHelper;
|
||||
import com.samsung.android.sdk.iap.lib.listener.OnConsumePurchasedItemsListener;
|
||||
import com.samsung.android.sdk.iap.lib.listener.OnGetOwnedListListener;
|
||||
import com.samsung.android.sdk.iap.lib.listener.OnPaymentListener;
|
||||
import com.samsung.android.sdk.iap.lib.vo.ConsumeVo;
|
||||
import com.samsung.android.sdk.iap.lib.vo.ErrorVo;
|
||||
import com.samsung.android.sdk.iap.lib.vo.OwnedProductVo;
|
||||
import com.samsung.android.sdk.iap.lib.vo.PurchaseVo;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.utils.L;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SamsungUtil {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
IapHelper iapHelper;
|
||||
|
||||
private static SamsungUtil samsungUtil;
|
||||
private Object samsung = null;
|
||||
|
||||
public static SamsungUtil newInstance(Context context) {
|
||||
if (samsungUtil == null) {
|
||||
@@ -34,20 +28,33 @@ public class SamsungUtil {
|
||||
|
||||
public SamsungUtil(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
try {
|
||||
samsung = mContext.getClassLoader().loadClass("com.samsung.android.sdk.iap.lib.SamsungUtil")
|
||||
.getConstructor(Context.class)
|
||||
.newInstance(mContext);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public void init() {
|
||||
iapHelper = IapHelper.getInstance(mContext);
|
||||
//设置支付模式 OPERATION_MODE_PRODUCTION 正式模式 OPERATION_MODE_TEST 测试模式
|
||||
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_PRODUCTION);
|
||||
if(samsung==null)return;
|
||||
try {
|
||||
samsung.getClass().getMethod("init").invoke(samsung);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (iapHelper != null) {
|
||||
iapHelper.dispose();
|
||||
if(samsung==null)return;
|
||||
try {
|
||||
samsung.getClass().getMethod("dispose").invoke(samsung);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,26 +64,25 @@ public class SamsungUtil {
|
||||
*
|
||||
* @param skuId
|
||||
*/
|
||||
public void buy(String skuId, OnPaymentListener onPaymentListener) {
|
||||
//购买
|
||||
iapHelper.startPayment(skuId, "", (errorVo, purchaseVo) -> {
|
||||
if (purchaseVo != null) {
|
||||
onPaymentListener.onPaymentSuccess(purchaseVo.getPurchaseId());
|
||||
} else {
|
||||
if (errorVo.getErrorCode() == HelperDefine.IAP_PAYMENT_IS_CANCELED) {
|
||||
onPaymentListener.onPaymentFailed(mContext.getString(R.string.pay_cancel));
|
||||
} else {
|
||||
onPaymentListener.onPaymentFailed(errorVo.getErrorString());
|
||||
public void buy(String skuId, OnSamsungPaymentListener onPaymentListener) {
|
||||
if(samsung==null)return;
|
||||
try {
|
||||
Class<?> listenerClass = Class.forName("com.samsung.android.sdk.iap.lib.SamsungUtil$OnPaymentListener");
|
||||
Object listenerObj = Proxy.newProxyInstance(mContext.getClassLoader(), new Class[]{listenerClass}, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if("onPaymentSuccess".equals(method.getName())){
|
||||
onPaymentListener.onPaymentSuccess((String) args[0]);
|
||||
}else if("onPaymentFailed".equals(method.getName())){
|
||||
onPaymentListener.onPaymentFailed((String) args[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public interface OnPaymentListener {
|
||||
void onPaymentSuccess(String purchaseVo);
|
||||
|
||||
void onPaymentFailed(String errorVo);
|
||||
});
|
||||
samsung.getClass().getMethod("buy",String.class, listenerClass).invoke(samsung,skuId,listenerObj);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,51 +92,25 @@ public class SamsungUtil {
|
||||
* @param skuId
|
||||
*/
|
||||
public void consume(String skuId) {
|
||||
//消耗
|
||||
iapHelper.consumePurchasedItems(skuId, new OnConsumePurchasedItemsListener() {
|
||||
@Override
|
||||
public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList) {
|
||||
if (_consumeList != null) {
|
||||
L.e("消耗:" + new Gson().toJson(_consumeList));
|
||||
L.e("ErrorVo:" + _errorVO.dump());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void consumeAll(ArrayList<OwnedProductVo> _ownedList) {
|
||||
if (_ownedList.size() > 0) {
|
||||
iapHelper.consumePurchasedItems(_ownedList.get(0).getPurchaseId(), new OnConsumePurchasedItemsListener() {
|
||||
@Override
|
||||
public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList1) {
|
||||
if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
|
||||
L.e("消耗:" + new Gson().toJson(_consumeList1));
|
||||
L.e("ErrorVo:" + _errorVO.dump());
|
||||
_ownedList.remove(0);
|
||||
consumeAll(_ownedList);
|
||||
}
|
||||
}
|
||||
});
|
||||
if(samsung==null)return;
|
||||
try {
|
||||
samsung.getClass().getMethod("consume",String.class).invoke(samsung,skuId);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 消耗所有未消耗的消耗品
|
||||
*/
|
||||
public void query() {
|
||||
//查询商品 PRODUCT_TYPE_ITEM 消耗品&非消耗品
|
||||
iapHelper.getOwnedList(HelperDefine.PRODUCT_TYPE_ITEM, new OnGetOwnedListListener() {
|
||||
@Override
|
||||
public void onGetOwnedProducts(ErrorVo _errorVo, ArrayList<OwnedProductVo> _ownedList) {
|
||||
if (_errorVo != null) {
|
||||
if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
|
||||
if (_ownedList != null) {
|
||||
consumeAll(_ownedList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if(samsung==null)return;
|
||||
try {
|
||||
samsung.getClass().getMethod("query").invoke(samsung);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user