Search in sources :

Example 1 with BCQueryReqParams

use of cn.beecloud.entity.BCQueryReqParams in project ttdj by soonphe.

the class BCWXWapPaymentActivity method onResume.

public void onResume() {
    super.onResume();
    synchronized (this) {
        if (firstIn) {
            firstIn = false;
            return;
        }
    }
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    loadingDialog.setMessage("处理中,请稍候...");
    loadingDialog.setIndeterminate(true);
    loadingDialog.setCancelable(false);
    loadingDialog.show();
    BCCache.executorService.execute(new Runnable() {

        @Override
        public void run() {
            boolean found = false;
            // 总共查3次
            for (int i = 0; i < 3; i++) {
                BCQueryReqParams bcQueryReqParams;
                try {
                    bcQueryReqParams = new BCQueryReqParams(BCReqParams.BCChannelTypes.ALL);
                } catch (BCException e) {
                    Log.w(TAG, e.getMessage() + "");
                    return;
                }
                String queryURL = BCHttpClientUtil.getBillQueryURL() + "/" + BCCache.getInstance().billID + "?para=";
                BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(queryURL + bcQueryReqParams.transToEncodedJsonString());
                if (response.code == 200 || (response.code >= 400 && response.code < 500)) {
                    try {
                        BCQueryBillResult billResult = BCQueryBillResult.transJsonToResultObject(response.content);
                        // 如果查询到成功退出
                        if (billResult.getResultCode() == 0 && billResult.getBill().getPayResult() != null && billResult.getBill().getPayResult()) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_SUCCESS, BCPayResult.APP_PAY_SUCC_CODE, BCPayResult.RESULT_SUCCESS, "用户支付成功", BCCache.getInstance().billID));
                            }
                            found = true;
                            break;
                        }
                    } catch (JsonSyntaxException ex) {
                        Log.w(TAG, ex.getMessage() + "");
                    }
                }
                try {
                    // 0.5s后继续查
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Log.w(TAG, e.getMessage() + "");
                }
            }
            if (!found) {
                // 如果一直没有查询到支付结果
                if (BCPay.payCallback != null) {
                    BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_CANCEL, BCPayResult.APP_PAY_CANCEL_CODE, BCPayResult.RESULT_CANCEL, "用户未支付,或服务器通信延迟,如果用户确认已支付,请注意webhook推送", BCCache.getInstance().billID));
                }
            }
            loadingDialog.dismiss();
            finish();
        }
    });
}
Also used : BCQueryReqParams(cn.beecloud.entity.BCQueryReqParams) BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) JsonSyntaxException(com.google.gson.JsonSyntaxException) ProgressDialog(android.app.ProgressDialog) BCPayResult(cn.beecloud.entity.BCPayResult)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 BCPayResult (cn.beecloud.entity.BCPayResult)1 BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)1 BCQueryReqParams (cn.beecloud.entity.BCQueryReqParams)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1