package xx.view.sonview;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.Purchase;
import xx.R;
import xx.api.ApiRetrofit;
import xx.entity.Googlepayentity;
import xx.entity.MemberPricesBean;
import xx.entity.MemberPricessBean;
import xx.utils.GoogleBillHelper;
import xx.utils.GoogleBillingListener;
import xx.utils.GoogleBillingManager;
import xx.utils.SharedUtil;
import xx.utils.Showbuffer;
import xx.utils.Showdiog;
import xx.utils.sin.SignForInster;
import xx.view.sonview.my.login.OneKeyLoginActivity;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public abstract class GooglePayBaseActivity extends AppCompatActivity {
private String TAG = "print.GooglePayBaseActivity";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//建立连接
GoogleBillingManager.getInstance().createClient(this);
Log.d(TAG, "GoogleBillingManager.getInstance.createClient");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "GoogleBillingManager.getInstance.onDestroy");
//结束连接
GoogleBillingManager.getInstance().endConn();
}
public abstract void onDialogClosePaySuccess();
public abstract void onGooglePaySuccess();
// 谷歌支付 @{
private GoogleBillHelper billProxy = new GoogleBillHelper();
String out_trade_no = "";
boolean isRequesting = false;
/**
* 创建谷歌预支付订单
* @param infoBean
*/
public void addGooglePreTradingRecord(MemberPricessBean.InfoBean infoBean) {
isRequesting = false;
if (SharedUtil.getString("userID") == null) {
startActivity(new Intent(GooglePayBaseActivity.this, OneKeyLoginActivity.class));
Toast.makeText(GooglePayBaseActivity.this, "Please sing in and try again", Toast.LENGTH_SHORT).show();
return;
}
//启动缓冲弹窗
String bodystr = "请求后台的参数";
RequestBody body = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), bodystr);
ApiRetrofit.getInstance().getApiService().addGooglePreTradingRecord(body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Googlepayentity>() {
@Override
public void onCompleted() {
showbuffer.closedialog();
}
@Override
public void onError(Throwable e) {
showbuffer.closedialog();
System.out.println(e);
Toast.makeText(GooglePayBaseActivity.this, "permanent failure", Toast.LENGTH_SHORT).show();
}
@Override
public void onNext(Googlepayentity response) {
System.out.println(response);
Log.d("print", ">>>>----addGooglePreTradingRecord.next--------->" + response);
out_trade_no = response.getInfo().getOut_trade_no();
Log.d(TAG, "----out_trade_no.onNext : " + out_trade_no);
googlepay(response.getInfo().getOut_trade_no(), infoBean);
}
});
}
/**
* 谷歌支付
* @param infoBean
*/
public void googlepay(String orderID, MemberPricessBean.InfoBean infoBean) {
Log.d("print", ">>>>----googlepay.orderID :" + orderID+" , getTradeGoodsId : "+infoBean.getOut_trade_goodsid());
Log.d(TAG, "googlepay.orderID : "+orderID);
billProxy.onQuerySkuDetailsAsync(billingListenerImpl,BillingClient.ProductType.INAPP,infoBean.getOut_trade_goodsid());
}
private GoogleBillingListener billingListenerImpl = new GoogleBillingListener(){
/**
* 产品查询成功
*
* @param list
*/
@Override
public void onProductDetailsSus(List<ProductDetails> list) {
Log.e(TAG, "onProductDetailsSus.list : "+list);
GoogleBillingListener.super.onProductDetailsSus(list);
if (null == list || list.size() <= 0) {
Log.e(TAG, "没有查询到相关产品~~~~");
return;
}
//查询方法中只传了一个商品,所以直接取第一个了
//根据实际情况处理~
Log.e(TAG, "billingListenerImpl.onOpenGooglePlay...");
billProxy.onOpenGooglePlay(this, GooglePayBaseActivity.this, list.get(0));
}
/**
* 购买监听
*
* @param
* @param purchases
*/
@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
Log.d(TAG, "onPurchasesUpdated.list : "+billingResult.getDebugMessage()+" , isRequesting : "+isRequesting);
if(isRequesting)return;
isRequesting = true;
GoogleBillingListener.super.onPurchasesUpdated(billingResult, purchases);
if (null == purchases || purchases.size() == 0) {
Log.d(TAG, "onPurchasesUpdated.purchases.size 0 return ");
return;
}
Log.d(TAG, "onPurchasesUpdated.purchases.size : "+purchases.size());
String debugMessage = billingResult.getDebugMessage();
// Log.d("print", ">>>>----mPurchasesUpdatedListener.debugMessage: "+debugMessage+" , isNotify : "+isNotify);
if (purchases != null && purchases.size() > 0) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (Purchase purchase : purchases) {
if(purchase == null || purchase.getPurchaseState() != Purchase.PurchaseState.PURCHASED) continue;
//核销订单
billProxy.onConsumeAsync(this, purchase);
//通知服务器支付成功,服务端验证后,消费商品
//TODO客户端同步回调支付成功
String userToken = SharedUtil.getString("userID");
String jsonData = purchase.getOriginalJson();;
long time = System.currentTimeMillis();
String joinType = getString(R.string.joinType);
Log.d("print", "googlePayNotify.jsonData :"+jsonData);
//String signStr = jsonData+out_trade_no+time+joinType+"kdjia^*";
String sign = SignForInster.signForInspirysin(jsonData + "*" + out_trade_no + "*" + time + "*" + getString(R.string.joinType) + "*kdjia^*");//后为key值
Log.d("print", "googlePayNotify.sign :"+sign);
Log.d("print", "googlePayNotify.sign :"+sign);
/**
* 支付成功,�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
谷歌支付相关源码.zip (4个子文件)
谷歌支付相关源码
GooglePayBaseActivity.java 10KB
GoogleBillingListener.java 820B
GoogleBillHelper.java 6KB
GoogleBillingManager.java 3KB
共 4 条
- 1
资源评论
无风之翼
- 粉丝: 86
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功